def StateHandler(next_state="End", auth_required=True):
  """A convenience decorator for state methods.

  Args:
    next_state: One or more next states possible from here (can be a
                string or a list of strings). If a state attempts to
                redirect to a state other than on this (with
                CallClient) an exception is raised.

    auth_required: Do we require messages to be authenticated? If the
                message is not authenticated we raise.

  Raises:
    RuntimeError: If a next state is not specified.

  Returns:
    A decorator
  """

  if not isinstance(next_state, (basestring, list, tuple)):
    raise RuntimeError("Next state must be a string.")

  def Decorator(f):
    """Initialised Decorator."""
    # Allow next_state to be a single string
    if isinstance(next_state, basestring):
      next_states = set([next_state])
    else:
      next_states = set(next_state)

    @functools.wraps(f)
    def Decorated(self, responses=None, request=None, direct_response=None):
      """A decorator that defines allowed follow up states for a method.

      Args:
        self: The self of the wrapped function.

        responses: The responses for this state.

        request: The request sent out originally.

        direct_response: A final responses object that does not need wrapping
                         again. If given, neither request nor responses is used.

      Returns:
        This calls the state and returns the obtained result.
      """
      if self.mode in "r":
        pending_termination = self.Get(self.Schema.PENDING_TERMINATION)
        if pending_termination:
          self.Error(pending_termination.reason)
          return

      runner = self.GetRunner()
      next_states = Decorated.next_states

      old_next_states = runner.GetAllowedFollowUpStates()
      try:
        if direct_response is not None:
          runner.SetAllowedFollowUpStates(next_states)
          return f(self, direct_response)

        if isinstance(responses, Responses):
          next_states.update(responses.next_states)
        else:
          # Prepare a responses object for the state method to use:
          responses = Responses(request=request,
                                next_states=next_states,
                                responses=responses,
                                auth_required=auth_required)

          if responses.status:
            runner.SaveResourceUsage(request, responses)

        stats.STATS.IncrementCounter("grr_worker_states_run")
        runner.SetAllowedFollowUpStates(next_states)

        if f.__name__ == "Start":
          stats.STATS.IncrementCounter("flow_starts",
                                       fields=[self.Name()])

        # Run the state method (Allow for flexibility in prototypes)
        args = [self, responses]
        res = f(*args[:f.func_code.co_argcount])

        return res
      finally:
        runner.SetAllowedFollowUpStates(old_next_states)

    # Make sure the state function itself knows where its allowed to
    # go (This is used to introspect the state graph).
    Decorated.next_states = next_states

    return Decorated

  return Decorator
dataset/ETHPy150Open google/grr/grr/lib/flow.py/StateHandler/swapped operands of `in`