forked from fgmacedo/python-statemachine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexceptions.py
More file actions
43 lines (29 loc) · 1.29 KB
/
Copy pathexceptions.py
File metadata and controls
43 lines (29 loc) · 1.29 KB
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
from collections.abc import MutableSet
from typing import TYPE_CHECKING
from .i18n import _
if TYPE_CHECKING:
from .event import Event
from .state import State
class StateMachineError(Exception):
"Base exception for this project, all exceptions that can be raised inherit from this class."
class InvalidDefinition(StateMachineError):
"The state machine has a definition error"
class InvalidStateValue(InvalidDefinition):
"The current model state value is not mapped to a state definition."
def __init__(self, value, msg=None):
self.value = value
if msg is None:
msg = _("{!r} is not a valid state value.").format(value)
super().__init__(msg)
class AttrNotFound(InvalidDefinition):
"There's no method or property with the given name"
class TransitionNotAllowed(StateMachineError):
"Raised when there's no transition that can run from the current :ref:`configuration`."
def __init__(self, event: "Event | None", configuration: MutableSet["State"]):
self.event = event
self.configuration = configuration
name = ", ".join(str(s.name) for s in configuration)
msg = _("Can't {} when in {}.").format(
self.event and self.event.name or "transition", name
)
super().__init__(msg)