SHOW:
|
|
- or go back to the newest paste.
| 1 | import operator, re | |
| 2 | ||
| 3 | - | def _match(pattern, string): |
| 3 | + | def _match(pattern, _string): |
| 4 | - | return True if re.match(pattern, string) else False |
| 4 | + | return True if re.match(pattern, _string) else False |
| 5 | ||
| 6 | numeric_types_operators = { '<' : operator.lt, '<=': operator.le, '==': operator.eq, '!=': operator.ne, '>=': operator.ge,'>' : operator.gt }
| |
| 7 | ||
| 8 | allowed_operators = {
| |
| 9 | boolean : {
| |
| 10 | '==': operator.eq, | |
| 11 | '!=': operator.ne, | |
| 12 | }, int : numeric_types_operators, | |
| 13 | float : numeric_types_operators, | |
| 14 | - | sting : {
|
| 14 | + | string : {
|
| 15 | 'match' : _match | |
| 16 | } | |
| 17 | } | |
| 18 | ||
| 19 | def evaluate(value, eval_string): | |
| 20 | """ eval string example: operator value_to_compare """ | |
| 21 | operation, value_to_compare = eval_string.split(" ")
| |
| 22 | return allower_operators[type(value)][operation](value, value_to_compare) |