@@ -38,7 +38,6 @@ def __init__(self, name, on_enter=None, on_exit=None,
3838 callable, or a list of strings.
3939 ignore_invalid_triggers (Boolean): Optional flag to indicate if
4040 unhandled/invalid triggers should raise an exception
41-
4241 """
4342 self .name = name
4443 self .ignore_invalid_triggers = ignore_invalid_triggers
@@ -70,37 +69,37 @@ def add_callback(self, trigger, func):
7069
7170class Condition (object ):
7271
73- def __init__ (self , func , target = True ):
74- """
75- Args:
76- func (string): Name of the condition-checking callable
77- target (bool): Indicates the target state--i.e., when True,
78- the condition-checking callback should return True to pass,
79- and when False, the callback should return False to pass.
80- Notes:
81- This class should not be initialized or called from outside a
82- Transition instance, and exists at module level (rather than
83- nesting under the ransition class) only because of a bug in
84- dill that prevents serialization under Python 2.7.
85- """
86- self .func = func
87- self .target = target
88- 89- def check (self , event_data ):
90- """ Check whether the condition passes.
91- Args:
92- event_data (EventData): An EventData instance to pass to the
93- condition (if event sending is enabled) or to extract arguments
94- from (if event sending is disabled). Also contains the data
95- model attached to the current machine which is used to invoke
96- the condition.
97- """
98- predicate = getattr (event_data .model , self .func )
99- if event_data .machine .send_event :
100- return predicate (event_data ) == self .target
101- else :
102- return predicate (
103- * event_data .args , ** event_data .kwargs ) == self .target
72+ def __init__ (self , func , target = True ):
73+ """
74+ Args:
75+ func (string): Name of the condition-checking callable
76+ target (bool): Indicates the target state--i.e., when True,
77+ the condition-checking callback should return True to pass,
78+ and when False, the callback should return False to pass.
79+ Notes:
80+ This class should not be initialized or called from outside a
81+ Transition instance, and exists at module level (rather than
82+ nesting under the ransition class) only because of a bug in
83+ dill that prevents serialization under Python 2.7.
84+ """
85+ self .func = func
86+ self .target = target
87+ 88+ def check (self , event_data ):
89+ """ Check whether the condition passes.
90+ Args:
91+ event_data (EventData): An EventData instance to pass to the
92+ condition (if event sending is enabled) or to extract arguments
93+ from (if event sending is disabled). Also contains the data
94+ model attached to the current machine which is used to invoke
95+ the condition.
96+ """
97+ predicate = getattr (event_data .model , self .func )
98+ if event_data .machine .send_event :
99+ return predicate (event_data ) == self .target
100+ else :
101+ return predicate (
102+ * event_data .args , ** event_data .kwargs ) == self .target
104103
105104
106105class Transition (object ):
@@ -323,7 +322,6 @@ def __init__(self, model=None, states=None, initial=None, transitions=None,
323322 executed in a state callback function will be queued and executed later.
324323 Due to the nature of the queued processing, all transitions will
325324 _always_ return True since conditional checks cannot be conducted at queueing time.
326-
327325 **kwargs additional arguments passed to next class in MRO. This can be ignored in most cases.
328326 """
329327
@@ -333,9 +331,7 @@ def __init__(self, model=None, states=None, initial=None, transitions=None,
333331 raise MachineError ('Passing arguments {0} caused an inheritance error: {1}' .format (kwargs .keys (), e ))
334332
335333 self .model = self if model is None else model
336- self .alphabet = self .events .keys () # a simple renaming
337334 self .states = OrderedDict ()
338- self .final_states = set ()
339335 self .events = {}
340336 self .current_state = None
341337 self .send_event = send_event
@@ -381,11 +377,6 @@ def initial(self):
381377 """ Return the initial state. """
382378 return self ._initial
383379
384- @property
385- def final (self ):
386- """ Return the set of final (or 'accepting') states """
387- return self .final_states
388- 389380 @property
390381 def has_queue (self ):
391382 """ Return boolean indicating if machine has queue or not """
@@ -395,10 +386,6 @@ def is_state(self, state):
395386 """ Check whether the current state matches the named state. """
396387 return self .current_state .name == state
397388
398- def is_final (self , state ):
399- """ Check whether the named state is a final state. """
400- return state in self .final_states
401- 402389 def get_state (self , state ):
403390 """ Return the State instance with the passed name. """
404391 if state not in self .states :
@@ -412,12 +399,6 @@ def set_state(self, state):
412399 self .current_state = state
413400 self .model .state = self .current_state .name
414401
415- def set_final (self , state ):
416- """ Set state as a final ('accepting') state. """
417- if state not in self .states :
418- raise MachineError ("Can't set state as final. State not in machine." )
419- self .final_states .add (state )
420- 421402 def add_state (self , * args , ** kwargs ):
422403 """ Alias for add_states. """
423404 self .add_states (* args , ** kwargs )
@@ -563,20 +544,6 @@ def _callback(self, func, event_data):
563544 else :
564545 func (* event_data .args , ** event_data .kwargs )
565546
566- def read (self , symbol ):
567- """
568- This has been added to the stock "transitions" library to be a more appropiate
569- transition handling method for algorithm implementation.
570-
571- For a transition q0 -[a]-> q1 the stock library can do
572- machine.a()
573- machine._process(s.a)
574- machine.events['a']_trigger()
575- none of which are particularly good for our purposes. With read() you can simply do
576- machine.read('a')
577- """
578- return self .events [symbol ]._trigger ()
579- 580547 def _process (self , trigger ):
581548
582549 # default processing
0 commit comments