wsdump, websocket.*: [PEP 8] Use conventional vertical spacing

This commit is contained in:
Allan Lewis
2016-04-27 12:18:57 +01:00
parent f1975aa380
commit c5afde8d77
8 changed files with 29 additions and 4 deletions

View File

@@ -27,6 +27,7 @@ ENCODING = get_encoding()
class VAction(argparse.Action): class VAction(argparse.Action):
def __call__(self, parser, args, values, option_string=None): def __call__(self, parser, args, values, option_string=None):
if values is None: if values is None:
values = "1" values = "1"
@@ -64,7 +65,9 @@ def parse_args():
return parser.parse_args() return parser.parse_args()
class RawInput: class RawInput:
def raw_input(self, prompt): def raw_input(self, prompt):
if six.PY3: if six.PY3:
line = input(prompt) line = input(prompt)
@@ -78,7 +81,9 @@ class RawInput:
return line return line
class InteractiveConsole(RawInput, code.InteractiveConsole): class InteractiveConsole(RawInput, code.InteractiveConsole):
def write(self, data): def write(self, data):
sys.stdout.write("\033[2K\033[E") sys.stdout.write("\033[2K\033[E")
# sys.stdout.write("\n") # sys.stdout.write("\n")
@@ -89,7 +94,9 @@ class InteractiveConsole(RawInput, code.InteractiveConsole):
def read(self): def read(self):
return self.raw_input("> ") return self.raw_input("> ")
class NonInteractive(RawInput): class NonInteractive(RawInput):
def write(self, data): def write(self, data):
sys.stdout.write(data) sys.stdout.write(data)
sys.stdout.write("\n") sys.stdout.write("\n")
@@ -98,6 +105,7 @@ class NonInteractive(RawInput):
def read(self): def read(self):
return self.raw_input("") return self.raw_input("")
def main(): def main():
start_time = time.time() start_time = time.time()
args = parse_args() args = parse_args()
@@ -140,7 +148,6 @@ def main():
return frame.opcode, frame.data return frame.opcode, frame.data
def recv_ws(): def recv_ws():
while True: while True:
opcode, data = recv() opcode, data = recv()

View File

@@ -70,6 +70,7 @@ VALID_CLOSE_STATUS = (
STATUS_UNEXPECTED_CONDITION, STATUS_UNEXPECTED_CONDITION,
) )
class ABNF(object): class ABNF(object):
""" """
ABNF frame class. ABNF frame class.
@@ -238,6 +239,7 @@ class ABNF(object):
_d = array.array("B", data) _d = array.array("B", data)
return _mask(_m, _d) return _mask(_m, _d)
class frame_buffer(object): class frame_buffer(object):
_HEADER_MASK_INDEX = 5 _HEADER_MASK_INDEX = 5
_HEADER_LENGTH_INDEX = 6 _HEADER_LENGTH_INDEX = 6
@@ -285,7 +287,6 @@ class frame_buffer(object):
return False return False
return self.header[frame_buffer._HEADER_MASK_INDEX] return self.header[frame_buffer._HEADER_MASK_INDEX]
def has_received_length(self): def has_received_length(self):
return self.length is None return self.length is None
@@ -359,6 +360,7 @@ class frame_buffer(object):
class continuous_frame(object): class continuous_frame(object):
def __init__(self, fire_cont_frame, skip_utf8_validation): def __init__(self, fire_cont_frame, skip_utf8_validation):
self.fire_cont_frame = fire_cont_frame self.fire_cont_frame = fire_cont_frame
self.skip_utf8_validation = skip_utf8_validation self.skip_utf8_validation = skip_utf8_validation

View File

