summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimotej Lazar <timotej.lazar@araneo.org>2015-08-24 12:57:23 +0200
committerTimotej Lazar <timotej.lazar@araneo.org>2015-08-24 12:57:23 +0200
commit7af27371090a7d7129c81a7aa97b0376ad233034 (patch)
tree7ecc25425f95f0ee67074efbb81c1771362679e6
parenta20f9b8842c6da6631ae36f62571394053b5c082 (diff)
Simplify python.engine
-rwxr-xr-xpython/engine.py10
1 files changed, 4 insertions, 6 deletions
diff --git a/python/engine.py b/python/engine.py
index f1b8d36..4a12443 100755
--- a/python/engine.py
+++ b/python/engine.py
@@ -6,16 +6,15 @@ import http.client
import json
address, port = 'localhost', 3031 # TODO put this somewhere sane
-def request(method, path, body=None):
+def request(path, args=None):
headers = {'Content-Type': 'application/json;charset=utf-8'}
- messages = []
+ body = json.dumps(args)
try:
conn = http.client.HTTPConnection(address, port, timeout=30)
- conn.request(method, path, body, headers=headers)
+ conn.request('GET', path, body=body, headers=headers)
response = conn.getresponse()
if response.status != http.client.OK:
raise Exception('server returned {}'.format(response.status))
-
reply = json.loads(response.read().decode('utf-8'))
return reply
finally:
@@ -24,8 +23,7 @@ def request(method, path, body=None):
# Inputs are given as a list of pairs (expression, stdin). Receives and returns
# a list of answers given as tuples (result, stdout, stderr, exception).
def run(code=None, inputs=None, timeout=1.0):
- body = {'code': code, 'inputs': inputs, 'timeout': timeout}
- return request('GET', '/run', body=json.dumps(body))
+ return request('/run', {'code': code, 'inputs': inputs, 'timeout': timeout})
# Basic sanity check.