]> khamidou — GitHub mirrors - vcrpy.git/commitdiff
del self.sock in VCRConnectionMixin.request
authorMarc Abramowitz <marc@marc-abramowitz.com>
Tue, 26 Nov 2013 20:12:39 +0000 (12:12 -0800)
committerMarc Abramowitz <marc@marc-abramowitz.com>
Tue, 26 Nov 2013 20:12:39 +0000 (12:12 -0800)
instead of in connection class constructors.

Fixes GH-48.

vcr/stubs/__init__.py

index eec9bc24c60fa878fa8c9993523b05d55cb952cc..0553890935cbb932f51f5df84ddb9e519bab1079 100644 (file)
@@ -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