def UrlMock(self, req, num_messages=10, **kwargs):
    if "server.pem" in req.get_full_url():
      return StringIO.StringIO(config_lib.CONFIG["Frontend.certificate"])

    _ = kwargs
    try:
      self.client_communication = rdf_flows.ClientCommunication(req.data)

      # Decrypt incoming messages
      self.messages, source, ts = self.server_communicator.DecodeMessages(
          self.client_communication)

      # Make sure the messages are correct
      self.assertEqual(source, self.client_cn)
      for i, message in enumerate(self.messages):
        # Do not check any status messages.
        if message.request_id:
          self.assertEqual(message.response_id, i)
          self.assertEqual(message.request_id, 1)
          self.assertEqual(message.session_id, "aff4:/W:session")

      # Now prepare a response
      response_comms = rdf_flows.ClientCommunication()
      message_list = rdf_flows.MessageList()
      for i in range(0, num_messages):
        message_list.job.Append(request_id=i, **self.server_response)

      # Preserve the timestamp as a nonce
      self.server_communicator.EncodeMessages(
          message_list, response_comms, destination=source,
          timestamp=ts, api_version=self.client_communication.api_version)

      return StringIO.StringIO(response_comms.SerializeToString())
    except communicator.UnknownClientCert:
      raise urllib2.HTTPError(url=None, code=406, msg=None, hdrs=None, fp=None)
    except Exception as e:
      logging.info("Exception in mock urllib2.Open: %s.", e)
      self.last_urlmock_error = e

      if flags.FLAGS.debug:
        pdb.post_mortem()

      raise urllib2.HTTPError(url=None, code=500, msg=None, hdrs=None, fp=None)
Parameters:
dataset/ETHPy150Open google/grr/grr/lib/communicator_test.py/HTTPClientTests.UrlMock--crossover with--dataset/ETHPy150Open alticelabs/meocloud-cli/meocloud/client/linux/protocol/daemon_core/UI.py/Client.notifySystem