diff options
Diffstat (limited to 'python')
-rwxr-xr-x | python/engine.py | 10 |
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. |