mirror of
https://github.com/kevin1024/vcrpy.git
synced 2025-12-09 01:03:24 +00:00
fix self.closed in python3, and request must inherit from httprequest for httplib2
This commit is contained in:
@@ -32,7 +32,7 @@ def parse_headers(header_list):
|
|||||||
headers = b"".join(header_list) + b"\r\n"
|
headers = b"".join(header_list) + b"\r\n"
|
||||||
return compat.get_httpmessage(headers)
|
return compat.get_httpmessage(headers)
|
||||||
|
|
||||||
class VCRHTTPResponse(object):
|
class VCRHTTPResponse(HTTPResponse):
|
||||||
"""
|
"""
|
||||||
Stub reponse class that gets returned instead of a HTTPResponse
|
Stub reponse class that gets returned instead of a HTTPResponse
|
||||||
"""
|
"""
|
||||||
@@ -42,13 +42,20 @@ class VCRHTTPResponse(object):
|
|||||||
self.status = self.code = recorded_response['status']['code']
|
self.status = self.code = recorded_response['status']['code']
|
||||||
self.version = None
|
self.version = None
|
||||||
self._content = BytesIO(self.recorded_response['body']['string'])
|
self._content = BytesIO(self.recorded_response['body']['string'])
|
||||||
self.closed = False
|
self._closed = False
|
||||||
|
|
||||||
headers = self.recorded_response['headers']
|
headers = self.recorded_response['headers']
|
||||||
self.msg = parse_headers(headers)
|
self.msg = parse_headers(headers)
|
||||||
|
|
||||||
self.length = compat.get_header(self.msg, 'content-length') or None
|
self.length = compat.get_header(self.msg, 'content-length') or None
|
||||||
|
|
||||||
|
@property
|
||||||
|
def closed(self):
|
||||||
|
# in python3, I can't change the value of self.closed. So I'm twiddling
|
||||||
|
# self._closed and using this property to shadow the real self.closed
|
||||||
|
# from the superclass
|
||||||
|
return self._closed
|
||||||
|
|
||||||
def read(self, *args, **kwargs):
|
def read(self, *args, **kwargs):
|
||||||
return self._content.read(*args, **kwargs)
|
return self._content.read(*args, **kwargs)
|
||||||
|
|
||||||
@@ -56,7 +63,7 @@ class VCRHTTPResponse(object):
|
|||||||
return self._content.readline(*args, **kwargs)
|
return self._content.readline(*args, **kwargs)
|
||||||
|
|
||||||
def close(self):
|
def close(self):
|
||||||
self.closed = True
|
self._closed = True
|
||||||
return True
|
return True
|
||||||
|
|
||||||
def getcode(self):
|
def getcode(self):
|
||||||
|
|||||||
Reference in New Issue
Block a user