human
Complete this python program:
def StateHandler(auth_required=True):
assistant
#Here is the Python code you requested.

    """A convenience decorator for state methods.
    Args:
    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
    """
    def Decorator(f):
        'Initialised    Decorator.'
        @functools.wraps(f)
        def Decorated(self, responses=None, request=None, direct_response=None):
            'A    decorator    that    defines    allowed    follow    up    states    for    a    method.\n\n                        Args:\n                                self:    The    self    of    the    wrapped    function.\n\n                                responses:    The    responses    for    this    state.\n\n                                request:    The    request    sent    out    originally.\n\n                                direct_response:    A    final    responses    object    that    does    not    need    wrapping\n                                                                                                    again.    If    given,    neither    request    nor    responses    is    used.\n\n                        Returns:\n                                This    calls    the    state    and    returns    the    obtained    result.\n                        '
            if ('r' in self.mode):
                pending_termination = self.Get(self.Schema.PENDING_TERMINATION)
                if pending_termination:
                    self.Error(pending_termination.reason)
                    return
            runner = self.GetRunner()
            if (direct_response is not None):
                return f(self, direct_response)
            if (not isinstance(responses, Responses)):
                responses = Responses(request=request, responses=responses, auth_required=auth_required)
            if responses.status:
                runner.SaveResourceUsage(request, responses)
            stats.STATS.IncrementCounter('grr_worker_states_run')
            if (f.__name__ == 'Start'):
                stats.STATS.IncrementCounter('flow_starts', fields=[self.Name()])
            args = [self, responses]
            res = f(*args[:f.func_code.co_argcount])
            return res
        return Decorated
    return Decorator