Skip to content

Commit

Permalink
serializer and unserializer methods
Browse files Browse the repository at this point in the history
  • Loading branch information
glyph committed Sep 17, 2015
1 parent fe233fe commit ee5764e
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions automat/_methodical.py
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,40 @@ def _oneTransition(self, startState, inputToken, endState, outputTokens,
inputToken.collectors[startState] = collector


@_keywords_only
def serializer(self):
"""
"""
def decorator(decoratee):
@wraps(decoratee)
def serialize(oself):
transitioner = _transitionerFromInstance(oself, self._symbol,
self._automaton)
return decoratee(oself, transitioner._state.serialized)
return serialize
return decorator

@_keywords_only
def unserializer(self):
"""
"""
def decorator(decoratee):
@wraps(decoratee)
def unserialize(oself, *args, **kwargs):
state = decoratee(oself, *args, **kwargs)
mapping = {}
for eachState in self._automaton.states():
mapping[eachState.serialized] = eachState
transitioner = _transitionerFromInstance(
oself, self._symbol, self._automaton)
transitioner._state = mapping[state]
return None # it's on purpose
return unserialize
return decorator


def graphviz(self):
"""
Visualize this state machine using graphviz.
Expand Down

0 comments on commit ee5764e

Please sign in to comment.