1
# -*- test-case-name: vertex.test.test_statemachine -*-
3
NOTHING = 'nothing' # be quiet (no output)
7
initialState = None # a str describing initial state
9
states = None # dict, mapping state to dict of str input: (str output,
13
def __init__(self, initialState=None):
14
if initialState is None:
15
initialState = self.initialState
16
self.state = self.initialState
18
def transition(self, oldstate, newstate, datum, *a, **kw):
19
exitmeth = getattr(self, 'exit_%s' % (oldstate,), None)
20
entermeth = getattr(self, 'enter_%s' % (newstate,), None)
21
transmeth = getattr(self, 'transition_%s_to_%s' % (
22
oldstate.upper(), newstate.upper()), None)
23
for meth in exitmeth, entermeth, transmeth:
28
def input(self, datum, *a, **kw):
32
output, newstate = self.states[self.state][datum]
34
NEWSTATE = newstate.upper()
36
self.transition(OLDSTATE, NEWSTATE, DATUM, *a, **kw)
37
self.output(output, *a, **kw)
39
def output(self, datum, *a, **kw):
40
foo = getattr(self, 'output_' + datum.upper(), None)