diff options
| author | engn33r <engn33r@users.noreply.github.com> | 2021-05-15 12:10:58 -0400 |
|---|---|---|
| committer | engn33r <engn33r@users.noreply.github.com> | 2021-05-15 12:10:58 -0400 |
| commit | ff67af8ef287ea6281fd8f76dcd234d19db06fc7 (patch) | |
| tree | 18c4625ce1818090c9a0625be2b290cf609464ab | |
| parent | ab1ebf788087f611058d83423d18ac056bbf73c4 (diff) | |
| download | websocket-client-ff67af8ef287ea6281fd8f76dcd234d19db06fc7.tar.gz | |
Remove unnecessary Python2 code
| -rw-r--r-- | websocket/_app.py | 1 | ||||
| -rw-r--r-- | websocket/_handshake.py | 8 | ||||
| -rw-r--r-- | websocket/_http.py | 11 | ||||
| -rw-r--r-- | websocket/_ssl_compat.py | 13 |
4 files changed, 5 insertions, 28 deletions
diff --git a/websocket/_app.py b/websocket/_app.py index aa330a6..7dbacb3 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -22,7 +22,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA """ -import inspect import selectors import sys import threading diff --git a/websocket/_handshake.py b/websocket/_handshake.py index b3002aa..74ccbaf 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -31,12 +31,6 @@ from ._socket import * __all__ = ["handshake_response", "handshake", "SUPPORTED_REDIRECT_STATUSES"] -if hasattr(hmac, "compare_digest"): - compare_digest = hmac.compare_digest -else: - def compare_digest(s1, s2): - return s1 == s2 - # websocket supported version. VERSION = 13 @@ -185,7 +179,7 @@ def _validate(headers, key, subprotocols): value = (key + "258EAFA5-E914-47DA-95CA-C5AB0DC85B11").encode('utf-8') hashed = base64encode(hashlib.sha1(value).digest()).strip().lower() - success = compare_digest(hashed, result) + success = hmac.compare_digest(hashed, result) if success: return True, subproto diff --git a/websocket/_http.py b/websocket/_http.py index c1d04ce..f046805 100644 --- a/websocket/_http.py +++ b/websocket/_http.py @@ -199,10 +199,6 @@ def _open_socket(addrinfo_list, sockopt, timeout): return sock -def _can_use_sni(): - return sys.version_info >= (3, 6) - - def _wrap_sni_socket(sock, sslopt, hostname, check_hostname): context = ssl.SSLContext(sslopt.get('ssl_version', ssl.PROTOCOL_SSLv23)) @@ -255,12 +251,7 @@ def _ssl_socket(sock, user_sslopt, hostname): check_hostname = sslopt["cert_reqs"] != ssl.CERT_NONE and sslopt.pop( 'check_hostname', True) - - if _can_use_sni(): - sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname) - else: - sslopt.pop('check_hostname', True) - sock = ssl.wrap_socket(sock, **sslopt) + sock = _wrap_sni_socket(sock, sslopt, hostname, check_hostname) if not HAVE_CONTEXT_CHECK_HOSTNAME and check_hostname: match_hostname(sock.getpeercert(), hostname) diff --git a/websocket/_ssl_compat.py b/websocket/_ssl_compat.py index 9e201dd..e0fc349 100644 --- a/websocket/_ssl_compat.py +++ b/websocket/_ssl_compat.py @@ -25,20 +25,14 @@ try: from ssl import SSLError from ssl import SSLWantReadError from ssl import SSLWantWriteError + HAVE_CONTEXT_CHECK_HOSTNAME = False if hasattr(ssl, 'SSLContext') and hasattr(ssl.SSLContext, 'check_hostname'): HAVE_CONTEXT_CHECK_HOSTNAME = True - else: - HAVE_CONTEXT_CHECK_HOSTNAME = False - if hasattr(ssl, "match_hostname"): - from ssl import match_hostname - else: - from backports.ssl_match_hostname import match_hostname - __all__.append("match_hostname") - __all__.append("HAVE_CONTEXT_CHECK_HOSTNAME") + __all__.append("HAVE_CONTEXT_CHECK_HOSTNAME") HAVE_SSL = True except ImportError: - # dummy class of SSLError for ssl none-support environment. + # dummy class of SSLError for environment without ssl support class SSLError(Exception): pass @@ -49,5 +43,4 @@ except ImportError: pass ssl = None - HAVE_SSL = False |