@@ -43,6 +43,7 @@ class WebSocketApp(object):
Higher level of APIs are provided. Higher level of APIs are provided.
The interface is like JavaScript WebSocket object. The interface is like JavaScript WebSocket object.
""" """
def __init__(self, url, header=None, def __init__(self, url, header=None,
on_open=None, on_message=None, on_error=None, on_open=None, on_message=None, on_error=None,
on_close=None, on_ping=None, on_pong=None, on_close=None, on_ping=None, on_pong=None,

View File

@@ -25,6 +25,7 @@ Copyright (C) 2010 Hiroki Ohtani(liris)
define websocket exceptions define websocket exceptions
""" """
class WebSocketException(Exception): class WebSocketException(Exception):
""" """
websocket exception class. websocket exception class.
@@ -72,6 +73,7 @@ class WebSocketBadStatusException(WebSocketException):
""" """
WebSocketBadStatusException will be raised when we get bad handshake status code. WebSocketBadStatusException will be raised when we get bad handshake status code.
""" """
def __init__(self, message, status_code): def __init__(self, message, status_code):
super(WebSocketBadStatusException, self).__init__(message % status_code) super(WebSocketBadStatusException, self).__init__(message % status_code)
self.status_code = status_code self.status_code = status_code

View File

@@ -48,6 +48,7 @@ VERSION = 13
class handshake_response(object): class handshake_response(object):
def __init__(self, status, headers, subprotocol): def __init__(self, status, headers, subprotocol):
self.status = status self.status = status
self.headers = headers self.headers = headers

View File

@@ -39,7 +39,9 @@ from ._ssl_compat import *
__all__ = ["proxy_info", "connect", "read_headers"] __all__ = ["proxy_info", "connect", "read_headers"]
class proxy_info(object): class proxy_info(object):
def __init__(self, **options): def __init__(self, **options):
self.host = options.get("http_proxy_host", None) self.host = options.get("http_proxy_host", None)
if self.host: if self.host:
@@ -51,6 +53,7 @@ class proxy_info(object):
self.auth = None self.auth = None
self.no_proxy = None self.no_proxy = None
def connect(url, options, proxy, socket): def connect(url, options, proxy, socket):
hostname, port, resource, is_secure = parse_url(url) 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): def _ssl_socket(sock, user_sslopt, hostname):
sslopt = dict(cert_reqs=ssl.CERT_REQUIRED) sslopt = dict(cert_reqs=ssl.CERT_REQUIRED)
sslopt.update(user_sslopt) sslopt.update(user_sslopt)
certPath = os.path.join( certPath = os.path.join(
os.path.dirname(__file__), "cacert.pem") os.path.dirname(__file__), "cacert.pem")
if os.path.isfile(certPath) and user_sslopt.get('ca_certs', None) is None: 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 return sock
def _tunnel(sock, host, port, auth): def _tunnel(sock, host, port, auth):
debug("Connecting proxy...") debug("Connecting proxy...")
connect_header = "CONNECT %s:%d HTTP/1.0\r\n" % (host, port) 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: if status != 200:
raise WebSocketProxyException( raise WebSocketProxyException(
"failed CONNECT via proxy status: %r" % status) "failed CONNECT via proxy status: %r" % status)
return sock return sock
def read_headers(sock): def read_headers(sock):
status = None status = None
headers = {} headers = {}

View File

@@ -42,7 +42,9 @@ _default_timeout = None
__all__ = ["DEFAULT_SOCKET_OPTION", "sock_opt", "setdefaulttimeout", "getdefaulttimeout", __all__ = ["DEFAULT_SOCKET_OPTION", "sock_opt", "setdefaulttimeout", "getdefaulttimeout",
"recv", "recv_line", "send"] "recv", "recv_line", "send"]
class sock_opt(object): class sock_opt(object):
def __init__(self, sockopt, sslopt): def __init__(self, sockopt, sslopt):
if sockopt is None: if sockopt is None:
sockopt = [] sockopt = []
@@ -52,6 +54,7 @@ class sock_opt(object):
self.sslopt = sslopt self.sslopt = sslopt
self.timeout = None self.timeout = None
def setdefaulttimeout(timeout): def setdefaulttimeout(timeout):
""" """
Set the global timeout setting to connect. Set the global timeout setting to connect.

View File

@@ -24,7 +24,9 @@ import six
__all__ = ["NoLock", "validate_utf8", "extract_err_message"] __all__ = ["NoLock", "validate_utf8", "extract_err_message"]
class NoLock(object): class NoLock(object):
def __enter__(self): def __enter__(self):
pass pass
@@ -86,6 +88,7 @@ except ImportError:
return True return True
def validate_utf8(utfbytes): def validate_utf8(utfbytes):
""" """
validate utf8 byte string. validate utf8 byte string.
@@ -94,6 +97,7 @@ def validate_utf8(utfbytes):
""" """
return _validate_utf8(utfbytes) return _validate_utf8(utfbytes)
def extract_err_message(exception): def extract_err_message(exception):
if exception.args: if exception.args:
return exception.args[0] return exception.args[0]