From c5afde8d771833a8e9f4b3be85b817bc9c3dbfcb Mon Sep 17 00:00:00 2001 From: Allan Lewis Date: Wed, 27 Apr 2016 12:18:57 +0100 Subject: [PATCH] wsdump, websocket.*: [PEP 8] Use conventional vertical spacing --- bin/wsdump.py | 9 ++++++++- websocket/_abnf.py | 4 +++- websocket/_app.py | 1 + websocket/_exceptions.py | 2 ++ websocket/_handshake.py | 1 + websocket/_http.py | 9 +++++++-- websocket/_socket.py | 3 +++ websocket/_utils.py | 4 ++++ 8 files changed, 29 insertions(+), 4 deletions(-) diff --git a/bin/wsdump.py b/bin/wsdump.py index d85e4fc..0478070 100755 --- a/bin/wsdump.py +++ b/bin/wsdump.py @@ -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() diff --git a/websocket/_abnf.py b/websocket/_abnf.py index ed10470..6e7b85f 100644 --- a/websocket/_abnf.py +++ b/websocket/_abnf.py @@ -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 diff --git a/websocket/_app.py b/websocket/_app.py index 180a1fc..9954ee6 100644 --- a/websocket/_app.py +++ b/websocket/_app.py @@ -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, diff --git a/websocket/_exceptions.py b/websocket/_exceptions.py index 7b3e508..bf5c4ab 100644 --- a/websocket/_exceptions.py +++ b/websocket/_exceptions.py @@ -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 diff --git a/websocket/_handshake.py b/websocket/_handshake.py index cfc228d..cba48ec 100644 --- a/websocket/_handshake.py +++ b/websocket/_handshake.py @@ -48,6 +48,7 @@ VERSION = 13 class handshake_response(object): + def __init__(self, status, headers, subprotocol): self.status = status self.headers = headers diff --git a/websocket/_http.py b/websocket/_http.py index b99c264..c57a310 100644 --- a/websocket/_http.py +++ b/websocket/_http.py @@ -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 = {} diff --git a/websocket/_socket.py b/websocket/_socket.py index 63e001c..7055ae7 100644 --- a/websocket/_socket.py +++ b/websocket/_socket.py @@ -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. diff --git a/websocket/_utils.py b/websocket/_utils.py index a7dd65c..c8bcd22 100644 --- a/websocket/_utils.py +++ b/websocket/_utils.py @@ -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]