-
Notifications
You must be signed in to change notification settings - Fork 10
/
Utils.py
27 lines (22 loc) · 854 Bytes
/
Utils.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import re
from typing import List
_regattr = re.compile('[A-Z]{3}')
class DummyList(list):
def __init__(self, list: List[int]):
super().__init__(list)
def __contains__(self, o: object) -> bool:
if type(o) is set:
for x in self:
if x in o: return True
return False
return super().__contains__(o)
def parseCondition(cond: str):
cond2 = _regattr.sub(lambda m: f'getattr(x, "{m.group()}")', cond.replace('AEVT','AVT')).replace('?[', ' in DummyList([').replace('![', 'not in DummyList([').replace(']', '])').replace('|',' or ')
while True:
try:
func = eval(f'lambda x: {cond2}')
func.__doc__ = cond2
return func
except:
print(f'[WARNING] missing ) in {cond}')
cond2 += ')'