From: Samuel Fekete Date: Mon, 3 Jul 2017 15:54:29 +0000 (+0100) Subject: Only have a sock attribute after connecting X-Git-Tag: v2.0.0~5^2~5 X-Git-Url: http://git.khamidou.com/?a=commitdiff_plain;h=eb4774a7d2252789f34801d9026e3d3cabd3be03;p=vcrpy.git Only have a sock attribute after connecting --- diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index 763204e..a23a731 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -171,6 +171,8 @@ class VCRConnection(object): # allows me to compare the entire length of the response to see if it # exists in the cassette. + self._sock = VCRFakeSocket() + def putrequest(self, method, url, *args, **kwargs): """ httplib gives you more than one way to do it. This is a way @@ -294,11 +296,13 @@ class VCRConnection(object): with force_reset(): return self.real_connection.connect(*args, **kwargs) + self._sock = VCRFakeSocket() + @property def sock(self): if self.real_connection.sock: return self.real_connection.sock - return VCRFakeSocket() + return self._sock @sock.setter def sock(self, value): @@ -316,6 +320,8 @@ class VCRConnection(object): with force_reset(): self.real_connection = self._baseclass(*args, **kwargs) + self._sock = None + def __setattr__(self, name, value): """ We need to define this because any attributes that are set on the