Hierarchical State Machine for Python