mirror of
https://github.com/python/cpython.git
synced 2025-09-26 18:29:57 +00:00
Add a wrapper function for ssl() on Windows. Inspired by SF patch
# 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.
This commit is contained in:
parent
bfb9184ba8
commit
3f69f21644
1 changed files with 11 additions and 6 deletions
|
@ -45,21 +45,26 @@ import os, sys
|
||||||
__all__ = ["getfqdn"]
|
__all__ = ["getfqdn"]
|
||||||
import _socket
|
import _socket
|
||||||
__all__.extend(os._get_exports_list(_socket))
|
__all__.extend(os._get_exports_list(_socket))
|
||||||
del _socket
|
|
||||||
|
|
||||||
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")):
|
||||||
|
|
||||||
# be sure this happens only once, even in the face of reload():
|
_realsocketcall = _socket.socket
|
||||||
try:
|
|
||||||
_realsocketcall
|
|
||||||
except NameError:
|
|
||||||
_realsocketcall = 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:
|
||||||
|
_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
|
# 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