summaryrefslogtreecommitdiffstats
path: root/Lib/socket.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/socket.py')
-rw-r--r--Lib/socket.py45
1 files changed, 32 insertions, 13 deletions
diff --git a/Lib/socket.py b/Lib/socket.py
index fb96637..0da08ae 100644
--- a/Lib/socket.py
+++ b/Lib/socket.py
@@ -46,13 +46,35 @@ the setsockopt() and getsockopt() methods.
import _socket
from _socket import *
-_have_ssl = False
-## try:
-## import _ssl
-## from _ssl import *
-## _have_ssl = True
-## except ImportError:
-## pass
+try:
+ import _ssl
+ import ssl as _realssl
+except ImportError:
+ # no SSL support
+ pass
+else:
+ def ssl(sock, keyfile=None, certfile=None):
+ # we do an internal import here because the ssl
+ # module imports the socket module
+ warnings.warn("socket.ssl() is deprecated. Use ssl.sslsocket() instead.",
+ DeprecationWarning, stacklevel=2)
+ return _realssl.sslwrap_simple(sock, keyfile, certfile)
+
+ # we need to import the same constants we used to...
+ from _ssl import \
+ sslerror, \
+ RAND_add, \
+ RAND_egd, \
+ RAND_status, \
+ SSL_ERROR_ZERO_RETURN, \
+ SSL_ERROR_WANT_READ, \
+ SSL_ERROR_WANT_WRITE, \
+ SSL_ERROR_WANT_X509_LOOKUP, \
+ SSL_ERROR_SYSCALL, \
+ SSL_ERROR_SSL, \
+ SSL_ERROR_WANT_CONNECT, \
+ SSL_ERROR_EOF, \
+ SSL_ERROR_INVALID_ERROR_CODE
import os, sys, io
@@ -63,12 +85,9 @@ except ImportError:
__all__ = ["getfqdn"]
__all__.extend(os._get_exports_list(_socket))
-if _have_ssl:
- __all__.extend(os._get_exports_list(_ssl))
- def ssl(sock, keyfile=None, certfile=None):
- import ssl as realssl
- return realssl.sslwrap_simple(sock, keyfile, certfile)
- __all__.append("ssl")
+
+
+_realsocket = socket
# WSA error codes
if sys.platform.lower().startswith("win"):