1
0
mirror of https://github.com/kevin1024/vcrpy.git synced 2025-12-10 01:25:34 +00:00

Add Support for Requests Library

Added support and tests for the Requests library.  At least basic
support seems to be working.  The tests should run fine if you
don't have requests installed; it just won't verify the requests-
specific tests.
This commit is contained in:
Kevin McCarthy
2012-09-05 20:43:39 -10:00
parent e19d82aa03
commit 41da9ddbab
8 changed files with 173 additions and 79 deletions

View File

@@ -12,15 +12,28 @@ class VCRHTTPResponse(object):
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()
class VCRConnectionMixin:
def _load_old_response(self):