def _toNextState(self, context):
      """Sets state of to the next state, if new state is different. 
      calls onLeave and onEnter methods
      """
      if self._next_state is not self._current_state:
         if hasattr(self._current_state, 'onLeave'):
            self._current_state.onLeave(context)
         self._current_state = self._next_state
         if hasattr(self._current_state, 'onEnter'):
            self._current_state.onEnter(context)
Sets state of to the next state, if new state is different. 
      calls onLeave and onEnter methods
      
recipes/Python/576613_Easy_State_Pattern__support_implementing_state/recipe-576613.py