]> granicus.if.org Git - python/commitdiff
Bug #978833: Really close underlying socket in _socketobject.close.
authorMartin v. Löwis <martin@v.loewis.de>
Wed, 26 Jul 2006 12:12:56 +0000 (12:12 +0000)
committerMartin v. Löwis <martin@v.loewis.de>
Wed, 26 Jul 2006 12:12:56 +0000 (12:12 +0000)
Fix httplib.HTTPConnection.getresponse to not close the
socket if it is still needed for the response.

Lib/httplib.py
Lib/socket.py
Misc/NEWS

index 36381de4693b65e22116ce785ea14c40ae6b711f..95456ea668355f667e0f959760a3c1ef1320fef7 100644 (file)
@@ -926,8 +926,8 @@ class HTTPConnection:
         self.__state = _CS_IDLE
 
         if response.will_close:
-            # this effectively passes the connection to the response
-            self.close()
+            # Pass the socket to the response
+            self.sock = None
         else:
             # remember this, so we can tell when it is complete
             self.__response = response
index 4e83f099a281aabb21f4dd819d6078bc1997a91d..52fb8e33cb6195afd4c906b9351b8214c130ebc6 100644 (file)
@@ -139,6 +139,8 @@ class _closedsocket(object):
     __slots__ = []
     def _dummy(*args):
         raise error(EBADF, 'Bad file descriptor')
+    def close(self):
+        pass
     # All _delegate_methods must also be initialized here.
     send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy
     __getattr__ = _dummy
@@ -157,6 +159,7 @@ class _socketobject(object):
             setattr(self, method, getattr(_sock, method))
 
     def close(self):
+        self._sock.close()
         self._sock = _closedsocket()
         dummy = self._sock._dummy
         for method in _delegate_methods:
index 15e74f306e473b589bfa71b2d89d16df4fabbbdf..4644c8269753d5c02c7e39a57a11e0aef7103b73 100644 (file)
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -42,6 +42,8 @@ Core and builtins
 Library
 -------
 
+- Bug #978833: Really close underlying socket in _socketobject.close.
+
 - Bug #1459963: urllib and urllib2 now normalize HTTP header names correctly
   with title().