Package docutils :: Module statemachine :: Class State
[show private | hide private]
[frames | no frames]

Class State

Known Subclasses:
StateWS

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.


Method Summary
  __init__(self, state_machine, debug)
Initialize a State object; make & add initial transitions.
  add_initial_transitions(self)
Make and add transitions listed in self.initial_transitions.
  add_transition(self, name, transition)
Add a transition to the start of the transition list.
  add_transitions(self, names, transitions)
Add a list of transitions to the start of the transition list.
  bof(self, context)
Handle beginning-of-file.
  eof(self, context)
Handle end-of-file.
  make_transition(self, name, next_state)
Make & return a transition tuple based on name.
  make_transitions(self, name_list)
Return a list of transition names and a transition mapping.
  no_match(self, context, transitions)
Called when there is no match from StateMachine.check_line().
  nop(self, match, context, next_state)
A "do nothing" transition method.
  remove_transition(self, name)
Remove a transition by name.
  runtime_init(self)
Initialize this State before running the state machine; called from self.state_machine.run().
  unlink(self)
Remove circular references to objects no longer required.

Class Variable Summary
NoneType initial_transitions = None                                                                  
NoneType nested_sm = None                                                                  
NoneType nested_sm_kwargs = None                                                                  
NoneType patterns = None                                                                  

Method Details

__init__(self, state_machine, debug=0)
(Constructor)

Initialize a State object; make & add initial transitions.

Parameters:

add_initial_transitions(self)

Make and add transitions listed in self.initial_transitions.

add_transition(self, name, transition)

Add a transition to the start of the transition list.

Parameter transition: a ready-made transition 3-tuple.

Exception: DuplicateTransitionError.

add_transitions(self, names, transitions)

Add a list of transitions to the start of the transition list.

Parameters:

  • names: a list of transition names.
  • transitions: a mapping of names to transition tuples.

Exceptions: DuplicateTransitionError, UnknownTransitionError.

bof(self, context)

Handle beginning-of-file. Return unchanged context, empty result.

Override in subclasses.

Parameter context: application-defined storage.

eof(self, context)

Handle end-of-file. Return empty result.

Override in subclasses.

Parameter context: application-defined storage.

make_transition(self, name, next_state=None)

Make & return a transition tuple based on name.

This is a convenience function to simplify transition creation.

Parameters:

  • name: a string, the name of the transition pattern & method. This State object must have a method called 'name', and a dictionary self.patterns containing a key 'name'.
  • next_state: a string, the name of the next State object for this transition. A value of None (or absent) implies no state change (i.e., continue with the same state).

Exceptions: TransitionPatternNotFound, TransitionMethodNotFound.

make_transitions(self, 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(self, context, transitions)

Called when there is no match from StateMachine.check_line().

Return the same values returned by transition methods:

  • context: unchanged;
  • next state name: None;
  • empty result list.

Override in subclasses to catch this event.

nop(self, 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(self, name)

Remove a transition by name.

Exception: UnknownTransitionError.

runtime_init(self)

Initialize this State before running the state machine; called from self.state_machine.run().

unlink(self)

Remove circular references to objects no longer required.

Class Variable Details

initial_transitions

Type:
NoneType
Value:
None                                                                  

nested_sm

Type:
NoneType
Value:
None                                                                  

nested_sm_kwargs

Type:
NoneType
Value:
None                                                                  

patterns

Type:
NoneType
Value:
None                                                                  

Generated by Epydoc 2.0 on Tue Jul 22 05:31:39 2003 http://epydoc.sf.net