[Python-checkins] r66682 - in python/trunk/Lib: ssl.py test/test_ssl.py

bill.janssen python-checkins at python.org
Mon Sep 29 20:56:38 CEST 2008


Author: bill.janssen
Date: Mon Sep 29 20:56:38 2008
New Revision: 66682

Log:
fix for release blocker 3910, 2.6 regression in socket.ssl method

Modified:
   python/trunk/Lib/ssl.py
   python/trunk/Lib/test/test_ssl.py

Modified: python/trunk/Lib/ssl.py
==============================================================================
--- python/trunk/Lib/ssl.py	(original)
+++ python/trunk/Lib/ssl.py	Mon Sep 29 20:56:38 2008
@@ -434,7 +434,18 @@
     for compability with Python 2.5 and earlier.  Will disappear in
     Python 3.0."""
 
-    ssl_sock = _ssl.sslwrap(sock._sock, 0, keyfile, certfile, CERT_NONE,
+    if hasattr(sock, "_sock"):
+        sock = sock._sock
+
+    ssl_sock = _ssl.sslwrap(sock, 0, keyfile, certfile, CERT_NONE,
                             PROTOCOL_SSLv23, None)
-    ssl_sock.do_handshake()
+    try:
+        sock.getpeername()
+    except:
+        # no, no connection yet
+        pass
+    else:
+        # yes, do the handshake
+        ssl_sock.do_handshake()
+
     return ssl_sock

Modified: python/trunk/Lib/test/test_ssl.py
==============================================================================
--- python/trunk/Lib/test/test_ssl.py	(original)
+++ python/trunk/Lib/test/test_ssl.py	Mon Sep 29 20:56:38 2008
@@ -34,6 +34,21 @@
     if test_support.verbose:
         sys.stdout.write(prefix + exc_format)
 
+    def testSimpleSSLwrap(self):
+        try:
+            ssl.sslwrap_simple(socket.socket(socket.AF_INET))
+        except IOError, e:
+            if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
+                pass
+            else:
+                raise
+        try:
+            ssl.sslwrap_simple(socket.socket(socket.AF_INET)._sock)
+        except IOError, e:
+            if e.errno == 32: # broken pipe when ssl_sock.do_handshake(), this test doesn't care about that
+                pass
+            else:
+                raise
 
 class BasicTests(unittest.TestCase):
 
@@ -58,7 +73,6 @@
         finally:
             s.close()
 
-
     def testCrucialConstants(self):
         ssl.PROTOCOL_SSLv2
         ssl.PROTOCOL_SSLv23


More information about the Python-checkins mailing list