@@ -38,7 +38,6 @@ def __init__(self, name, on_enter=None, on_exit=None,
38
38
callable, or a list of strings.
39
39
ignore_invalid_triggers (Boolean): Optional flag to indicate if
40
40
unhandled/invalid triggers should raise an exception
41
-
42
41
"""
43
42
self .name = name
44
43
self .ignore_invalid_triggers = ignore_invalid_triggers
@@ -70,37 +69,37 @@ def add_callback(self, trigger, func):
70
69
71
70
class Condition (object ):
72
71
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
104
103
105
104
106
105
class Transition (object ):
@@ -323,7 +322,6 @@ def __init__(self, model=None, states=None, initial=None, transitions=None,
323
322
executed in a state callback function will be queued and executed later.
324
323
Due to the nature of the queued processing, all transitions will
325
324
_always_ return True since conditional checks cannot be conducted at queueing time.
326
-
327
325
**kwargs additional arguments passed to next class in MRO. This can be ignored in most cases.
328
326
"""
329
327
@@ -333,9 +331,7 @@ def __init__(self, model=None, states=None, initial=None, transitions=None,
333
331
raise MachineError ('Passing arguments {0} caused an inheritance error: {1}' .format (kwargs .keys (), e ))
334
332
335
333
self .model = self if model is None else model
336
- self .alphabet = self .events .keys () # a simple renaming
337
334
self .states = OrderedDict ()
338
- self .final_states = set ()
339
335
self .events = {}
340
336
self .current_state = None
341
337
self .send_event = send_event
@@ -381,11 +377,6 @@ def initial(self):
381
377
""" Return the initial state. """
382
378
return self ._initial
383
379
384
- @property
385
- def final (self ):
386
- """ Return the set of final (or 'accepting') states """
387
- return self .final_states
388
-
389
380
@property
390
381
def has_queue (self ):
391
382
""" Return boolean indicating if machine has queue or not """
@@ -395,10 +386,6 @@ def is_state(self, state):
395
386
""" Check whether the current state matches the named state. """
396
387
return self .current_state .name == state
397
388
398
- def is_final (self , state ):
399
- """ Check whether the named state is a final state. """
400
- return state in self .final_states
401
-
402
389
def get_state (self , state ):
403
390
""" Return the State instance with the passed name. """
404
391
if state not in self .states :
@@ -412,12 +399,6 @@ def set_state(self, state):
412
399
self .current_state = state
413
400
self .model .state = self .current_state .name
414
401
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
-
421
402
def add_state (self , * args , ** kwargs ):
422
403
""" Alias for add_states. """
423
404
self .add_states (* args , ** kwargs )
@@ -563,20 +544,6 @@ def _callback(self, func, event_data):
563
544
else :
564
545
func (* event_data .args , ** event_data .kwargs )
565
546
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
-
580
547
def _process (self , trigger ):
581
548
582
549
# default processing
0 commit comments