'A mock for url handler processing from the server\'s POV.'

def UrlMock(self, num_messages=10, url=None, data=None, **kwargs):

    if ('server.pem' in url):
        return MakeResponse(200, utils.SmartStr(config.CONFIG['Frontend.certificate']))
    _ = kwargs
    try:
        comms_cls = rdf_flows.ClientCommunication
        self.client_communication = comms_cls.FromSerializedString(data)
        (self.messages, source, ts) = self.server_communicator.DecodeMessages(self.client_communication)
        self.assertEqual(source, self.client_cn)
        for (i, message) in enumerate(self.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')
        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)
        self.server_communicator.EncodeMessages(message_list, response_comms, destination=source, timestamp=ts, api_version=self.client_communication.api_version)
        return MakeResponse(200, response_comms.SerializeToString())
    except communicator.UnknownClientCert:
        raise MakeHTTPException(406)
    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 MakeHTTPException(500)
