From ea13d516776d5360461dc7a7f41cc98f3b950b2e Mon Sep 17 00:00:00 2001 From: Marc Abramowitz Date: Tue, 26 Nov 2013 12:12:39 -0800 Subject: [PATCH] del self.sock in VCRConnectionMixin.request instead of in connection class constructors. Fixes GH-48. --- vcr/stubs/__init__.py | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/vcr/stubs/__init__.py b/vcr/stubs/__init__.py index eec9bc2..0553890 100644 --- a/vcr/stubs/__init__.py +++ b/vcr/stubs/__init__.py @@ -56,6 +56,10 @@ class VCRConnectionMixin: def request(self, method, url, body=None, headers=None): '''Persist the request metadata in self._vcr_request''' + # see VCRConnectionMixin._restore_socket for the motivation here + if hasattr(self, 'sock'): + del self.sock + self._vcr_request = Request( protocol=self._protocol, host=self.host, @@ -205,11 +209,6 @@ class VCRHTTPConnection(VCRConnectionMixin, HTTPConnection): _baseclass = HTTPConnection _protocol = 'http' - def __init__(self, *args, **kwargs): - HTTPConnection.__init__(self, *args, **kwargs) - # see VCRConnectionMixin._restore_socket for the motivation here - del self.sock - class VCRHTTPSConnection(VCRConnectionMixin, HTTPSConnection): '''A Mocked class for HTTPS requests''' @@ -223,5 +222,3 @@ class VCRHTTPSConnection(VCRConnectionMixin, HTTPSConnection): HTTPConnection.__init__(self, *args, **kwargs) self.key_file = kwargs.pop('key_file', None) self.cert_file = kwargs.pop('cert_file', None) - # see VCRConnectionMixin._restore_socket for the motivation here - del self.sock