def _deserialize_response(self, payload): """Convert string into httplib2 response and content. Args: payload: string, headers and body as a string. Returns: A pair (resp, content), such as would be returned from httplib2.request. """ # Strip off the status line status_line, payload = payload.split('\n', 1) protocol, status, reason = status_line.split(' ', 2) # Parse the rest of the response parser = FeedParser() parser.feed(payload) msg = parser.close() msg['status'] = status # Create httplib2.Response from the parsed headers. resp = Response(msg) resp.reason = reason resp.version = int(protocol.split('/', 1)[1].replace('.', '')) content = payload.split('\r\n\r\n', 1)[1] return resp, content
def _response_generator(bad_status_code, reason): # TODO: Should this be a mock? We shouldn't know any more than # necessary about the interface of Response bad_response = Response({}) bad_response.status = bad_status_code bad_response.reason = reason good_response = Response({}) good_response.status = 200 content = 'some content' return [(bad_response, content), (bad_response, content), (good_response, content)]
def create_http_response(status, reason): resp = Response({'status': status}) resp.reason = reason return resp