Skip to content

Instantly share code, notes, and snippets.

@glyph
Created September 16, 2015 21:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save glyph/e40fd64802db4f8b59a4 to your computer and use it in GitHub Desktop.
Save glyph/e40fd64802db4f8b59a4 to your computer and use it in GitHub Desktop.
class Mechanism(object):
m = MethodicalMachine()
def __init__(self):
self.value = 1
@m.state(serialized="first-state")
def first(self):
"First state."
@m.state(serialized="second-state")
def second(self):
"Second state."
@m.serializer
def save(self, state):
return {
'machine-state': state,
'some-value': self.value,
}
@m.unserializer
def load(self, blob):
self.value = blob['some-value']
return blob['machine-state']
@classmethod
def fromBlob(cls, blob):
self = cls()
self.load(blob)
return self
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment