A simple Python implementation of a finite state machine.