Coverage for vcr.request : 62%

Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
""" VCR's representation of a request.
There is a weird quirk in HTTP. You can send the same header twice. For this reason, headers are represented by a dict, with lists as the values. However, it appears that HTTPlib is completely incapable of sending the same header twice. This puts me in a weird position: I want to be able to accurately represent HTTP headers in cassettes, but I don't want the extra step of always having to do [0] in the general case, i.e. request.headers['key'][0]
In addition, some servers sometimes send the same header more than once, and httplib *can* deal with this situation.
Futhermore, I wanted to keep the request and response cassette format as similar as possible.
For this reason, in cassettes I keep a dict with lists as keys, but once deserialized into VCR, I keep them as plain, naked dicts. """
self._body = body.read() if not isinstance(self._body, binary_type): self._body = self._body.encode('utf-8') else:
def body(self): return BytesIO(self._body) if self._was_file else self._body
def body(self, value): self._body = value
# see class docstring for an explanation else:
def scheme(self): return urlparse(self.uri).scheme
def host(self): return urlparse(self.uri).hostname
def port(self): parse_uri = urlparse(self.uri) port = parse_uri.port if port is None: port = {'https': 443, 'http': 80}[parse_uri.scheme] return port
def path(self): return urlparse(self.uri).path
def query(self): q = urlparse(self.uri).query return sorted(parse_qsl(q))
# alias for backwards compatibility def url(self): return self.uri
# alias for backwards compatibility def protocol(self): return self.scheme
return self.__str__()
return { 'method': self.method, 'uri': self.uri, 'body': self.body, 'headers': dict(((k, [v]) for k, v in self.headers.items())), }
def _from_dict(cls, dct): |