Module model¶
- class sismic.model.ActionStateMixin(on_entry=None, on_exit=None)¶
Bases:
object
State that can define actions on entry and on exit.
- class sismic.model.BasicState(name, on_entry=None, on_exit=None)¶
Bases:
ContractMixin
,StateMixin
,ActionStateMixin
,TransitionStateMixin
A basic state, with a name, transitions, actions, etc. but no child state.
- class sismic.model.CompoundState(name, initial=None, on_entry=None, on_exit=None)¶
Bases:
ContractMixin
,StateMixin
,ActionStateMixin
,TransitionStateMixin
,CompositeStateMixin
Compound states must have children states.
- class sismic.model.ContractMixin¶
Bases:
object
Mixin with a contract: preconditions, postconditions and invariants.
- class sismic.model.DeepHistoryState(name, on_entry=None, on_exit=None, memory=None)¶
Bases:
ContractMixin
,StateMixin
,ActionStateMixin
,HistoryStateMixin
A deep history state resumes the execution of its parent, and of every nested active states in its parent.
- class sismic.model.Event(name, **additional_parameters)¶
Bases:
object
An event with a name and (optionally) some data passed as named parameters.
The list of parameters can be obtained using dir(event). Notice that name and data are reserved names. If a delay parameter is provided, then this event will be considered as a delayed event (and won’t be executed until given delay has elapsed).
When two events are compared, they are considered equal if their names and their data are equal.
- Parameters:
name (
str
) – name of the event.data – additional data passed as named parameters.
- class sismic.model.FinalState(name, on_entry=None, on_exit=None)¶
Bases:
ContractMixin
,StateMixin
,ActionStateMixin
Final state has NO transition and is used to detect state machine termination.
- class sismic.model.HistoryStateMixin(memory=None)¶
Bases:
object
History state has a memory that can be resumed.
- Parameters:
memory (
str
) – name of the initial state
- class sismic.model.InternalEvent(name, **additional_parameters)¶
Bases:
Event
Subclass of Event that represents an internal event.
- class sismic.model.MacroStep(time, steps)¶
Bases:
object
A macro step is a list of micro steps.
- Parameters:
- property transitions: List[Transition]¶
A (possibly empty) list of transitions that were triggered.
- class sismic.model.MetaEvent(name, **additional_parameters)¶
Bases:
Event
Subclass of Event that represents a MetaEvent, as used in property statecharts.
- class sismic.model.MicroStep(event=None, transition=None, entered_states=None, exited_states=None, sent_events=None)¶
Bases:
object
Create a micro step.
A step consider event, takes a transition and results in a list of entered_states and a list of exited_states. Order in the two lists is REALLY important!
- Parameters:
event (
Event
) – Event or None in case of eventless transitiontransition (
Transition
) – a Transition or None if no processed transitionentered_states (
List
[str
]) – possibly empty list of entered statesexited_states (
List
[str
]) – possibly empty list of exited statessent_events (
List
[Event
]) – a possibly empty list of events that are sent during the step
- class sismic.model.OrthogonalState(name, on_entry=None, on_exit=None)¶
Bases:
ContractMixin
,StateMixin
,ActionStateMixin
,TransitionStateMixin
,CompositeStateMixin
Orthogonal states run their children simultaneously.
- class sismic.model.ShallowHistoryState(name, on_entry=None, on_exit=None, memory=None)¶
Bases:
ContractMixin
,StateMixin
,ActionStateMixin
,HistoryStateMixin
A shallow history state resumes the execution of its parent. It activates the latest visited state of its parent.
- class sismic.model.StateMixin(name)¶
Bases:
object
State element with a name.
- Parameters:
name (
str
) – name of the state
- class sismic.model.Statechart(name, description=None, preamble=None)¶
Bases:
object
Python structure for a statechart
- Parameters:
- property preamble¶
Preamble code
- property states¶
List of state names in lexicographic order.
- state_for(name)¶
Return the state instance that has given name.
- Parameters:
name (
str
) – a state name- Return type:
- Returns:
a StateMixin that has the same name or None
- Raises:
StatechartError – if state does not exist
- parent_for(name)¶
Return the name of the parent of given state name.
- Parameters:
name (
str
) – a state name- Return type:
- Returns:
its parent name, or None.
- Raises:
StatechartError – if state does not exist
- children_for(name)¶
Return the names of the children of the given state.
- Parameters:
name (
str
) – a state name- Return type:
- Returns:
a (possibly empty) list of children
- Raises:
StatechartError – if state does not exist
- ancestors_for(name)¶
Return an ordered list of ancestors for the given state. Ancestors are ordered by decreasing depth.
- Parameters:
name (
str
) – name of the state- Return type:
- Returns:
state’s ancestors
- Raises:
StatechartError – if state does not exist
- descendants_for(name)¶
Return an ordered list of descendants for the given state. Descendants are ordered by increasing depth.
- Parameters:
name (
str
) – name of the state- Return type:
- Returns:
state’s descendants
- Raises:
StatechartError – if state does not exist
- depth_for(name)¶
Return the depth of given state (1-indexed).
- Parameters:
name (
str
) – name of the state- Return type:
- Returns:
state depth
- Raises:
StatechartError – if state does not exist
- least_common_ancestor(name_first, name_second)¶
Return the deepest common ancestor for s1 and s2, or None if there is no common ancestor except root (top-level) state.
- Parameters:
- Return type:
- Returns:
name of deepest common ancestor or None
- Raises:
StatechartError – if state does not exist
- leaf_for(names)¶
Return the leaves of names.
Considering the list of states names in names, return a list containing each element of names such that this element has no descendant in names.
- Parameters:
- Return type:
- Returns:
the names of the leaves in names
- Raises:
StatechartError – if a state does not exist
- property transitions¶
List of available transitions
- add_transition(transition)¶
Register given transition and register it on the source state
- Parameters:
transition (
Transition
) – transition to add- Raises:
- Return type:
- remove_transition(transition)¶
Remove given transitions.
- Parameters:
transition (
Transition
) – a Transition instance- Raises:
StatechartError – if transition is not registered
- Return type:
- rotate_transition(transition, new_source='', new_target='')¶
Rotate given transition.
You MUST specify either new_source (a valid state name) or new_target (a valid state name or None) or both.
- Parameters:
transition (
Transition
) – a Transition instancenew_source (
str
) – a state name
- Raises:
StatechartError – if given transition or a given state does not exist.
- Return type:
- transitions_from(source)¶
Return the list of transitions whose source is given name.
- Parameters:
source (
str
) – name of source state- Return type:
- Returns:
a list of Transition instances
- Raises:
StatechartError – if state does not exist
- transitions_to(target)¶
Return the list of transitions whose target is given name. Internal transitions are returned too.
- Parameters:
target (
str
) – name of target state- Return type:
- Returns:
a list of Transition instances
- Raises:
StatechartError – if state does not exist
- transitions_with(event)¶
Return the list of transitions that can be triggered by given event name.
- Parameters:
event (
str
) – name of the event- Return type:
- Returns:
a list of Transition instances
- events_for(name_or_names=None)¶
Return a list containing the name of every event that guards a transition in this statechart.
If name_or_names is specified, it must be the name of a state (or a list of such names). Only transitions that have a source state from this list will be considered. By default, the list contains all the states.
- add_state(state, parent)¶
Add given state (a StateMixin instance) on given parent (its name as an str). If given state should be use as a root state, set parent to None.
- Parameters:
state (
StateMixin
) – state to add
- Raises:
- Return type:
- remove_state(name)¶
Remove given state.
The transitions that involve this state will also be removed. If the state is the target of an initial or memory property, their value will be set to None. If the state has children, they will be removed too.
- Parameters:
name (
str
) – name of a state- Raises:
- Return type:
- rename_state(old_name, new_name)¶
Change state name, and adapt transitions, initial state, memory, etc.
- move_state(name, new_parent)¶
Move given state (and its children) such that its new parent is new_parent.
Notice that a state cannot be moved inside itself or inside one of its descendants. If the state to move is the target of an initial or memory property of its parent, this property will be set to None. The same occurs if given state is an history state.
- copy_from_statechart(statechart, *, source, replace, renaming_func=<function Statechart.<lambda>>)¶
Copy (a part of) given statechart into current one.
Copy source state, all its descendants and all involved transitions from statechart into current statechart. The source state will override replace state (but will be renamed to replace), and all its descendants in statechart will be copied into current statechart.
All the transitions that are involved in the process must be fully contained in source state (ie. for all transition T: S->T, if S (resp. T) is a descendant-or-self of source, then T (resp. S) must be a descendant-or-self of source).
If necessary, callable renaming_func can be provided. This function should accept a (state) name and return a (new state) name. Use renaming_func to avoid conflicting names in target statechart.
- Parameters:
- Return type:
- validate()¶
Checks that every CompoundState’s initial state refer to one of its children Checks that every HistoryStateMixin’s memory refer to one of its parent’s children
- Return type:
- Returns:
True
- Raises:
- class sismic.model.Transition(source, target=None, event=None, guard=None, action=None, priority=None)¶
Bases:
ContractMixin
Represent a transition from a source state to a target state.
A transition can be eventless (no event) or internal (no target). A condition (code as string) can be specified as a guard.
- Parameters:
- property internal¶
Boolean indicating whether this transition is an internal transition.
- property eventless¶
Boolean indicating whether this transition is an eventless transition.