wsdump, websocket.*: [PEP 8] Use conventional vertical spacing
This commit is contained in:
parent
f1975aa380
commit
c5afde8d77
|
@ -27,6 +27,7 @@ ENCODING = get_encoding()
|
|||
|
||||
|
||||
class VAction(argparse.Action):
|
||||
|
||||
def __call__(self, parser, args, values, option_string=None):
|
||||
if values is None:
|
||||
values = "1"
|
||||
|
@ -64,7 +65,9 @@ def parse_args():
|
|||
|
||||
return parser.parse_args()
|
||||
|
||||
|
||||
class RawInput:
|
||||
|
||||
def raw_input(self, prompt):
|
||||
if six.PY3:
|
||||
line = input(prompt)
|
||||
|
@ -78,7 +81,9 @@ class RawInput:
|
|||
|
||||
return line
|
||||
|
||||
|
||||
class InteractiveConsole(RawInput, code.InteractiveConsole):
|
||||
|
||||
def write(self, data):
|
||||
sys.stdout.write("\033[2K\033[E")
|
||||
# sys.stdout.write("\n")
|
||||
|
@ -89,7 +94,9 @@ class InteractiveConsole(RawInput, code.InteractiveConsole):
|
|||
def read(self):
|
||||
return self.raw_input("> ")
|
||||
|
||||
|
||||
class NonInteractive(RawInput):
|
||||
|
||||
def write(self, data):
|
||||
sys.stdout.write(data)
|
||||
sys.stdout.write("\n")
|
||||
|
@ -98,6 +105,7 @@ class NonInteractive(RawInput):
|
|||
def read(self):
|
||||
return self.raw_input("")
|
||||
|
||||
|
||||
def main():
|
||||
start_time = time.time()
|
||||
args = parse_args()
|
||||
|
@ -140,7 +148,6 @@ def main():
|
|||
|
||||
return frame.opcode, frame.data
|
||||
|
||||
|
||||
def recv_ws():
|
||||
while True:
|
||||
opcode, data = recv()
|
||||
|
|
|
@ -70,6 +70,7 @@ VALID_CLOSE_STATUS = (
|
|||
STATUS_UNEXPECTED_CONDITION,
|
||||
)
|
||||
|
||||
|
||||
class ABNF(object):
|
||||
"""
|
||||
ABNF frame class.
|
||||
|
@ -238,6 +239,7 @@ class ABNF(object):
|
|||
_d = array.array("B", data)
|
||||
return _mask(_m, _d)
|
||||
|
||||
|
||||
class frame_buffer(object):
|
||||
_HEADER_MASK_INDEX = 5
|
||||
_HEADER_LENGTH_INDEX = 6
|
||||
|
@ -285,7 +287,6 @@ class frame_buffer(object):
|
|||
return False
|
||||
return self.header[frame_buffer._HEADER_MASK_INDEX]
|
||||
|
||||
|
||||
def has_received_length(self):
|
||||
return self.length is None
|
||||
|
||||
|
@ -359,6 +360,7 @@ class frame_buffer(object):
|
|||
|
||||
|
||||
class continuous_frame(object):
|
||||
|
||||
def __init__(self, fire_cont_frame, skip_utf8_validation):
|
||||
self.fire_cont_frame = fire_cont_frame
|
||||
self.skip_utf8_validation = skip_utf8_validation
|
||||
|
|
|
@ -43,6 +43,7 @@ class WebSocketApp(object):
|
|||
Higher level of APIs are provided.
|
||||
The interface is like JavaScript WebSocket object.
|
||||
"""
|
||||
|
||||
def __init__(self, url, header=None,
|
||||
on_open=None, on_message=None, on_error=None,
|
||||
on_close=None, on_ping=None, on_pong=None,
|
||||
|
|
|
@ -25,6 +25,7 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
|
|||
define websocket exceptions
|
||||
"""
|
||||
|
||||
|
||||
class WebSocketException(Exception):
|
||||
"""
|
||||
websocket exception class.
|
||||
|
@ -72,6 +73,7 @@ class WebSocketBadStatusException(WebSocketException):
|
|||
"""
|
||||
WebSocketBadStatusException will be raised when we get bad handshake status code.
|
||||
"""
|
||||
|
||||
def __init__(self, message, status_code):
|
||||
super(WebSocketBadStatusException, self).__init__(message % status_code)
|
||||
self.status_code = status_code
|
||||
|
|
|
@ -48,6 +48,7 @@ VERSION = 13
|
|||
|
||||
|
||||
class handshake_response(object):
|
||||
|
||||
def __init__(self, status, headers, subprotocol):
|
||||
self.status = status
|
||||
self.headers = headers
|
||||
|
|
|
@ -39,7 +39,9 @@ from ._ssl_compat import *
|
|||
|
||||
__all__ = ["proxy_info", "connect", "read_headers"]
|
||||
|
||||
|
||||
class proxy_info(object):
|
||||
|
||||
def __init__(self, **options):
|
||||
self.host = options.get("http_proxy_host", None)
|
||||
if self.host:
|
||||
|
@ -51,6 +53,7 @@ class proxy_info(object):
|
|||
self.auth = None
|
||||
self.no_proxy = None
|
||||
|
||||
|
||||
def connect(url, options, proxy, socket):
|
||||
hostname, port, resource, is_secure = parse_url(url)
|
||||
|
||||
|
@ -158,7 +161,7 @@ def _wrap_sni_socket(sock, sslopt, hostname, check_hostname):
|
|||
def _ssl_socket(sock, user_sslopt, hostname):
|
||||
sslopt = dict(cert_reqs=ssl.CERT_REQUIRED)
|
||||
sslopt.update(user_sslopt)
|
||||
|
||||
|
||||
certPath = os.path.join(
|
||||
os.path.dirname(__file__), "cacert.pem")
|
||||
if os.path.isfile(certPath) and user_sslopt.get('ca_certs', None) is None:
|
||||
|
@ -176,6 +179,7 @@ def _ssl_socket(sock, user_sslopt, hostname):
|
|||
|
||||
return sock
|
||||
|
||||
|
||||
def _tunnel(sock, host, port, auth):
|
||||
debug("Connecting proxy...")
|
||||
connect_header = "CONNECT %s:%d HTTP/1.0\r\n" % (host, port)
|
||||
|
@ -199,9 +203,10 @@ def _tunnel(sock, host, port, auth):
|
|||
if status != 200:
|
||||
raise WebSocketProxyException(
|
||||
"failed CONNECT via proxy status: %r" % status)
|
||||
|
||||
|
||||
return sock
|
||||
|
||||
|
||||
def read_headers(sock):
|
||||
status = None
|
||||
headers = {}
|
||||
|
|
|
@ -42,7 +42,9 @@ _default_timeout = None
|
|||
__all__ = ["DEFAULT_SOCKET_OPTION", "sock_opt", "setdefaulttimeout", "getdefaulttimeout",
|
||||
"recv", "recv_line", "send"]
|
||||
|
||||
|
||||
class sock_opt(object):
|
||||
|
||||
def __init__(self, sockopt, sslopt):
|
||||
if sockopt is None:
|
||||
sockopt = []
|
||||
|
@ -52,6 +54,7 @@ class sock_opt(object):
|
|||
self.sslopt = sslopt
|
||||
self.timeout = None
|
||||
|
||||
|
||||
def setdefaulttimeout(timeout):
|
||||
"""
|
||||
Set the global timeout setting to connect.
|
||||
|
|
|
@ -24,7 +24,9 @@ import six
|
|||
|
||||
__all__ = ["NoLock", "validate_utf8", "extract_err_message"]
|
||||
|
||||
|
||||
class NoLock(object):
|
||||
|
||||
def __enter__(self):
|
||||
pass
|
||||
|
||||
|
@ -86,6 +88,7 @@ except ImportError:
|
|||
|
||||
return True
|
||||
|
||||
|
||||
def validate_utf8(utfbytes):
|
||||
"""
|
||||
validate utf8 byte string.
|
||||
|
@ -94,6 +97,7 @@ def validate_utf8(utfbytes):
|
|||
"""
|
||||
return _validate_utf8(utfbytes)
|
||||
|
||||
|
||||
def extract_err_message(exception):
|
||||
if exception.args:
|
||||
return exception.args[0]
|
||||
|
|
Loading…
Reference in New Issue