diff options
author | Prabhu Ramachandran | 2015-09-04 18:57:57 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2015-09-04 18:57:57 +0530 |
commit | 31f5e743031d105b0406e9587dc33bb065cd6e4d (patch) | |
tree | 653fbd703850e1e12f875bc5422ec3cb809c6e07 /testapp/yaksh_app/language_registry.py | |
parent | c9abbadbb0e6a4a60edb7ef2a14d6c74648b0677 (diff) | |
parent | 3ee050fe509b83f36188566ee57b3dd16d94a8a7 (diff) | |
download | online_test-31f5e743031d105b0406e9587dc33bb065cd6e4d.tar.gz online_test-31f5e743031d105b0406e9587dc33bb065cd6e4d.tar.bz2 online_test-31f5e743031d105b0406e9587dc33bb065cd6e4d.zip |
Merge pull request #55 from ankitjavalkar/yaksh
Change app name to yaksh
Diffstat (limited to 'testapp/yaksh_app/language_registry.py')
-rw-r--r-- | testapp/yaksh_app/language_registry.py | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/testapp/yaksh_app/language_registry.py b/testapp/yaksh_app/language_registry.py new file mode 100644 index 0000000..76a23d7 --- /dev/null +++ b/testapp/yaksh_app/language_registry.py @@ -0,0 +1,36 @@ +from settings import code_evaluators +import importlib + +registry = None + +def set_registry(): + global registry + registry = _LanguageRegistry() + +def get_registry(): + return registry + +class _LanguageRegistry(object): + def __init__(self): + self._register = {} + for language, module in code_evaluators.iteritems(): + self._register[language] = None + + # Public Protocol ########## + def get_class(self, language): + """ Get the code evaluator class for the given language """ + if not self._register.get(language): + self._register[language] = code_evaluators.get(language) + + cls = self._register[language] + module_name, class_name = cls.rsplit(".", 1) + # load the module, will raise ImportError if module cannot be loaded + get_module = importlib.import_module(module_name) + # get the class, will raise AttributeError if class cannot be found + get_class = getattr(get_module, class_name) + return get_class + + def register(self, language, class_name): + """ Register a new code evaluator class for language""" + self._register[language] = class_name + |