'Stores new flow requests and responses to the data store.
Args:
new_requests: A list of tuples (request, timestamp) to store in the
data store.
new_responses: A list of tuples (response, timestamp) to store in the
data store.
requests_to_delete: A list of requests that should be deleted from the
data store.
token: A data store token.'

def StoreRequestsAndResponses(self, new_requests=None, new_responses=None, requests_to_delete=None, token=None):

    to_write = {}
    if (new_requests is not None):
        for (request, timestamp) in new_requests:
            subject = request.session_id.Add('state')
            queue = to_write.setdefault(subject, {})
            queue.setdefault((self.FLOW_REQUEST_TEMPLATE % request.id), []).append((request.SerializeToString(), timestamp))
    if (new_responses is not None):
        for (response, timestamp) in new_responses:
            if (response.type == rdf_flows.GrrMessage.Type.STATUS):
                subject = response.session_id.Add('state')
                attribute = (self.FLOW_STATUS_TEMPLATE % response.request_id)
                to_write.setdefault(subject, {}).setdefault(attribute, []).append((response.SerializeToString(), timestamp))
            subject = self.GetFlowResponseSubject(response.session_id, response.request_id)
            attribute = (self.FLOW_RESPONSE_TEMPLATE % (response.request_id, response.response_id))
            to_write.setdefault(subject, {}).setdefault(attribute, []).append((response.SerializeToString(), timestamp))
    to_delete = {}
    if (requests_to_delete is not None):
        for request in requests_to_delete:
            queue = to_delete.setdefault(request.session_id.Add('state'), [])
            queue.append((self.FLOW_REQUEST_TEMPLATE % request.id))
            queue.append((self.FLOW_STATUS_TEMPLATE % request.id))
    for subject in (set(to_write) | set(to_delete)):
        self.MultiSet(subject, to_write.get(subject, {}), to_delete=to_delete.get(subject, []), sync=True, token=token)
