diff options
author | Paul McGuire <ptmcg@austin.rr.com> | 2019-04-15 18:53:05 -0500 |
---|---|---|
committer | Paul McGuire <ptmcg@austin.rr.com> | 2019-04-15 18:53:05 -0500 |
commit | 6c447c4d663d0badddd84976033504c855325ce5 (patch) | |
tree | 81c7f74073236b499c3656f82a8179033c02f8b9 /examples/statemachine/documentSignoffDemo.py | |
parent | adf8dd00b736ba1934914e1db78528af02662b65 (diff) | |
download | pyparsing-git-6c447c4d663d0badddd84976033504c855325ce5.tar.gz |
Refactor generated State code to use overridden transition methods instead of overriding getattr; add generation of state-managing mixin class to delegate to _state instance variable, and reworked demos to use mixin instead of replicating state code
Diffstat (limited to 'examples/statemachine/documentSignoffDemo.py')
-rw-r--r-- | examples/statemachine/documentSignoffDemo.py | 21 |
1 files changed, 3 insertions, 18 deletions
diff --git a/examples/statemachine/documentSignoffDemo.py b/examples/statemachine/documentSignoffDemo.py index 58aa208..0cbfc1f 100644 --- a/examples/statemachine/documentSignoffDemo.py +++ b/examples/statemachine/documentSignoffDemo.py @@ -7,26 +7,11 @@ import statemachine import documentsignoffstate +print('\n'.join(t.__name__ for t in documentsignoffstate.DocumentRevisionState.transitions())) -class Document: +class Document(documentsignoffstate.DocumentRevisionStateMixin): def __init__(self): - # start light in Red state - self._state = documentsignoffstate.New() - - @property - def state(self): - return self._state - - # get behavior/properties from current state - def __getattr__(self, attrname): - attr = getattr(self._state, attrname) - if isinstance(getattr(documentsignoffstate, attrname, None), - documentsignoffstate.DocumentRevisionStateTransition): - return lambda : setattr(self, '_state', attr()) - return attr - - def __str__(self): - return "{0}: {1}".format(self.__class__.__name__, self._state) + self.initialize_state(documentsignoffstate.New()) def run_demo(): |