wsdump, _core, _url, _utils: Remove redundant parentheses

This commit is contained in:
Allan Lewis
2016-04-27 11:25:59 +01:00
parent f0f3cc129b
commit 669096e874
4 changed files with 14 additions and 14 deletions

View File

@@ -63,7 +63,7 @@ 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)
@@ -103,16 +103,16 @@ def main():
if args.verbose > 1: if args.verbose > 1:
websocket.enableTrace(True) websocket.enableTrace(True)
options = {} options = {}
if (args.proxy): if args.proxy:
p = urlparse(args.proxy) p = urlparse(args.proxy)
options["http_proxy_host"] = p.hostname options["http_proxy_host"] = p.hostname
options["http_proxy_port"] = p.port options["http_proxy_port"] = p.port
if (args.origin): if args.origin:
options["origin"] = args.origin options["origin"] = args.origin
if (args.subprotocols): if args.subprotocols:
options["subprotocols"] = args.subprotocols options["subprotocols"] = args.subprotocols
opts = {} opts = {}
if (args.nocert): if args.nocert:
opts = { "cert_reqs": websocket.ssl.CERT_NONE, "check_hostname": False } opts = { "cert_reqs": websocket.ssl.CERT_NONE, "check_hostname": False }
ws = websocket.create_connection(args.url, sslopt=opts, **options) ws = websocket.create_connection(args.url, sslopt=opts, **options)
if args.raw: if args.raw:
@@ -125,14 +125,14 @@ def main():
try: try:
frame = ws.recv_frame() frame = ws.recv_frame()
except websocket.WebSocketException: except websocket.WebSocketException:
return (websocket.ABNF.OPCODE_CLOSE, None) return websocket.ABNF.OPCODE_CLOSE, None
if not frame: if not frame:
raise websocket.WebSocketException("Not a valid frame %s" % frame) raise websocket.WebSocketException("Not a valid frame %s" % frame)
elif frame.opcode in OPCODE_DATA: elif frame.opcode in OPCODE_DATA:
return (frame.opcode, frame.data) return frame.opcode, frame.data
elif frame.opcode == websocket.ABNF.OPCODE_CLOSE: elif frame.opcode == websocket.ABNF.OPCODE_CLOSE:
ws.send_close() ws.send_close()
return (frame.opcode, None) return frame.opcode, None
elif frame.opcode == websocket.ABNF.OPCODE_PING: elif frame.opcode == websocket.ABNF.OPCODE_PING:
ws.pong(frame.data) ws.pong(frame.data)
return frame.opcode, frame.data return frame.opcode, frame.data
@@ -152,7 +152,7 @@ def main():
msg = "%s: %s" % (websocket.ABNF.OPCODE_MAP.get(opcode), data) msg = "%s: %s" % (websocket.ABNF.OPCODE_MAP.get(opcode), data)
if msg is not None: if msg is not None:
if (args.timings): if args.timings:
console.write(str(time.time() - start_time) + ": " + msg) console.write(str(time.time() - start_time) + ": " + msg)
else: else:
console.write(msg) console.write(msg)

View File

@@ -339,17 +339,17 @@ class WebSocket(object):
elif frame.opcode == ABNF.OPCODE_CLOSE: elif frame.opcode == ABNF.OPCODE_CLOSE:
self.send_close() self.send_close()
return (frame.opcode, frame) return frame.opcode, frame
elif frame.opcode == ABNF.OPCODE_PING: elif frame.opcode == ABNF.OPCODE_PING:
if len(frame.data) < 126: if len(frame.data) < 126:
self.pong(frame.data) self.pong(frame.data)
else: else:
raise WebSocketProtocolException("Ping message is too long") raise WebSocketProtocolException("Ping message is too long")
if control_frame: if control_frame:
return (frame.opcode, frame) return frame.opcode, frame
elif frame.opcode == ABNF.OPCODE_PONG: elif frame.opcode == ABNF.OPCODE_PONG:
if control_frame: if control_frame:
return (frame.opcode, frame) return frame.opcode, frame
def recv_frame(self): def recv_frame(self):
""" """

View File

@@ -66,7 +66,7 @@ def parse_url(url):
if parsed.query: if parsed.query:
resource += "?" + parsed.query resource += "?" + parsed.query
return (hostname, port, resource, is_secure) return hostname, port, resource, is_secure
DEFAULT_NO_PROXY_HOST = ["localhost", "127.0.0.1"] DEFAULT_NO_PROXY_HOST = ["localhost", "127.0.0.1"]

View File

@@ -69,7 +69,7 @@ except ImportError:
def _decode(state, codep, ch): def _decode(state, codep, ch):
tp = _UTF8D[ch] tp = _UTF8D[ch]
codep = (ch & 0x3f ) | (codep << 6) if (state != _UTF8_ACCEPT) else (0xff >> tp) & (ch) codep = (ch & 0x3f ) | (codep << 6) if (state != _UTF8_ACCEPT) else (0xff >> tp) & ch
state = _UTF8D[256 + state + tp] state = _UTF8D[256 + state + tp]
return state, codep; return state, codep;