diff options
author | Prabhu Ramachandran | 2016-05-10 20:09:08 +0530 |
---|---|---|
committer | Prabhu Ramachandran | 2016-05-10 20:09:08 +0530 |
commit | 5c74697b00ea08a2b78615637d8b322410fca4b0 (patch) | |
tree | d5b937e90bc7d3051b9c9128c4e1560b09db1c2c /yaksh/code_server.py | |
parent | d386d24aaa662f91e4314060926dc9bc02426c7d (diff) | |
parent | c384c60c6d7fb5d30f3f929c518e0b41e084c4c4 (diff) | |
download | online_test-5c74697b00ea08a2b78615637d8b322410fca4b0.tar.gz online_test-5c74697b00ea08a2b78615637d8b322410fca4b0.tar.bz2 online_test-5c74697b00ea08a2b78615637d8b322410fca4b0.zip |
Merge pull request #96 from ankitjavalkar/code-eval-refactor-clean2
Code evaluator refactor
Diffstat (limited to 'yaksh/code_server.py')
-rwxr-xr-x | yaksh/code_server.py | 23 |
1 files changed, 9 insertions, 14 deletions
diff --git a/yaksh/code_server.py b/yaksh/code_server.py index faf9c0d..2d8567e 100755 --- a/yaksh/code_server.py +++ b/yaksh/code_server.py @@ -31,7 +31,7 @@ import re import json # Local imports. from settings import SERVER_PORTS, SERVER_POOL_PORT -from language_registry import set_registry, get_registry +from language_registry import create_evaluator_instance, unpack_json MY_DIR = abspath(dirname(__file__)) @@ -58,13 +58,17 @@ class CodeServer(object): self.queue = queue # Public Protocol ########## - def check_code(self, language, json_data, in_dir=None): + def check_code(self, language, test_case_type, json_data, in_dir=None): """Calls relevant EvaluateCode class based on language to check the answer code """ - code_evaluator = self._create_evaluator_instance(language, json_data, - in_dir) - result = code_evaluator.evaluate() + code_evaluator = create_evaluator_instance(language, + test_case_type, + json_data, + in_dir + ) + data = unpack_json(json_data) + result = code_evaluator.evaluate(**data) # Put us back into the server pool queue since we are free now. self.queue.put(self.port) @@ -79,15 +83,6 @@ class CodeServer(object): self.queue.put(self.port) server.serve_forever() - # Private Protocol ########## - def _create_evaluator_instance(self, language, json_data, in_dir): - """Create instance of relevant EvaluateCode class based on language""" - set_registry() - registry = get_registry() - cls = registry.get_class(language) - instance = cls.from_json(language, json_data, in_dir) - return instance - ############################################################################### # `ServerPool` class. |