summaryrefslogtreecommitdiff
path: root/testapp/yaksh/language_registry.py
diff options
context:
space:
mode:
authorankitjavalkar2015-09-11 12:35:09 +0530
committerankitjavalkar2015-09-14 12:00:53 +0530
commit32cde26f9807a29eb1fae0833e353212d43d7802 (patch)
tree52423f2c68ee22d4375eef86a3950d169410fe55 /testapp/yaksh/language_registry.py
parentae10d36297797ffc53275eabe3acfa0cb4bf3b11 (diff)
downloadonline_test-32cde26f9807a29eb1fae0833e353212d43d7802.tar.gz
online_test-32cde26f9807a29eb1fae0833e353212d43d7802.tar.bz2
online_test-32cde26f9807a29eb1fae0833e353212d43d7802.zip
Change app name to 'yaksh'
Diffstat (limited to 'testapp/yaksh/language_registry.py')
-rw-r--r--testapp/yaksh/language_registry.py36
1 files changed, 36 insertions, 0 deletions
diff --git a/testapp/yaksh/language_registry.py b/testapp/yaksh/language_registry.py
new file mode 100644
index 0000000..76a23d7
--- /dev/null
+++ b/testapp/yaksh/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
+