python implementation of a simple statemachine