def _GetActionInstance(self, action_name, arg=None, grr_worker=None,
                         action_worker_cls=None):
    """Run an action and generate responses.

    This basically emulates GRRClientWorker.HandleMessage().

    Args:
       action_name: The action to run.
       arg: A protobuf to pass the action.
       grr_worker: The GRRClientWorker instance to use. If not provided we make
         a new one.
       action_worker_cls: The action worker class to use for iterated actions.
         If not provided we use the default.
    Returns:
      A list of response protobufs.
    """
    # A mock SendReply() method to collect replies.
    def MockSendReply(mock_self, reply=None, **kwargs):
      if reply is None:
        reply = mock_self.out_rdfvalues[0](**kwargs)
      self.results.append(reply)

    if grr_worker is None:
      grr_worker = worker_mocks.FakeClientWorker()

    try:
      suspended_action_id = arg.iterator.suspended_action
      action = grr_worker.suspended_actions[suspended_action_id]

    except (AttributeError, __HOLE__):
      action_cls = actions.ActionPlugin.classes[action_name]
      if issubclass(action_cls, actions.SuspendableAction):
        action = action_cls(grr_worker=grr_worker,
                            action_worker_cls=action_worker_cls)
      else:
        action = action_cls(grr_worker=grr_worker)

    action.SendReply = types.MethodType(MockSendReply, action)

    return action
dataset/ETHPy150Open google/grr/grr/lib/test_lib.py/EmptyActionTest._GetActionInstance