summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorமனோஜ்குமார் பழனிச்சாமி <smartmanoj42857@gmail.com>2022-05-09 01:25:22 +0530
committerGitHub <noreply@github.com>2022-05-08 19:55:22 +0000
commitfbf061a9a0dd9ce533bc3c7b3486f517a31b5514 (patch)
tree774990a00d162036e5a2794cbcb9a7b0c3d8ded6
parentc2625f99789ad71f5295b86a1d2e2217ee2c5886 (diff)
downloadwebsocket-client-fbf061a9a0dd9ce533bc3c7b3486f517a31b5514.tar.gz
update dict access (#818)
* update dict access ``` if 'header' not in options or 'Sec-WebSocket-Key' not in options['header']: ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ TypeError: argument of type 'NoneType' is not iterable``` * Remove extra space for linter Co-authored-by: engn33r <engn33r@users.noreply.github.com>
-rw-r--r--websocket/_handshake.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/websocket/_handshake.py b/websocket/_handshake.py
index f032c4b..6a57c95 100644
--- a/websocket/_handshake.py
+++ b/websocket/_handshake.py
@@ -81,7 +81,7 @@ def _get_handshake_headers(resource, url, host, port, options):
hostport = _pack_hostname(host)
else:
hostport = "%s:%d" % (_pack_hostname(host), port)
- if "host" in options and options["host"] is not None:
+ if options.get("host"):
headers.append("Host: %s" % options["host"])
else:
headers.append("Host: %s" % hostport)
@@ -89,7 +89,7 @@ def _get_handshake_headers(resource, url, host, port, options):
# scheme indicates whether http or https is used in Origin
# The same approach is used in parse_url of _url.py to set default port
scheme, url = url.split(":", 1)
- if "suppress_origin" not in options or not options["suppress_origin"]:
+ if not options.get("suppress_origin"):
if "origin" in options and options["origin"] is not None:
headers.append("Origin: %s" % options["origin"])
elif scheme == "wss":
@@ -100,16 +100,16 @@ def _get_handshake_headers(resource, url, host, port, options):
key = _create_sec_websocket_key()
# Append Sec-WebSocket-Key & Sec-WebSocket-Version if not manually specified
- if 'header' not in options or 'Sec-WebSocket-Key' not in options['header']:
+ if not options.get('header') or 'Sec-WebSocket-Key' not in options['header']:
key = _create_sec_websocket_key()
headers.append("Sec-WebSocket-Key: %s" % key)
else:
key = options['header']['Sec-WebSocket-Key']
- if 'header' not in options or 'Sec-WebSocket-Version' not in options['header']:
+ if not options.get('header') or 'Sec-WebSocket-Version' not in options['header']:
headers.append("Sec-WebSocket-Version: %s" % VERSION)
- if 'connection' not in options or options['connection'] is None:
+ if not options.get('connection'):
headers.append('Connection: Upgrade')
else:
headers.append(options['connection'])
@@ -118,8 +118,8 @@ def _get_handshake_headers(resource, url, host, port, options):
if subprotocols:
headers.append("Sec-WebSocket-Protocol: %s" % ",".join(subprotocols))
- if "header" in options:
- header = options["header"]
+ header = options.get("header")
+ if header:
if isinstance(header, dict):
header = [
": ".join([k, v])