Add a wrapper function for ssl() on Windows. Inspired by SF patch
authorGuido van Rossum <guido@python.org>
Thu, 22 Mar 2001 22:12:17 +0000 (22:12 +0000)
committerGuido van Rossum <guido@python.org>
Thu, 22 Mar 2001 22:12:17 +0000 (22:12 +0000)
# 409287, ssl fix when using _socketobject, by Robin Dunn.

I took the opportunity to improve the way it deals with reload(socket)
for the socket function as well.

Lib/socket.py

index a49e7cbcd1f661b805bb552165bca3ce7f5948ba..7cd788944687d6642523442cda28bc1c69ee4e8a 100644 (file)
@@ -45,21 +45,26 @@ import os, sys
 __all__ = ["getfqdn"]
 import _socket
 __all__.extend(os._get_exports_list(_socket))
-del _socket
 
 if (sys.platform.lower().startswith("win")
     or (hasattr(os, 'uname') and os.uname()[0] == "BeOS")
     or (sys.platform=="RISCOS")):
 
-    # be sure this happens only once, even in the face of reload():
-    try:
-        _realsocketcall
-    except NameError:
-        _realsocketcall = socket
+    _realsocketcall = _socket.socket
 
     def socket(family, type, proto=0):
         return _socketobject(_realsocketcall(family, type, proto))
 
+    try:
+        _realsslcall = _socket.ssl
+    except AttributeError:
+        pass # No ssl
+    else:
+        def ssl(sock, keyfile=None, certfile=None):
+            if hasattr(sock, "_sock"):
+                sock = sock._sock
+            return _realsslcall(sock, keyfile, certfile)    
+
 
 # WSA error codes
 if sys.platform.lower().startswith("win"):