python-statemachine 2.3.3__py3-none-any.whl → 2.3.4__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.3.3.dist-info → python_statemachine-2.3.4.dist-info}/METADATA +1 -1
- {python_statemachine-2.3.3.dist-info → python_statemachine-2.3.4.dist-info}/RECORD +9 -9
- statemachine/__init__.py +1 -1
- statemachine/callbacks.py +9 -4
- statemachine/dispatcher.py +13 -5
- statemachine/statemachine.py +14 -7
- statemachine/states.py +7 -6
- {python_statemachine-2.3.3.dist-info → python_statemachine-2.3.4.dist-info}/LICENSE +0 -0
- {python_statemachine-2.3.3.dist-info → python_statemachine-2.3.4.dist-info}/WHEEL +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
statemachine/__init__.py,sha256=
|
|
2
|
-
statemachine/callbacks.py,sha256=
|
|
1
|
+
statemachine/__init__.py,sha256=adVlL_-BcysTOCiwLuk9ETvy23vCnxMDRioFAadkeZ4,192
|
|
2
|
+
statemachine/callbacks.py,sha256=5_WaILrjUvZOYX_LQe4Gd8nsCvkErjw9DaHYG_ggvxs,11101
|
|
3
3
|
statemachine/contrib/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
4
4
|
statemachine/contrib/diagram.py,sha256=JJx52yZqgDNIebvcUJ82IGT4EyerXQmOcF5mR21_kao,7198
|
|
5
|
-
statemachine/dispatcher.py,sha256=
|
|
5
|
+
statemachine/dispatcher.py,sha256=2DtjCj_kiDF2uk_EEvXxs5NTABOvCr4paxVz77s6mXA,5365
|
|
6
6
|
statemachine/engines/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
7
7
|
statemachine/engines/async_.py,sha256=Z-AS4zQ2xDj2uexJ7fepQTSaw5PjqesemWGXX9g0rpU,5546
|
|
8
8
|
statemachine/engines/sync.py,sha256=bYCyzoYo03LLfxzUl2XyyNlmMmxDLn_w0AMa5IHCF3U,5497
|
|
@@ -20,12 +20,12 @@ statemachine/model.py,sha256=OylI3FjMiHpYyDl9mtK1zEJMeSvemaN4giQDonpc8kI,211
|
|
|
20
20
|
statemachine/registry.py,sha256=HmV9sUGkYVrNUZxJYoZo-trSUis7dIun_WcGktblgc8,922
|
|
21
21
|
statemachine/signature.py,sha256=HwuyWX3p_GZwKKrGbt9wk4-bHpymqs_pgqW7OlDgGRc,7877
|
|
22
22
|
statemachine/state.py,sha256=IKdkMBkXCgcvswMKQZ-hn0-739Hhf6z6q8mSEoevV7o,8262
|
|
23
|
-
statemachine/statemachine.py,sha256=
|
|
24
|
-
statemachine/states.py,sha256=
|
|
23
|
+
statemachine/statemachine.py,sha256=WgI4LbnOyOBl8OZqBXFRYETtt8rQi0XEhQN-D_2oMFM,11536
|
|
24
|
+
statemachine/states.py,sha256=vpRNjiGmTDHvE0fn0gwdq8-WcG32n4ZiPTU-kgZ73rc,4870
|
|
25
25
|
statemachine/transition.py,sha256=R7gfSZjqR59OIdpKePgdr66zTp5azow-tDqqYJsECR4,4711
|
|
26
26
|
statemachine/transition_list.py,sha256=_tdFD1O7hw8xVAU6nRYmGrj6TCAM0SD-Sa0_DYKa88Y,6034
|
|
27
27
|
statemachine/utils.py,sha256=DpcrGqlbrnT-ogh-BogG0L07EG3KirHOsKORHlspDlI,1041
|
|
28
|
-
python_statemachine-2.3.
|
|
29
|
-
python_statemachine-2.3.
|
|
30
|
-
python_statemachine-2.3.
|
|
31
|
-
python_statemachine-2.3.
|
|
28
|
+
python_statemachine-2.3.4.dist-info/LICENSE,sha256=zcP7TsJMqaFxuTvLRZPT7nJl3_ppjxR9Z76BE9pL5zc,1074
|
|
29
|
+
python_statemachine-2.3.4.dist-info/METADATA,sha256=Sn9ueboV6iqunRJjBB5VtyxuD1UJyTk8f002WFzWwM4,13932
|
|
30
|
+
python_statemachine-2.3.4.dist-info/WHEEL,sha256=Zb28QaM1gQi8f4VCBhsUklF61CTlNYfs9YAZn-TOGFk,88
|
|
31
|
+
python_statemachine-2.3.4.dist-info/RECORD,,
|
statemachine/__init__.py
CHANGED
statemachine/callbacks.py
CHANGED
|
@@ -3,6 +3,7 @@ from bisect import insort
|
|
|
3
3
|
from collections import defaultdict
|
|
4
4
|
from collections import deque
|
|
5
5
|
from enum import IntEnum
|
|
6
|
+
from enum import IntFlag
|
|
6
7
|
from enum import auto
|
|
7
8
|
from inspect import isawaitable
|
|
8
9
|
from inspect import iscoroutinefunction
|
|
@@ -26,10 +27,14 @@ class CallbackPriority(IntEnum):
|
|
|
26
27
|
AFTER = 40
|
|
27
28
|
|
|
28
29
|
|
|
29
|
-
class SpecReference(
|
|
30
|
-
NAME =
|
|
31
|
-
CALLABLE =
|
|
32
|
-
PROPERTY =
|
|
30
|
+
class SpecReference(IntFlag):
|
|
31
|
+
NAME = auto()
|
|
32
|
+
CALLABLE = auto()
|
|
33
|
+
PROPERTY = auto()
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
SPECS_ALL = SpecReference.NAME | SpecReference.CALLABLE | SpecReference.PROPERTY
|
|
37
|
+
SPECS_SAFE = SpecReference.NAME
|
|
33
38
|
|
|
34
39
|
|
|
35
40
|
class CallbackGroup(IntEnum):
|
statemachine/dispatcher.py
CHANGED
|
@@ -8,8 +8,8 @@ from typing import Iterable
|
|
|
8
8
|
from typing import Set
|
|
9
9
|
from typing import Tuple
|
|
10
10
|
|
|
11
|
-
from
|
|
12
|
-
|
|
11
|
+
from .callbacks import SPECS_ALL
|
|
12
|
+
from .callbacks import SpecReference
|
|
13
13
|
from .signature import SignatureAdapter
|
|
14
14
|
|
|
15
15
|
if TYPE_CHECKING:
|
|
@@ -54,10 +54,18 @@ class Listeners:
|
|
|
54
54
|
all_attrs = set().union(*(listener.all_attrs for listener in listeners))
|
|
55
55
|
return cls(listeners, all_attrs)
|
|
56
56
|
|
|
57
|
-
def resolve(
|
|
57
|
+
def resolve(
|
|
58
|
+
self,
|
|
59
|
+
specs: "CallbackSpecList",
|
|
60
|
+
registry,
|
|
61
|
+
allowed_references: SpecReference = SPECS_ALL,
|
|
62
|
+
):
|
|
58
63
|
found_convention_specs = specs.conventional_specs & self.all_attrs
|
|
59
64
|
filtered_specs = [
|
|
60
|
-
spec
|
|
65
|
+
spec
|
|
66
|
+
for spec in specs
|
|
67
|
+
if spec.reference in allowed_references
|
|
68
|
+
and (not spec.is_convention or spec.func in found_convention_specs)
|
|
61
69
|
]
|
|
62
70
|
if not filtered_specs:
|
|
63
71
|
return
|
|
@@ -101,7 +109,7 @@ class Listeners:
|
|
|
101
109
|
if func is not None and func.__func__ is spec.func:
|
|
102
110
|
return callable_method(spec.attr_name, func, config.resolver_id)
|
|
103
111
|
|
|
104
|
-
return callable_method(spec.
|
|
112
|
+
return callable_method(spec.attr_name, spec.func, None)
|
|
105
113
|
|
|
106
114
|
def _search_name(self, name) -> Generator["Callable", None, None]:
|
|
107
115
|
for config in self.items:
|
statemachine/statemachine.py
CHANGED
|
@@ -9,11 +9,11 @@ from typing import Any
|
|
|
9
9
|
from typing import Dict
|
|
10
10
|
from typing import List
|
|
11
11
|
|
|
12
|
-
from
|
|
13
|
-
from
|
|
14
|
-
|
|
12
|
+
from .callbacks import SPECS_ALL
|
|
13
|
+
from .callbacks import SPECS_SAFE
|
|
15
14
|
from .callbacks import CallbacksExecutor
|
|
16
15
|
from .callbacks import CallbacksRegistry
|
|
16
|
+
from .callbacks import SpecReference
|
|
17
17
|
from .dispatcher import Listener
|
|
18
18
|
from .dispatcher import Listeners
|
|
19
19
|
from .engines.async_ import AsyncEngine
|
|
@@ -24,8 +24,10 @@ from .exceptions import InvalidDefinition
|
|
|
24
24
|
from .exceptions import InvalidStateValue
|
|
25
25
|
from .exceptions import TransitionNotAllowed
|
|
26
26
|
from .factory import StateMachineMetaclass
|
|
27
|
+
from .graph import iterate_states_and_transitions
|
|
27
28
|
from .i18n import _
|
|
28
29
|
from .model import Model
|
|
30
|
+
from .utils import run_async_from_sync
|
|
29
31
|
|
|
30
32
|
if TYPE_CHECKING:
|
|
31
33
|
from .state import State
|
|
@@ -177,8 +179,12 @@ class StateMachine(metaclass=StateMachineMetaclass):
|
|
|
177
179
|
continue
|
|
178
180
|
setattr(target, event.name, trigger)
|
|
179
181
|
|
|
180
|
-
def _add_listener(self, listeners: "Listeners"):
|
|
181
|
-
register = partial(
|
|
182
|
+
def _add_listener(self, listeners: "Listeners", allowed_references: SpecReference = SPECS_ALL):
|
|
183
|
+
register = partial(
|
|
184
|
+
listeners.resolve,
|
|
185
|
+
registry=self._callbacks_registry,
|
|
186
|
+
allowed_references=allowed_references,
|
|
187
|
+
)
|
|
182
188
|
for visited in iterate_states_and_transitions(self.states):
|
|
183
189
|
register(visited._specs)
|
|
184
190
|
|
|
@@ -210,7 +216,7 @@ class StateMachine(metaclass=StateMachineMetaclass):
|
|
|
210
216
|
def add_observer(self, *observers):
|
|
211
217
|
"""Add a listener."""
|
|
212
218
|
warnings.warn(
|
|
213
|
-
"""
|
|
219
|
+
"""Method `add_observer` has been renamed to `add_listener`.""",
|
|
214
220
|
DeprecationWarning,
|
|
215
221
|
stacklevel=2,
|
|
216
222
|
)
|
|
@@ -228,7 +234,8 @@ class StateMachine(metaclass=StateMachineMetaclass):
|
|
|
228
234
|
"""
|
|
229
235
|
self._listeners.update({o: None for o in listeners})
|
|
230
236
|
return self._add_listener(
|
|
231
|
-
Listeners.from_listeners(Listener.from_obj(o) for o in listeners)
|
|
237
|
+
Listeners.from_listeners(Listener.from_obj(o) for o in listeners),
|
|
238
|
+
allowed_references=SPECS_SAFE,
|
|
232
239
|
)
|
|
233
240
|
|
|
234
241
|
def _repr_html_(self):
|
statemachine/states.py
CHANGED
|
@@ -102,12 +102,13 @@ class States:
|
|
|
102
102
|
... def on_enter_completed(self):
|
|
103
103
|
... print("Completed!")
|
|
104
104
|
|
|
105
|
-
..
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
105
|
+
.. tip::
|
|
106
|
+
When you assign the result of ``States.from_enum`` to a class-level variable in your
|
|
107
|
+
:ref:`StateMachine`, you're all set. You can use any name for this variable. In this
|
|
108
|
+
example, we used ``_`` to show that the name doesn't matter. The metaclass will inspect
|
|
109
|
+
the variable of type :ref:`States (class)` and automatically assign the inner
|
|
110
|
+
:ref:`State` instances to the state machine.
|
|
111
|
+
|
|
111
112
|
|
|
112
113
|
Everything else is similar, the ``Enum`` is only used to declare the :ref:`State`
|
|
113
114
|
instances.
|
|
File without changes
|
|
File without changes
|