Python "state machine" module