State superclass. Contains a list of transitions, and transition methods.
Transition methods all have the same signature. They take 3 parameters:
Transition methods all return a 3-tuple:
Transition methods may raise an EOFError to cut processing short.
There are two implicit transitions, and corresponding transition methods are defined: bof() handles the beginning-of-file, and eof() handles the end-of-file. These methods have non-standard signatures and return values. bof() returns the initial context and results, and may be used to return a header string, or do any other processing needed. eof() should handle any remaining context and wrap things up; it returns the final processing result.
Typical applications need only subclass State (or a subclass), set the patterns and initial_transitions class attributes, and provide corresponding transition methods. The default object initialization will take care of constructing the list of transitions.
There are no base classes.
There are no implemented interfaces.
initial_transitions
(type: NoneType
)
None
nested_sm
(type: NoneType
)
None
nested_sm_kwargs
(type: NoneType
)
None
patterns
(type: NoneType
)
None
add_initial_transitions()
Make and add transitions listed in self.initial_transitions.
add_transition(name, transition)
Add a transition to the start of the transition list.
Parameter transition: a ready-made transition 3-tuple.
Exception: DuplicateTransitionError.
add_transitions(names, transitions)
Add a list of transitions to the start of the transition list.
Parameters:
Exceptions: DuplicateTransitionError, UnknownTransitionError.
bof(context)
Handle beginning-of-file. Return unchanged context, empty result.
Override in subclasses.
Parameter context: application-defined storage.
eof(context)
Handle end-of-file. Return empty result.
Override in subclasses.
Parameter context: application-defined storage.
make_transition(name, next_state=None)
Make & return a transition tuple based on name.
This is a convenience function to simplify transition creation.
Parameters:
Exceptions: TransitionPatternNotFound, TransitionMethodNotFound.
make_transitions(name_list)
Return a list of transition names and a transition mapping.
Parameter name_list: a list, where each entry is either a transition name string, or a 1- or 2-tuple (transition name, optional next state name).
no_match(context, transitions)
Called when there is no match from StateMachine.check_line().
Return the same values returned by transition methods:
Override in subclasses to catch this event.
nop(match, context, next_state)
A "do nothing" transition method.
Return unchanged context & next_state, empty result. Useful for simple state changes (actionless transitions).
remove_transition(name)
Remove a transition by name.
Exception: UnknownTransitionError.
runtime_init()
Initialize this State before running the state machine; called from self.state_machine.run().
unlink()
Remove circular references to objects no longer required.