diff --git a/bin/wsdump.py b/bin/wsdump.py index 0478070..5af00ac 100755 --- a/bin/wsdump.py +++ b/bin/wsdump.py @@ -2,12 +2,15 @@ import argparse import code -import six import sys import threading import time -import websocket + +import six from six.moves.urllib.parse import urlparse + +import websocket + try: import readline except ImportError: diff --git a/compliance/test_fuzzingclient.py b/compliance/test_fuzzingclient.py index 58c5ea6..f4b0ff1 100644 --- a/compliance/test_fuzzingclient.py +++ b/compliance/test_fuzzingclient.py @@ -1,13 +1,9 @@ #!/usr/bin/env python -import websocket import json import traceback -import six - - - +import websocket SERVER = 'ws://127.0.0.1:8642' AGENT = 'py-websockets-client' diff --git a/websocket/__init__.py b/websocket/__init__.py index a895023..9b2cef5 100644 --- a/websocket/__init__.py +++ b/websocket/__init__.py @@ -19,7 +19,10 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ -from ._core import * from ._app import WebSocketApp +from ._core import * +from ._exceptions import * +from ._logging import * +from ._socket import * __version__ = "0.37.0" diff --git a/websocket/_abnf.py b/websocket/_abnf.py index 87503ce..fca07e6 100644 --- a/websocket/_abnf.py +++ b/websocket/_abnf.py @@ -19,10 +19,12 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ -import six import array -import struct import os +import struct + +import six + from ._exceptions import * from ._utils import validate_utf8 @@ -44,6 +46,22 @@ except ImportError: else: return _d.tostring() +__all__ = [ + 'ABNF', 'continuous_frame', 'frame_buffer', + 'STATUS_NORMAL', + 'STATUS_GOING_AWAY', + 'STATUS_PROTOCOL_ERROR', + 'STATUS_UNSUPPORTED_DATA_TYPE', + 'STATUS_STATUS_NOT_AVAILABLE', + 'STATUS_ABNORMAL_CLOSED', + 'STATUS_INVALID_PAYLOAD', + 'STATUS_POLICY_VIOLATION', + 'STATUS_MESSAGE_TOO_BIG', + 'STATUS_INVALID_EXTENSION', + 'STATUS_UNEXPECTED_CONDITION', + 'STATUS_TLS_HANDSHAKE_ERROR', +] + # closing frame status codes. STATUS_NORMAL = 1000 STATUS_GOING_AWAY = 1001 diff --git a/websocket/_app.py b/websocket/_app.py index 5096aef..3ea942d 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -23,17 +23,18 @@ Copyright (C) 2010 Hiroki Ohtani(liris) """ WebSocketApp provides higher level APIs. """ +import select +import sys import threading import time import traceback -import sys -import select + import six +from ._abnf import ABNF from ._core import WebSocket, getdefaulttimeout from ._exceptions import * from ._logging import * -from ._abnf import ABNF __all__ = ["WebSocketApp"] diff --git a/websocket/_core.py b/websocket/_core.py index e0be9f2..adcdb6b 100644 --- a/websocket/_core.py +++ b/websocket/_core.py @@ -21,24 +21,22 @@ Copyright (C) 2010 Hiroki Ohtani(liris) """ from __future__ import print_function +import socket +import struct +import threading import six -import socket - -if six.PY3: - from base64 import encodebytes as base64encode -else: - from base64 import encodestring as base64encode - -import threading # websocket modules from ._abnf import * +from ._exceptions import * +from ._handshake import * +from ._http import * +from ._logging import * from ._socket import * from ._utils import * -from ._logging import * -from ._http import * -from ._handshake import * + +__all__ = ['WebSocket', 'create_connection'] """ websocket python client. diff --git a/websocket/_handshake.py b/websocket/_handshake.py index cba48ec..73c9e7f 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -19,21 +19,21 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - -import six -if six.PY3: - from base64 import encodebytes as base64encode -else: - from base64 import encodestring as base64encode - import hashlib import hmac import os -from ._logging import * -from ._socket import* -from ._http import * +import six + from ._exceptions import * +from ._http import * +from ._logging import * +from ._socket import * + +if six.PY3: + from base64 import encodebytes as base64encode +else: + from base64 import encodestring as base64encode __all__ = ["handshake_response", "handshake"] diff --git a/websocket/_http.py b/websocket/_http.py index 4f9c3e3..88f313a 100644 --- a/websocket/_http.py +++ b/websocket/_http.py @@ -19,24 +19,24 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - -import six -import socket import errno import os +import socket import sys +import six + +from ._exceptions import * +from ._logging import * +from ._socket import* +from ._ssl_compat import * +from ._url import * + if six.PY3: from base64 import encodebytes as base64encode else: from base64 import encodestring as base64encode -from ._logging import * -from ._url import * -from ._socket import* -from ._exceptions import * -from ._ssl_compat import * - __all__ = ["proxy_info", "connect", "read_headers"] diff --git a/websocket/_logging.py b/websocket/_logging.py index 321e24a..d440bf7 100644 --- a/websocket/_logging.py +++ b/websocket/_logging.py @@ -19,7 +19,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - import logging _logger = logging.getLogger('websocket') diff --git a/websocket/_socket.py b/websocket/_socket.py index f2bc4f1..e2e1dd2 100644 --- a/websocket/_socket.py +++ b/websocket/_socket.py @@ -19,13 +19,13 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - import socket + import six from ._exceptions import * -from ._utils import * from ._ssl_compat import * +from ._utils import * DEFAULT_SOCKET_OPTION = [(socket.SOL_TCP, socket.TCP_NODELAY, 1)] if hasattr(socket, "SO_KEEPALIVE"): diff --git a/websocket/_ssl_compat.py b/websocket/_ssl_compat.py index d41ca79..0304816 100644 --- a/websocket/_ssl_compat.py +++ b/websocket/_ssl_compat.py @@ -19,7 +19,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - __all__ = ["HAVE_SSL", "ssl", "SSLError"] try: diff --git a/websocket/_url.py b/websocket/_url.py index 7299e5c..11216b6 100644 --- a/websocket/_url.py +++ b/websocket/_url.py @@ -19,9 +19,9 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ +import os from six.moves.urllib.parse import urlparse -import os __all__ = ["parse_url", "get_proxy_info"] diff --git a/websocket/_utils.py b/websocket/_utils.py index 0c939f8..399fb89 100644 --- a/websocket/_utils.py +++ b/websocket/_utils.py @@ -19,7 +19,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris) Boston, MA 02110-1335 USA """ - import six __all__ = ["NoLock", "validate_utf8", "extract_err_message"] diff --git a/websocket/tests/test_websocket.py b/websocket/tests/test_websocket.py index 20de24c..d2170ae 100644 --- a/websocket/tests/test_websocket.py +++ b/websocket/tests/test_websocket.py @@ -1,40 +1,39 @@ # -*- coding: utf-8 -*- # -import six import sys sys.path[0:0] = [""] import os import os.path import socket -try: - from ssl import SSLError -except ImportError: - # dummy class of SSLError for ssl none-support environment. - class SSLError(Exception): - pass -if sys.version_info[0] == 2 and sys.version_info[1] < 7: - import unittest2 as unittest -else: - import unittest +import six +# websocket-client +import websocket as ws +from websocket._handshake import _create_sec_websocket_key, \ + _validate as _validate_header +from websocket._http import read_headers +from websocket._url import get_proxy_info, parse_url +from websocket._utils import validate_utf8 if six.PY3: from base64 import decodebytes as base64decode else: from base64 import decodestring as base64decode +if sys.version_info[0] == 2 and sys.version_info[1] < 7: + import unittest2 as unittest +else: + import unittest -# websocket-client -import websocket as ws -from websocket._handshake import _create_sec_websocket_key -from websocket._url import parse_url, get_proxy_info -from websocket._utils import validate_utf8 -from websocket._handshake import _validate as _validate_header -from websocket._http import read_headers - +try: + from ssl import SSLError +except ImportError: + # dummy class of SSLError for ssl none-support environment. + class SSLError(Exception): + pass # Skip test to access the internet. TEST_WITH_INTERNET = os.environ.get('TEST_WITH_INTERNET', '0') == '1'