diff options
author | Timotej Lazar <timotej.lazar@araneo.org> | 2015-09-22 11:33:43 +0200 |
---|---|---|
committer | Timotej Lazar <timotej.lazar@araneo.org> | 2015-09-22 11:33:43 +0200 |
commit | 15f35dc1c2eb50a8140f1a0abf45d5aa25fdf66b (patch) | |
tree | f0d793936f66467df6f711944b9d7adae893dde1 /server/handlers.py | |
parent | dce8ec719b1d85acf3c753effae3f28629dd847c (diff) |
Add support for execing the user's Python program
Diffstat (limited to 'server/handlers.py')
-rw-r--r-- | server/handlers.py | 24 |
1 files changed, 23 insertions, 1 deletions
diff --git a/server/handlers.py b/server/handlers.py index 52a33f5..08994a0 100644 --- a/server/handlers.py +++ b/server/handlers.py @@ -106,7 +106,27 @@ class Query(CodeqService): request.reply(result) -# Push stdin to the session's Python interpreter. TODO: convert to async handling +# Push user program to the Python interpreter to be exec'd. +class PythonExec(CodeqService): + def process(self, request): + program = request.data.get('program') + if program is None: + request.reply({'code': 1, 'message': 'No program specified'}) + else: + python = request.session.get_python() + python.exec(program) + request.reply({'code': 0, 'message': 'ok'}) + + +# Send an interrupt to the Python interpreter. +class PythonStop(CodeqService): + def process(self, request): + python = request.session.get_python() + python.stop() + request.reply({'code': 0, 'message': 'ok'}) + + +# Push stdin to the Python interpreter. class PythonPush(CodeqService): def process(self, request): text = request.data.get('text') @@ -194,7 +214,9 @@ incoming_handlers = { 'logout': None, 'activity': Activity(), 'query': Query(), + 'python_exec': PythonExec(), 'python_push': PythonPush(), + 'python_stop': PythonStop(), 'hint': Hint(), 'test': Test() } |