mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Repair so that importing socket doesn't blow up on platforms that lack
SSL support. test_socket.py passes again on Windows. Added an XXX about adding _ssl exports to the __all__ list (it doesn't appear to be doing anything about that now, but since I don't have SSL on this box I can't really tell).
This commit is contained in:
parent
643a7fc62f
commit
18e6778bcd
1 changed files with 12 additions and 7 deletions
|
@ -38,37 +38,42 @@ Many other constants may be defined; these may be used in calls to
|
||||||
the setsockopt() and getsockopt() methods.
|
the setsockopt() and getsockopt() methods.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
import _socket
|
||||||
from _socket import *
|
from _socket import *
|
||||||
|
|
||||||
|
SSL_EXISTS = 1
|
||||||
try:
|
try:
|
||||||
|
import _ssl
|
||||||
from _ssl import *
|
from _ssl import *
|
||||||
except ImportError:
|
except ImportError:
|
||||||
pass
|
SSL_EXISTS = 0
|
||||||
|
|
||||||
import os, sys
|
import os, sys
|
||||||
|
|
||||||
__all__ = ["getfqdn"]
|
__all__ = ["getfqdn"]
|
||||||
import _socket
|
|
||||||
__all__.extend(os._get_exports_list(_socket))
|
__all__.extend(os._get_exports_list(_socket))
|
||||||
|
# XXX shouldn't there be something similar to the above for _ssl exports?
|
||||||
|
|
||||||
if (sys.platform.lower().startswith("win")
|
if (sys.platform.lower().startswith("win")
|
||||||
or (hasattr(os, 'uname') and os.uname()[0] == "BeOS")
|
or (hasattr(os, 'uname') and os.uname()[0] == "BeOS")
|
||||||
or (sys.platform=="riscos")):
|
or sys.platform=="riscos"):
|
||||||
|
|
||||||
_realsocketcall = _socket.socket
|
_realsocketcall = _socket.socket
|
||||||
|
|
||||||
def socket(family, type, proto=0):
|
def socket(family, type, proto=0):
|
||||||
return _socketobject(_realsocketcall(family, type, proto))
|
return _socketobject(_realsocketcall(family, type, proto))
|
||||||
|
|
||||||
try:
|
if SSL_EXISTS:
|
||||||
_realsslcall = _ssl.ssl
|
_realsslcall = _ssl.ssl
|
||||||
except AttributeError:
|
|
||||||
pass # No ssl
|
|
||||||
else:
|
|
||||||
def ssl(sock, keyfile=None, certfile=None):
|
def ssl(sock, keyfile=None, certfile=None):
|
||||||
if hasattr(sock, "_sock"):
|
if hasattr(sock, "_sock"):
|
||||||
sock = sock._sock
|
sock = sock._sock
|
||||||
return _realsslcall(sock, keyfile, certfile)
|
return _realsslcall(sock, keyfile, certfile)
|
||||||
|
|
||||||
|
del _socket
|
||||||
|
if SSL_EXISTS:
|
||||||
|
del _ssl
|
||||||
|
del SSL_EXISTS
|
||||||
|
|
||||||
# WSA error codes
|
# WSA error codes
|
||||||
if sys.platform.lower().startswith("win"):
|
if sys.platform.lower().startswith("win"):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue