diff options
-rw-r--r-- | client/__init__.py | 1 | ||||
-rw-r--r-- | server/__init__.py | 3 | ||||
-rw-r--r-- | server/user_session.py | 2 | ||||
-rw-r--r-- | wsgi_server.py | 30 |
4 files changed, 27 insertions, 9 deletions
diff --git a/client/__init__.py b/client/__init__.py index 0e3e06a..2cffb52 100644 --- a/client/__init__.py +++ b/client/__init__.py @@ -8,6 +8,7 @@ class CodeqManager(multiprocessing.managers.BaseManager): pass CodeqManager.register('PrologSession') +CodeqManager.register('PythonSession') CodeqManager.register('UserSession') #CodeqManager.register('get_session_by_id') #CodeqManager.register('get_or_create_session') diff --git a/server/__init__.py b/server/__init__.py index d71f707..284c162 100644 --- a/server/__init__.py +++ b/server/__init__.py @@ -30,9 +30,10 @@ class CodeqManager(multiprocessing.managers.BaseManager): pass class UserSessionProxy(multiprocessing.managers.BaseProxy): - _method_to_typeid_ = {'get_prolog':'PrologSession'} + _method_to_typeid_ = {'get_prolog': 'PrologSession', 'get_python': 'PythonSession'} CodeqManager.register('PrologSession') +CodeqManager.register('PythonSession') CodeqManager.register('UserSession', proxytype=UserSessionProxy) #CodeqManager.register('get_session_by_id', callable=user_session.get_session_by_id, proxytype=UserSessionProxy) #CodeqManager.register('get_or_create_session', callable=user_session.get_or_create_session, proxytype=UserSessionProxy) diff --git a/server/user_session.py b/server/user_session.py index 8b76e0a..920e195 100644 --- a/server/user_session.py +++ b/server/user_session.py @@ -42,7 +42,7 @@ class UserSession(object): self.prolog_session.end() self.prolog_session = None if self.python_session is not None: - self.python_session.end() + self.python_session.destroy() self.python_session = None # TODO: add any cleanups as features are added! diff --git a/wsgi_server.py b/wsgi_server.py index df3c303..2597403 100644 --- a/wsgi_server.py +++ b/wsgi_server.py @@ -145,29 +145,45 @@ class Query(CodeqService): class Hint(CodeqService): def process(self, js, session): + language = js.get('language') problem_id = js.get('problem_id') program = js.get('program') + if problem_id is None: - return {'code': 1, 'message': 'Problem ID not given'} + return {'code': 1, 'message': 'No problem ID specified'} if program is None: return {'code': 2, 'message': 'No program specified'} - prolog = session.get_prolog() - hints = prolog.hint(session.get_uid(), problem_id, program) + if language == 'prolog': + lang_session = session.get_prolog() + elif language == 'python': + lang_session = session.get_python() + else: + return {'code': 3, 'message': 'Unknown language specified'} + + hints = lang_session.hint(session.get_uid(), problem_id, program) return {'code': 0, 'message': 'ok', 'hints': hints} class Test(CodeqService): def process(self, js, session): + language = js.get('language') problem_id = js.get('problem_id') program = js.get('program') + if problem_id is None: - return {'code': 1, 'message': 'Problem ID not given'} + return {'code': 1, 'message': 'No problem ID specified'} if program is None: return {'code': 2, 'message': 'No program specified'} - prolog = session.get_prolog() - messages = prolog.test(session.get_uid(), problem_id, program) - return {'code': 0, 'message': 'ok', 'hints': messages} + if language == 'prolog': + lang_session = session.get_prolog() + elif language == 'python': + lang_session = session.get_python() + else: + return {'code': 3, 'message': 'Unknown language specified'} + + hints = lang_session.test(session.get_uid(), problem_id, program) + return {'code': 0, 'message': 'ok', 'hints': hints} class GetProblem(CodeqService): def process(self, js, session): |