summaryrefslogtreecommitdiff
path: root/python
diff options
context:
space:
mode:
authorMartin <martin@leo.fri1.uni-lj.si>2015-09-22 17:26:24 +0200
committerMartin <martin@leo.fri1.uni-lj.si>2015-09-22 17:26:24 +0200
commit138101ec997ee80e8f33f690ae47e451b5b278f7 (patch)
tree3aebb5cc1f1c58a80ef1c2feec24f9a75b34d01c /python
parent68acd82d75106cddd3d4b79365672cad7391c3cd (diff)
Added basic handling of exception to util.py
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']))