diff options
author | ankitjavalkar | 2015-04-30 11:21:49 +0530 |
---|---|---|
committer | ankitjavalkar | 2015-04-30 11:29:35 +0530 |
commit | d8847656ba79e51c96c6e3650374aaf616c375dc (patch) | |
tree | 9e4ca3c29bc082cdd7b6775208544c2da9cee374 /testapp/exam/code_server.py | |
parent | 18df6d88a2e1a9dfe7d05ca97b2d69ff0569e088 (diff) | |
download | online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.tar.gz online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.tar.bz2 online_test-d8847656ba79e51c96c6e3650374aaf616c375dc.zip |
Code Review: Code Refactoring
Diffstat (limited to 'testapp/exam/code_server.py')
-rwxr-xr-x | testapp/exam/code_server.py | 38 |
1 files changed, 19 insertions, 19 deletions
diff --git a/testapp/exam/code_server.py b/testapp/exam/code_server.py index 697b131..c621dcd 100755 --- a/testapp/exam/code_server.py +++ b/testapp/exam/code_server.py @@ -32,13 +32,13 @@ import json import importlib # Local imports. from settings import SERVER_PORTS, SERVER_TIMEOUT, SERVER_POOL_PORT -from language_registry import registry -from evaluate_python_code import EvaluatePythonCode -from evaluate_c_code import EvaluateCCode -from evaluate_cpp_code import EvaluateCppCode -from evaluate_java_code import EvaluateJavaCode -from evaluate_scilab_code import EvaluateScilabCode -from evaluate_bash_code import EvaluateBashCode +from language_registry import set_registry +# from evaluate_python_code import EvaluatePythonCode +# from evaluate_c_code import EvaluateCCode +# from evaluate_cpp_code import EvaluateCppCode +# from evaluate_java_code import EvaluateJavaCode +# from evaluate_scilab_code import EvaluateScilabCode +# from evaluate_bash_code import EvaluateBashCode MY_DIR = abspath(dirname(__file__)) @@ -69,24 +69,15 @@ class CodeServer(object): """Calls relevant EvaluateCode class based on language to check the answer code """ - evaluate_code_instance = self.create_class_instance(language, - json_data, in_dir) - - result = evaluate_code_instance.run_code() + code_evaluator = self._create_evaluator_instance(language, json_data, + in_dir) + result = code_evaluator.code_evaluator() # Put us back into the server pool queue since we are free now. self.queue.put(self.port) return json.dumps(result) - # Public Protocol ########## - def create_class_instance(self, language, json_data, in_dir): - """Create instance of relevant EvaluateCode class based on language""" - cls = registry.get_class(language) - instance = cls.from_json(language, json_data, in_dir) - return instance - - # Public Protocol ########## def run(self): """Run XMLRPC server, serving our methods.""" server = SimpleXMLRPCServer(("localhost", self.port)) @@ -95,6 +86,15 @@ 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. |