From 7af27371090a7d7129c81a7aa97b0376ad233034 Mon Sep 17 00:00:00 2001 From: Timotej Lazar Date: Mon, 24 Aug 2015 12:57:23 +0200 Subject: Simplify python.engine --- python/engine.py | 10 ++++------ 1 file 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. -- cgit v1.2.1