7 A state machine that can be locked. 8 When locked, no transition can be done regardless of the resulting outcome. 9 However, if any outcome would be triggered, the outcome will be stored 10 and the state won't be executed anymore until it is unlocked and the stored outcome is set. 12 path_for_switch =
None 15 super(LockableStateMachine, self).
__init__(*args, **kwargs)
20 Looks for the current state (traversing all state machines down to the real state). 22 @return: The current state (not state machine) 25 while isinstance(container._current_state, LockableStateMachine):
26 container = container._current_state
27 return container._current_state
30 return transition_target
in self.
_labels 33 if outcome
is None or outcome ==
'None':
35 transition_target = self.
_transitions[state].get(outcome)
38 self.parent.transition_allowed(self.
name, transition_target))))
43 if (LockableStateMachine.path_for_switch
is not None 44 and LockableStateMachine.path_for_switch.startswith(self.
path)):
45 path_segments = LockableStateMachine.path_for_switch.replace(self.
path,
"", 1).split(
"/")
46 wanted_state = path_segments[1]
48 if len(path_segments) <= 2:
49 LockableStateMachine.path_for_switch =
None 50 return super(LockableStateMachine, self).
execute(userdata)
56 old_state = self.
_labels[state.name]
57 state._parent = old_state._parent
58 self.
_states[self._states.index(old_state)] = state
59 self.
_labels[state.name] = state
63 self._states.remove(state)
72 return self._parent.lock(path)
81 return self._parent.unlock(path)
93 if isinstance(state, LockableStateMachine):
94 result = state.is_locked_inside()
96 result = state.is_locked()
105 if state.is_locked():
107 elif isinstance(state, LockableStateMachine):
108 return state.get_locked_state()
def __init__(self, args, kwargs)
def remove_state(self, state)
def get_locked_state(self)
def transition_allowed(self, state, outcome)
def replace_userdata(self, userdata)
def execute(self, userdata)
def is_locked_inside(self)
def replace_state(self, state)
def _is_internal_transition(self, transition_target)