summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
Diffstat (limited to 'python')
-rw-r--r--python/util.py17
1 files changed, 16 insertions, 1 deletions
diff --git a/python/util.py b/python/util.py
index 21426ca..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(get_tokens('x + y >= 0'), ['>=', '0']))
print(has_token_sequence(get_tokens('x + y > 0'), ['>=', '0']))