-
Notifications
You must be signed in to change notification settings - Fork 0
/
state_func.py
64 lines (53 loc) · 1.66 KB
/
state_func.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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import copy
class stateFunc:
def __init__(self, body):
self.body = body
def body_run(self, *args):
self.body(self, *args)
class stateFuncE(stateFunc):
def __init__(self, body, kattr):
self.base_kattr = {}
self.assign(kattr)
super().__init__(body)
def assign(self, kattr):
self.base_kattr.update(copy.deepcopy(kattr))
for k, v in kattr.items():
setattr(self, k, v)
class stateFuncM(stateFuncE):
def __init__(self, body, sources):
self.base_kattr = {}
for s in sources:
self.assign(s)
self.body = body
def check_dictlike(dictlike):
try:
dictlike.items()
return True
except:
return False
class stateFuncI(stateFuncM):
def __init__(self, body, sources):
changed_sources = list(sources)
first_source = sources[0]
if hasattr(first_source, '__self__'):
upper = first_source.__self__
# print(upper)
if not issubclass(type(upper),stateFunc):
print("not")
raise Exception("Invalid inheritence")
else:
changed_sources[0] = upper.base_kattr
super().__init__(body, changed_sources)
def state_func(function):
sf = stateFunc(function)
return sf.body_run
def state_func_e(kattr):
def decorator(function):
sf_e = stateFuncE(function, kattr)
return sf_e.body_run
return decorator
def state_func_i(*sources):
def decorator(function):
sf_e = stateFuncI(function, sources)
return sf_e.body_run
return decorator