'Fetches all Requests and Responses for a given session_id.'

def ReadRequestsAndResponses(self, session_id, timestamp=None, request_limit=None, response_limit=None, token=None):

    subject = session_id.Add('state')
    requests = {}
    for (predicate, serialized, _) in self.ResolvePrefix(subject, self.FLOW_REQUEST_PREFIX, token=token, limit=request_limit, timestamp=timestamp):
        request_id = predicate.split(':', 1)[1]
        requests[str(subject.Add(request_id))] = serialized
    response_data = dict(self.MultiResolvePrefix(requests.keys(), self.FLOW_RESPONSE_PREFIX, limit=response_limit, token=token, timestamp=timestamp))
    for (urn, request_data) in sorted(requests.items()):
        request = rdf_flows.RequestState.FromSerializedString(request_data)
        responses = []
        for (_, serialized, _) in response_data.get(urn, []):
            responses.append(rdf_flows.GrrMessage.FromSerializedString(serialized))
        (yield (request, sorted(responses, key=(lambda msg: msg.response_id))))
