summaryrefslogtreecommitdiff
path: root/wsgi_server.py
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-09-04 16:57:17 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-09-04 16:57:17 +0200
commita293cf9d5fd64ff29bc05daa80d2f9a3a8c0abe0 (patch)
tree3ab047f9bcd85dff3c12fee7c2a3d75cfe864962 /wsgi_server.py
parentc494a44b3c0e8faf77419c3cd5bef4da195e89c6 (diff)
Add Python push&pull services to wsgi_server
Diffstat (limited to 'wsgi_server.py')
-rw-r--r--wsgi_server.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/wsgi_server.py b/wsgi_server.py
index fda576b..324f338 100644
--- a/wsgi_server.py
+++ b/wsgi_server.py
@@ -143,6 +143,24 @@ class Query(CodeqService):
session.update_solution(problem_id, trace, program)
return result
+# Pull stdout/stderr from the session's Python interpreter.
+class PythonPull(CodeqService):
+ def process(self, js, session):
+ python = session.get_python()
+ output = python.pull()
+ return {'code': 0, 'message': 'ok', 'terminal': {'text': output if output else ''}}
+
+# Push stdin to the session's Python interpreter.
+class PythonPush(CodeqService):
+ def process(self, js, session):
+ text = js.get('text')
+ if text is None:
+ return {'code': 1, 'message': 'No input specified'}
+
+ python = session.get_python()
+ python.push(text)
+ return {'code': 0, 'message': 'ok'}
+
class Hint(CodeqService):
def process(self, js, session):
language = js.get('language')
@@ -211,6 +229,9 @@ api.add_route('/activity', activity)
query = Query()
api.add_route('/query', query)
+api.add_route('/python_pull', PythonPull())
+api.add_route('/python_push', PythonPush())
+
hint = Hint()
api.add_route('/hint', hint)