diff options
-rw-r--r-- | python/util.py | 21 | ||||
-rw-r--r-- | server/python_session.py | 2 |
2 files changed, 19 insertions, 4 deletions
diff --git a/python/util.py b/python/util.py index f149953..ecd5ee8 100644 --- a/python/util.py +++ b/python/util.py @@ -18,7 +18,7 @@ def has_token_sequence(tokens, sequence): def almost_equal(a, b, prec=1): """ Compares values a and b using at most <code>prec</code> decimal values. """ - return int(a*10**prec) == int(b*10**prec) + return round(a*10**prec) == round(b*10**prec) def get_numbers(s): """ Extracts numbers from string s. """ @@ -46,6 +46,21 @@ def string_contains_number(s, a): return a in get_numbers(s) +def get_exception_desc(exc): + # if have an exception! + if exc: + if 'EOFError' in exc: + return [{'id':'eof_error'}] + if 'timed out' in exc: + return [{'id':'timed_out'}] + if 'NameError' in exc: + return [{'id':'name_error', 'args': {'message': exc}}] + elif 'TypeError' in exc: + return [{'id':'type_error', 'args': {'message': exc}}] + else: + return [{'id':'error', 'args': {'message': exc}}] + return None + if __name__ == '__main__': - print(has_token_sequence('x + y >= 0', ['>=', '0'])) - print(has_token_sequence('x + y > 0', ['>=', '0'])) + print(has_token_sequence(get_tokens('x + y >= 0'), ['>=', '0'])) + print(has_token_sequence(get_tokens('x + y > 0'), ['>=', '0'])) diff --git a/server/python_session.py b/server/python_session.py index 975af7f..85e1d2e 100644 --- a/server/python_session.py +++ b/server/python_session.py @@ -52,7 +52,7 @@ class PythonSession(object): if conn.poll(real_timeout): results.append(conn.recv()) else: - results.append('timed out') + results.append((None, None, None, 'timed out')) p.terminate() return results |