This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspect | |
| class Commands(list): | |
| def __init__(self, commands): | |
| commands = commands if commands else [] | |
| if not hasattr(commands, '__iter__'): | |
| commands = [commands] | |
| super(Commands, self).__init__(commands) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from file import PluginDirectory | |
| from interpreter import Interpreter | |
| from plugin_loader import PluginLoader | |
| class Application: | |
| def run(self): | |
| plugin_loader = PluginLoader() | |
| plugin_directory = PluginDirectory() | |
| commands = plugin_loader.load(plugin_directory) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Python: | |
| priority = 'low' | |
| def matches(self, expression): | |
| return True | |
| def execute(self, expression, variables): | |
| ''' | |
| >>> python = Python() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class PluginLoader: | |
| def load(self, directory): | |
| ret = [] | |
| for plugin in directory.children: | |
| plugin_file = plugin.find(name=plugin.name, type='py') | |
| plugin_class = plugin_file.classes[plugin.name] | |
| self._check_attributes(plugin_class) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import re | |
| class Assignment: | |
| def matches(self, expression): | |
| ''' | |
| >>> assignment = Assignment() | |
| >>> assignment.matches('a=5') | |
| True |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| class Python: | |
| priority = 'low' | |
| def matches(self, expression): | |
| return True | |
| def execute(self, expression, variables): | |
| ''' | |
| >>> from py.test import raises |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspect | |
| class Commands(list): | |
| def __init__(self, commands): | |
| commands = commands if commands else [] | |
| if not hasattr(commands, '__iter__'): | |
| commands = [commands] | |
| super(Commands, self).__init__(commands) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| ... | |
| def interpret(self, expression): | |
| possible_parameters = {'commands': self.commands, | |
| 'expression': expression, 'variables': self.variables} | |
| try: | |
| command = self.commands.match(expression) | |
| args = self._get_args(command.execute) | |
| params = self._find_parameters(possible_parameters, args) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import inspect | |
| class Commands(list): | |
| def __init__(self, commands=None): | |
| commands = commands if commands else [] | |
| if not hasattr(commands, '__iter__'): | |
| commands = [commands] | |
| super(Commands, self).__init__(commands) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from file import PluginDirectory | |
| from interpreter import Interpreter | |
| from plugin_loader import PluginLoader | |
| class Application: | |
| def run(self): | |
| plugin_loader = PluginLoader() | |
| plugin_directory = PluginDirectory() | |
| commands = plugin_loader.load(plugin_directory) |