[Python-checkins] r56588 - in python/trunk: Lib/httplib.py Lib/socket.py Lib/test/test_socket_ssl.py Misc/NEWS

martin.v.loewis python-checkins at python.org
Fri Jul 27 20:28:22 CEST 2007


Author: martin.v.loewis
Date: Fri Jul 27 20:28:22 2007
New Revision: 56588

Modified:
   python/trunk/Lib/httplib.py
   python/trunk/Lib/socket.py
   python/trunk/Lib/test/test_socket_ssl.py
   python/trunk/Misc/NEWS
Log:
Bug #978833: Close https sockets by releasing the _ssl object.


Modified: python/trunk/Lib/httplib.py
==============================================================================
--- python/trunk/Lib/httplib.py	(original)
+++ python/trunk/Lib/httplib.py	Fri Jul 27 20:28:22 2007
@@ -1117,6 +1117,9 @@
     def __getattr__(self, attr):
         return getattr(self._sock, attr)
 
+    def close(self):
+        SharedSocketClient.close(self)
+        self._ssl = None
 
 class HTTPSConnection(HTTPConnection):
     "This class allows communication via SSL."

Modified: python/trunk/Lib/socket.py
==============================================================================
--- python/trunk/Lib/socket.py	(original)
+++ python/trunk/Lib/socket.py	Fri Jul 27 20:28:22 2007
@@ -144,6 +144,10 @@
     send = recv = recv_into = sendto = recvfrom = recvfrom_into = _dummy
     __getattr__ = _dummy
 
+# Wrapper around platform socket objects. This implements
+# a platform-independent dup() functionality. The
+# implementation currently relies on reference counting
+# to close the underlying socket object.
 class _socketobject(object):
 
     __doc__ = _realsocket.__doc__

Modified: python/trunk/Lib/test/test_socket_ssl.py
==============================================================================
--- python/trunk/Lib/test/test_socket_ssl.py	(original)
+++ python/trunk/Lib/test/test_socket_ssl.py	Fri Jul 27 20:28:22 2007
@@ -106,6 +106,25 @@
         connector()
         t.join()
 
+    def test_978833(self):
+        if test_support.verbose:
+            print "test_978833 ..."
+
+        import os, httplib
+        with test_support.transient_internet():
+            s = socket.socket(socket.AF_INET)
+            s.connect(("www.sf.net", 443))
+            fd = s._sock.fileno()
+            sock = httplib.FakeSocket(s, socket.ssl(s))
+            s = None
+            sock.close()
+            try:
+                os.fstat(fd)
+            except OSError:
+                pass
+            else:
+                raise test_support.TestFailed("Failed to close socket")
+
 class OpenSSLTests(unittest.TestCase):
 
     def testBasic(self):

Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS	(original)
+++ python/trunk/Misc/NEWS	Fri Jul 27 20:28:22 2007
@@ -238,6 +238,8 @@
 Library
 -------
 
+- Bug #978833: Close https sockets by releasing the _ssl object.
+
 - Change location of the package index to pypi.python.org/pypi
 
 - Bug #1701409: Fix a segfault in printing ctypes.c_char_p and


More information about the Python-checkins mailing list