wsdump, test_fuzzingclient, websocket.*, test_websocket: Organise imports
Previously, because of the multiple instances of `from foo import *`, names were imported from modules that had themselves imported them, instead of from the place of definition. This commit therefore does the following: - Declares `__all__` in every module that imports anything, so that `from foo import *` is sane. - Sorts the imports based on conventions, similar to the output of `isort`. - Places all conditional imports after unconditional imports, except where that isn't valid. - Imports local names from the modules where they are defined, except when importing the package itself.
This commit is contained in:
		@@ -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:
 | 
			
		||||
 
 | 
			
		||||
@@ -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'
 | 
			
		||||
 
 | 
			
		||||
@@ -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"
 | 
			
		||||
 
 | 
			
		||||
@@ -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
 | 
			
		||||
 
 | 
			
		||||
@@ -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"]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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.
 | 
			
		||||
 
 | 
			
		||||
@@ -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"]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -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"]
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
 | 
			
		||||
    Boston, MA  02110-1335  USA
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import logging
 | 
			
		||||
 | 
			
		||||
_logger = logging.getLogger('websocket')
 | 
			
		||||
 
 | 
			
		||||
@@ -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"):
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
 | 
			
		||||
    Boston, MA 02110-1335  USA
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
__all__ = ["HAVE_SSL", "ssl", "SSLError"]
 | 
			
		||||
 | 
			
		||||
try:
 | 
			
		||||
 
 | 
			
		||||
@@ -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"]
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -19,7 +19,6 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
 | 
			
		||||
    Boston, MA 02110-1335  USA
 | 
			
		||||
 | 
			
		||||
"""
 | 
			
		||||
 | 
			
		||||
import six
 | 
			
		||||
 | 
			
		||||
__all__ = ["NoLock", "validate_utf8", "extract_err_message"]
 | 
			
		||||
 
 | 
			
		||||
@@ -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'
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user