summaryrefslogtreecommitdiff
path: root/yaksh/language_registry.py
diff options
context:
space:
mode:
authorankitjavalkar2016-03-11 12:11:49 +0530
committerankitjavalkar2016-05-05 18:59:22 +0530
commit1e993bee18028c59d809f49d853b60e41326991c (patch)
treee1af06404a634e54f9ad8a27c6948b131481b127 /yaksh/language_registry.py
parentceb4f2cbc1a03835a3c7e34d806ec21e47e3f059 (diff)
downloadonline_test-1e993bee18028c59d809f49d853b60e41326991c.tar.gz
online_test-1e993bee18028c59d809f49d853b60e41326991c.tar.bz2
online_test-1e993bee18028c59d809f49d853b60e41326991c.zip
Add a python standard out evaluator
Diffstat (limited to 'yaksh/language_registry.py')
-rw-r--r--yaksh/language_registry.py27
1 files changed, 19 insertions, 8 deletions
diff --git a/yaksh/language_registry.py b/yaksh/language_registry.py
index ee311ec..512e2f5 100644
--- a/yaksh/language_registry.py
+++ b/yaksh/language_registry.py
@@ -1,21 +1,31 @@
from settings import code_evaluators
import importlib
+import json
registry = None
# def set_registry():
# global registry
# registry = _LanguageRegistry()
-
-def _set_registry():
+
+def get_registry(): #@@@get_evaluator_registry
global registry
if registry is None:
registry = _LanguageRegistry()
return registry
-
-def get_registry():
- registry = _set_registry()
- return registry
+
+def unpack_json(json_data):
+ data = json.loads(json_data)
+ return data
+
+def create_evaluator_instance(language, test_case_type, json_data, in_dir):
+ """Create instance of relevant EvaluateCode class based on language"""
+ # set_registry()
+ registry = get_registry()
+ cls = registry.get_class(language, test_case_type) #@@@get_evaluator_for_language
+ instance = cls(in_dir)
+ # instance = cls.from_json(language, json_data, in_dir)
+ return instance
class _LanguageRegistry(object):
def __init__(self):
@@ -24,12 +34,13 @@ class _LanguageRegistry(object):
self._register[language] = None
# Public Protocol ##########
- def get_class(self, language):
+ def get_class(self, language, test_case_type):
""" 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]
+ test_case_register = self._register[language]
+ cls = test_case_register.get(test_case_type)
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)