From 0d77d2dcc6e65ca24b4a8cff6275a4de24d150b3 Mon Sep 17 00:00:00 2001 From: Kevin McCarthy Date: Sat, 8 Mar 2014 21:11:50 -1000 Subject: [PATCH] fix self.closed in python3, and request must inherit from httprequest for httplib2 --- vcr/stubs/__init__.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index 4345e77..82588ae 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -32,7 +32,7 @@ def parse_headers(header_list): headers = b"".join(header_list) + b"\r\n" return compat.get_httpmessage(headers) -class VCRHTTPResponse(object): +class VCRHTTPResponse(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.version = None self._content = BytesIO(self.recorded_response['body']['string']) - self.closed = False + self._closed = False headers = self.recorded_response['headers'] self.msg = parse_headers(headers) 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): return self._content.read(*args, **kwargs) @@ -56,7 +63,7 @@ class VCRHTTPResponse(object): return self._content.readline(*args, **kwargs) def close(self): - self.closed = True + self._closed = True return True def getcode(self): -- 2.43.0