Simple finite-state machines in Python