summaryrefslogtreecommitdiff
path: root/testapp/exam/language_registry.py
diff options
context:
space:
mode:
authorankitjavalkar2015-04-30 12:41:17 +0530
committerankitjavalkar2015-05-11 16:08:06 +0530
commit3e29dc7f6df7019562b179872b43cb13c7483738 (patch)
treef3ce37bc01aa8ffaf15a5ee380cbb371a74f4188 /testapp/exam/language_registry.py
parentd8847656ba79e51c96c6e3650374aaf616c375dc (diff)
downloadonline_test-3e29dc7f6df7019562b179872b43cb13c7483738.tar.gz
online_test-3e29dc7f6df7019562b179872b43cb13c7483738.tar.bz2
online_test-3e29dc7f6df7019562b179872b43cb13c7483738.zip
- Seperate testcases, Modify views, models, templates for compatibility
- Change functions names in code_evaluator
Diffstat (limited to 'testapp/exam/language_registry.py')
-rw-r--r--testapp/exam/language_registry.py21
1 files changed, 13 insertions, 8 deletions
diff --git a/testapp/exam/language_registry.py b/testapp/exam/language_registry.py
index 8700d32..76a23d7 100644
--- a/testapp/exam/language_registry.py
+++ b/testapp/exam/language_registry.py
@@ -1,31 +1,36 @@
-from settings import language_register
+from settings import code_evaluators
+import importlib
registry = None
def set_registry():
- globals registry = _LanguageRegistry()
+ global registry
+ registry = _LanguageRegistry()
def get_registry():
return registry
class _LanguageRegistry(object):
def __init__(self):
- for language, module in language_register.iteritems():
+ self._register = {}
+ for language, module in code_evaluators.iteritems():
self._register[language] = None
# Public Protocol ##########
def get_class(self, language):
- if not self._register[language]:
- self._register[language] = language_register[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.split(".")
+ 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, cls):
- # self._register[language] = cls
+ def register(self, language, class_name):
+ """ Register a new code evaluator class for language"""
+ self._register[language] = class_name