python-statemachine 2.1.2__py3-none-any.whl → 2.3.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {python_statemachine-2.1.2.dist-info → python_statemachine-2.3.0.dist-info}/METADATA +86 -25
- python_statemachine-2.3.0.dist-info/RECORD +28 -0
- statemachine/__init__.py +1 -1
- statemachine/callbacks.py +106 -76
- statemachine/contrib/diagram.py +20 -6
- statemachine/dispatcher.py +72 -37
- statemachine/event.py +21 -20
- statemachine/exceptions.py +9 -3
- statemachine/factory.py +72 -9
- statemachine/graph.py +6 -0
- statemachine/locale/en/LC_MESSAGES/statemachine.po +40 -26
- statemachine/locale/pt_BR/LC_MESSAGES/statemachine.po +60 -39
- statemachine/mixins.py +1 -3
- statemachine/signature.py +15 -8
- statemachine/state.py +22 -25
- statemachine/statemachine.py +125 -97
- statemachine/states.py +6 -4
- statemachine/transition.py +35 -26
- statemachine/utils.py +19 -0
- python_statemachine-2.1.2.dist-info/RECORD +0 -30
- statemachine/locale/en/LC_MESSAGES/statemachine.mo +0 -0
- statemachine/locale/pt_BR/LC_MESSAGES/statemachine.mo +0 -0
- {python_statemachine-2.1.2.dist-info → python_statemachine-2.3.0.dist-info}/LICENSE +0 -0
- {python_statemachine-2.1.2.dist-info → python_statemachine-2.3.0.dist-info}/WHEEL +0 -0
statemachine/transition.py
CHANGED
|
@@ -2,6 +2,7 @@ from typing import TYPE_CHECKING
|
|
|
2
2
|
|
|
3
3
|
from .callbacks import BoolCallbackMeta
|
|
4
4
|
from .callbacks import CallbackMetaList
|
|
5
|
+
from .callbacks import CallbackPriority
|
|
5
6
|
from .event import same_event_cond_builder
|
|
6
7
|
from .events import Events
|
|
7
8
|
from .exceptions import InvalidDefinition
|
|
@@ -48,7 +49,6 @@ class Transition:
|
|
|
48
49
|
before=None,
|
|
49
50
|
after=None,
|
|
50
51
|
):
|
|
51
|
-
|
|
52
52
|
self.source = source
|
|
53
53
|
self.target = target
|
|
54
54
|
self.internal = internal
|
|
@@ -57,14 +57,14 @@ class Transition:
|
|
|
57
57
|
raise InvalidDefinition("Internal transitions should be self-transitions.")
|
|
58
58
|
|
|
59
59
|
self._events = Events().add(event)
|
|
60
|
-
self.validators = CallbackMetaList().add(validators)
|
|
61
|
-
self.before = CallbackMetaList().add(before)
|
|
62
|
-
self.on = CallbackMetaList().add(on)
|
|
63
|
-
self.after = CallbackMetaList().add(after)
|
|
60
|
+
self.validators = CallbackMetaList().add(validators, priority=CallbackPriority.INLINE)
|
|
61
|
+
self.before = CallbackMetaList().add(before, priority=CallbackPriority.INLINE)
|
|
62
|
+
self.on = CallbackMetaList().add(on, priority=CallbackPriority.INLINE)
|
|
63
|
+
self.after = CallbackMetaList().add(after, priority=CallbackPriority.INLINE)
|
|
64
64
|
self.cond = (
|
|
65
65
|
CallbackMetaList(factory=BoolCallbackMeta)
|
|
66
|
-
.add(cond)
|
|
67
|
-
.add(unless, expected_value=False)
|
|
66
|
+
.add(cond, priority=CallbackPriority.INLINE)
|
|
67
|
+
.add(unless, priority=CallbackPriority.INLINE, expected_value=False)
|
|
68
68
|
)
|
|
69
69
|
|
|
70
70
|
def __repr__(self):
|
|
@@ -73,49 +73,58 @@ class Transition:
|
|
|
73
73
|
f"internal={self.internal!r})"
|
|
74
74
|
)
|
|
75
75
|
|
|
76
|
-
def
|
|
77
|
-
|
|
78
|
-
register(self.cond)
|
|
79
|
-
register(self.before)
|
|
80
|
-
register(self.on)
|
|
81
|
-
register(self.after)
|
|
76
|
+
def __str__(self):
|
|
77
|
+
return f"transition {self.event!s} from {self.source!s} to {self.target!s}"
|
|
82
78
|
|
|
83
|
-
def
|
|
79
|
+
def _setup(self):
|
|
84
80
|
before = self.before.add
|
|
85
81
|
on = self.on.add
|
|
86
82
|
after = self.after.add
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
)
|
|
90
|
-
on("on_transition", registry=registry, suppress_errors=True, prepend=True)
|
|
83
|
+
|
|
84
|
+
before("before_transition", priority=CallbackPriority.GENERIC, suppress_errors=True)
|
|
85
|
+
on("on_transition", priority=CallbackPriority.GENERIC, suppress_errors=True)
|
|
91
86
|
|
|
92
87
|
for event in self._events:
|
|
93
88
|
same_event_cond = same_event_cond_builder(event)
|
|
94
89
|
before(
|
|
95
90
|
f"before_{event}",
|
|
96
|
-
|
|
91
|
+
priority=CallbackPriority.NAMING,
|
|
97
92
|
suppress_errors=True,
|
|
98
93
|
cond=same_event_cond,
|
|
99
94
|
)
|
|
100
95
|
on(
|
|
101
96
|
f"on_{event}",
|
|
102
|
-
|
|
97
|
+
priority=CallbackPriority.NAMING,
|
|
103
98
|
suppress_errors=True,
|
|
104
99
|
cond=same_event_cond,
|
|
105
100
|
)
|
|
106
101
|
after(
|
|
107
102
|
f"after_{event}",
|
|
108
|
-
|
|
103
|
+
priority=CallbackPriority.NAMING,
|
|
109
104
|
suppress_errors=True,
|
|
110
105
|
cond=same_event_cond,
|
|
111
106
|
)
|
|
112
107
|
|
|
113
108
|
after(
|
|
114
109
|
"after_transition",
|
|
115
|
-
|
|
110
|
+
priority=CallbackPriority.AFTER,
|
|
116
111
|
suppress_errors=True,
|
|
117
112
|
)
|
|
118
113
|
|
|
114
|
+
def _add_observer(self, register):
|
|
115
|
+
register(self.validators)
|
|
116
|
+
register(self.cond)
|
|
117
|
+
register(self.before)
|
|
118
|
+
register(self.on)
|
|
119
|
+
register(self.after)
|
|
120
|
+
|
|
121
|
+
def _check_callbacks(self, check):
|
|
122
|
+
check(self.validators)
|
|
123
|
+
check(self.cond)
|
|
124
|
+
check(self.before)
|
|
125
|
+
check(self.on)
|
|
126
|
+
check(self.after)
|
|
127
|
+
|
|
119
128
|
def match(self, event):
|
|
120
129
|
return self._events.match(event)
|
|
121
130
|
|
|
@@ -130,13 +139,13 @@ class Transition:
|
|
|
130
139
|
def add_event(self, value):
|
|
131
140
|
self._events.add(value)
|
|
132
141
|
|
|
133
|
-
def execute(self, event_data: "EventData"):
|
|
142
|
+
async def execute(self, event_data: "EventData"):
|
|
134
143
|
machine = event_data.machine
|
|
135
144
|
args, kwargs = event_data.args, event_data.extended_kwargs
|
|
136
|
-
machine._callbacks_registry[self.validators].call(*args, **kwargs)
|
|
137
|
-
if not machine._callbacks_registry[self.cond].all(*args, **kwargs):
|
|
145
|
+
await machine._callbacks_registry[self.validators].call(*args, **kwargs)
|
|
146
|
+
if not await machine._callbacks_registry[self.cond].all(*args, **kwargs):
|
|
138
147
|
return False
|
|
139
148
|
|
|
140
|
-
result = machine._activate(event_data)
|
|
149
|
+
result = await machine._activate(event_data)
|
|
141
150
|
event_data.result = result
|
|
142
151
|
return True
|
statemachine/utils.py
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import asyncio
|
|
2
|
+
|
|
3
|
+
|
|
1
4
|
def qualname(cls):
|
|
2
5
|
"""
|
|
3
6
|
Returns a fully qualified name of the class, to avoid name collisions.
|
|
@@ -6,9 +9,25 @@ def qualname(cls):
|
|
|
6
9
|
|
|
7
10
|
|
|
8
11
|
def ensure_iterable(obj):
|
|
12
|
+
"""
|
|
13
|
+
Returns an iterator if obj is not an instance of string or if it
|
|
14
|
+
encounters type error, otherwise it returns a list.
|
|
15
|
+
"""
|
|
9
16
|
if isinstance(obj, str):
|
|
10
17
|
return [obj]
|
|
11
18
|
try:
|
|
12
19
|
return iter(obj)
|
|
13
20
|
except TypeError:
|
|
14
21
|
return [obj]
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def run_async_from_sync(coroutine):
|
|
25
|
+
"""
|
|
26
|
+
Run an async coroutine from a synchronous context.
|
|
27
|
+
"""
|
|
28
|
+
try:
|
|
29
|
+
loop = asyncio.get_running_loop()
|
|
30
|
+
return asyncio.ensure_future(coroutine)
|
|
31
|
+
except RuntimeError:
|
|
32
|
+
loop = asyncio.get_event_loop()
|
|
33
|
+
return loop.run_until_complete(coroutine)
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
statemachine/__init__.py,sha256=Bx88FyKa4Gm2RZxCWmYSxlefw0hVvOJMdWcqpsEiCgc,192
|
|
2
|
-
statemachine/callbacks.py,sha256=_tmx5AZlhn_f3zhtUNAKBwfkkOKQLPBfSByhDUdFCeo,8265
|
|
3
|
-
statemachine/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
|
-
statemachine/contrib/diagram.py,sha256=_UxkX0ycOhzCAuvV_b3hrvZ6V_VOUFmbBigI3oz4PCA,6748
|
|
5
|
-
statemachine/dispatcher.py,sha256=GMAwivNTz_m8X9szPqKD9O0cV2XoWhPkBE8d3btsFHY,3598
|
|
6
|
-
statemachine/event.py,sha256=fvWxyFcrbPVxNW94p66rGJ5I1UZUK9mDJz68udkz2JI,2106
|
|
7
|
-
statemachine/event_data.py,sha256=nxOfypngK-78A77gj4pS-oxLx9zl1S9wnSt_rTiCyZA,2257
|
|
8
|
-
statemachine/events.py,sha256=rUbiTX-QGoo7zzmQMEeWeLrIVnp9zhicdRIm34CoAVI,731
|
|
9
|
-
statemachine/exceptions.py,sha256=uzvDbHkzCZkmFI_02L0yC9gd6d0SBn9GmsI8ekc0Hjk,952
|
|
10
|
-
statemachine/factory.py,sha256=KGAa3rSnxTFyPSD1UXDgkGtBpg95A5vFISq3YCyvccQ,5779
|
|
11
|
-
statemachine/graph.py,sha256=QTNlEmEYCq6NfX6yiKrjfEY8bpbGASgV-M1g5TNR7YM,359
|
|
12
|
-
statemachine/i18n.py,sha256=NLvGseaORmQ0G-V_J8tkjoxh_piWMOm2CI6mBQpLamc,362
|
|
13
|
-
statemachine/locale/en/LC_MESSAGES/statemachine.mo,sha256=aGIvF2G_OISexcLv3ZsudPfAkVIvL33zaEGeXJM47-I,452
|
|
14
|
-
statemachine/locale/en/LC_MESSAGES/statemachine.po,sha256=MfODCwzML6DzhOpHbno2Pdhsb26AWboR5Ka1JCNvJIA,1685
|
|
15
|
-
statemachine/locale/pt_BR/LC_MESSAGES/statemachine.mo,sha256=wTh7ge52cALzWScvS1wdjT-QO5ZhrsvodiI-dscYZhI,1914
|
|
16
|
-
statemachine/locale/pt_BR/LC_MESSAGES/statemachine.po,sha256=KsR9rlnhw17EZG-IbVx3F0wJAJSK0B-OByGmUmDHDUM,2375
|
|
17
|
-
statemachine/mixins.py,sha256=54aOvLZh9TyAIrqwfufGNmo1K4gaJR_dzhPdzisGPMk,1055
|
|
18
|
-
statemachine/model.py,sha256=OylI3FjMiHpYyDl9mtK1zEJMeSvemaN4giQDonpc8kI,211
|
|
19
|
-
statemachine/registry.py,sha256=RnVBRS3I_6Tm2OMgXMB_ewX7zQaslqEfhXFOhbqIkG4,959
|
|
20
|
-
statemachine/signature.py,sha256=o8HLzhysMSnH_yy8qWG7aW5jVMOWdJM47OMnMyGVfC4,7463
|
|
21
|
-
statemachine/state.py,sha256=YJ6NxsYi6KYxMTH8wp_jf4yZL2FSYN_HZmcqJXmch1w,8175
|
|
22
|
-
statemachine/statemachine.py,sha256=rol4RKXG7R0hsibLCkcQMs7v3__v069IJc7xtFZuhRc,11998
|
|
23
|
-
statemachine/states.py,sha256=gK-_csTDatvX4DYJcHUB45Ealv4FnfVz1Bj7IAS5nn0,4151
|
|
24
|
-
statemachine/transition.py,sha256=7UO6Kjb73tsF7nHfaYM94J-FsByZJN81k_KtCBB_1vY,4833
|
|
25
|
-
statemachine/transition_list.py,sha256=DatsmMWgK0YK30Nrj-josVvlTgeGapKutzYur9-puF8,5949
|
|
26
|
-
statemachine/utils.py,sha256=hY72gKE7VT9dn3xW5ffjKZosVblGbga8G9sKLEh5ZFg,317
|
|
27
|
-
python_statemachine-2.1.2.dist-info/LICENSE,sha256=zcP7TsJMqaFxuTvLRZPT7nJl3_ppjxR9Z76BE9pL5zc,1074
|
|
28
|
-
python_statemachine-2.1.2.dist-info/METADATA,sha256=3KLowdmDsCjT4zMeeFpan_7g-HVlLGoCgiiLzwzRybA,11454
|
|
29
|
-
python_statemachine-2.1.2.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
30
|
-
python_statemachine-2.1.2.dist-info/RECORD,,
|
|
Binary file
|
|
Binary file
|
|
File without changes
|
|
File without changes
|