class VCRHTTPResponse(object): """ Stub reponse class that gets returned instead of a HTTPResponse """ def __init__(self, recorded_response): self.recorded_response = recorded_response self.reason = recorded_response['status']['message'] self.status = recorded_response['status']['code'] self.version = None self._content = StringIO(self.recorded_response['body']['string']) self.msg = HTTPMessage(StringIO('')) for k, v in self.recorded_response['headers'].iteritems(): self.msg.addheader(k, v) self.length = self.msg.getheader('content-length') or None def read(self, chunked=False): # Note: I'm pretty much ignoring any chunking stuff because # I don't really understand what it is or how it works. return self._content.read() def isclosed(self): # Urllib3 seems to call this because it actually uses # the weird chunking support in httplib return True def getheaders(self): return self.recorded_response['headers'].iteritems()
def parse_headers_backwards_compat(header_dict): """ In vcr 0.6.0, I changed the cassettes to store headers as a list instead of a dict. This method parses the old dictionary-style headers for backwards-compatability reasons. """ msg = HTTPMessage(StringIO("")) for key, val in header_dict.iteritems(): msg.addheader(key, val) msg.headers.append("{0}:{1}".format(key, val)) return msg
def parse_headers_backwards_compat(header_dict): """ In vcr 0.6.0, I changed the cassettes to store headers as a list instead of a dict. This method parses the old dictionary-style headers for backwards-compatability reasons. """ msg = HTTPMessage(StringIO("")) for key, val in header_dict.iteritems(): msg.addheader(key, val) msg.headers.append("{0}:{1}".format(key, val)) return msg
class VCRHTTPResponse(object): def __init__(self, recorded_response): self.recorded_response = recorded_response self.reason = recorded_response["status"]["message"] self.status = recorded_response["status"]["code"] self._content = StringIO(self.recorded_response["body"]["string"]) self.msg = HTTPMessage(StringIO("")) for k, v in self.recorded_response["headers"].iteritems(): self.msg.addheader(k, v) def read(self, chunked=False): return self._content.read()
class VCRHTTPResponse(object): """ Stub reponse class that gets returned instead of a HTTPResponse """ def __init__(self, recorded_response): self.recorded_response = recorded_response self.reason = recorded_response['status']['message'] self.status = recorded_response['status']['code'] self.version = None self._content = StringIO(self.recorded_response['body']['string']) # We are skipping the header parsing (they have already been parsed # at this point) and directly adding the headers to the header # container, so just pass an empty StringIO. self.msg = HTTPMessage(StringIO('')) for key, val in self.recorded_response['headers'].iteritems(): self.msg.addheader(key, val) # msg.addheaders adds the headers to msg.dict, but not to # the msg.headers list representation of headers, so # I have to add it to both. self.msg.headers.append("{0}:{1}".format(key, val)) self.length = self.msg.getheader('content-length') or None def read(self, *args, **kwargs): # Note: I'm pretty much ignoring any chunking stuff because # I don't really understand what it is or how it works. return self._content.read(*args, **kwargs) def close(self): return True def isclosed(self): # Urllib3 seems to call this because it actually uses # the weird chunking support in httplib return True def getheaders(self): return self.recorded_response['headers'].iteritems()