class Robot(): name = 'R2-D2' sleeping = State(initial=True) running = State() cleaning = State() run = Event(from_states=sleeping, to_state=running) cleanup = Event(from_states=running, to_state=cleaning) sleep = Event(from_states=(running, cleaning), to_state=sleeping) @before('sleep') def do_one_thing(self): print("{} is sleepy".format(self.name)) @before('sleep') def do_another_thing(self): print("{} is REALLY sleepy".format(self.name)) @after('sleep') def snore(self): print("Zzzzzzzzzzzz") @after('sleep') def snore(self): print("Zzzzzzzzzzzzzzzzzzzzzz")
class Puppy(Base): __tablename__ = 'puppies' id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) name = sqlalchemy.Column(sqlalchemy.String) sleeping = State(initial=True) running = State() cleaning = State() run = Event(from_states=sleeping, to_state=running) cleanup = Event(from_states=running, to_state=cleaning) sleep = Event(from_states=(running, cleaning), to_state=sleeping) @before('sleep') def do_one_thing(self): print("{} is sleepy".format(self.name)) @before('sleep') def do_another_thing(self): print("{} is REALLY sleepy".format(self.name)) @after('sleep') def snore(self): print("Zzzzzzzzzzzz") @after('sleep') def snore(self): print("Zzzzzzzzzzzzzzzzzzzzzz")
class Robot(): name = 'R2-D2' sleeping = State(initial=True) running = State() cleaning = State() run = Event(from_states=sleeping, to_state=running) cleanup = Event(from_states=running, to_state=cleaning) sleep = Event(from_states=(running, cleaning), to_state=sleeping)
class Dog(object): sleeping = State(initial=True) running = State() run = Event(from_states=sleeping, to_state=running) sleep = Event(from_states=(running,), to_state=sleeping) @before('run') def on_run(self): things_done.append("Dog.ran")
class Person(object): sleeping = State(initial=True) running = State() cleaning = State() run = Event(from_states=sleeping, to_state=running) cleanup = Event(from_states=running, to_state=cleaning) sleep = Event(from_states=(running, cleaning), to_state=sleeping) @before('run') def on_run(self): things_done.append("Person.ran")
class Penguin(Base): __tablename__ = 'penguins' id = sqlalchemy.Column(sqlalchemy.Integer, primary_key=True) name = sqlalchemy.Column(sqlalchemy.String) sleeping = State(initial=True) running = State() cleaning = State() run = Event(from_states=sleeping, to_state=running) cleanup = Event(from_states=running, to_state=cleaning) sleep = Event(from_states=(running, cleaning), to_state=sleeping)