Skip to content

Commit

Permalink
fix build errors from missing : in if statements
Browse files Browse the repository at this point in the history
  • Loading branch information
engn33r committed Dec 3, 2023
1 parent 780584f commit 2f51937
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions websocket/_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ def read(
sel.register(self.app.sock.sock, selectors.EVENT_READ)
try:
while self.app.keep_running:
if r:= sel.select(self.ping_timeout)
if r:= sel.select(self.ping_timeout):
if not read_callback():
break
check_callback()
Expand All @@ -111,7 +111,7 @@ def read(
sel.register(sock, selectors.EVENT_READ)
try:
while self.app.keep_running:
if r:= self.select(sock, sel)
if r:= self.select(sock, sel):
if not read_callback():
break
check_callback()
Expand Down
2 changes: 1 addition & 1 deletion websocket/_cookiejar.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def add(self, set_cookie: Optional[str]) -> None:
simpleCookie = http.cookies.SimpleCookie(set_cookie)

for k, v in simpleCookie.items():
if domain:= v.get("domain")
if domain:= v.get("domain"):
if not domain.startswith("."):
domain = f".{domain}"
cookie = self.jar.get(domain) if self.jar.get(domain) else http.cookies.SimpleCookie()
Expand Down
22 changes: 11 additions & 11 deletions websocket/_handshake.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,47 +73,47 @@ def _pack_hostname(hostname: str) -> str:

def _get_handshake_headers(resource: str, url: str, host: str, port: int, options: dict):
headers = [
"GET {resource} HTTP/1.1".format(resource=resource),
f"GET {resource} HTTP/1.1",
"Upgrade: websocket"
]
if port in [80, 443]:
hostport = _pack_hostname(host)
else:
hostport = "{h}:{p}".format(h=_pack_hostname(host), p=port)
hostport = f"{_pack_hostname(host)}:{port}"
if options.get("host"):
headers.append("Host: {h}".format(h=options["host"]))
headers.append(f'Host: {options["host"]}')
else:
headers.append("Host: {hp}".format(hp=hostport))
headers.append(f"Host: {hostport}")

# 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 not options.get("suppress_origin"):
if "origin" in options and options["origin"] is not None:
headers.append("Origin: {origin}".format(origin=options["origin"]))
headers.append(f'Origin: {options["origin"]}')
elif scheme == "wss":
headers.append("Origin: https://{hp}".format(hp=hostport))
headers.append(f"Origin: https://{hostport}")
else:
headers.append("Origin: http://{hp}".format(hp=hostport))
headers.append(f"Origin: http://{hostport}")

key = _create_sec_websocket_key()

# Append Sec-WebSocket-Key & Sec-WebSocket-Version if not manually specified
if not options.get('header') or 'Sec-WebSocket-Key' not in options['header']:
headers.append("Sec-WebSocket-Key: {key}".format(key=key))
headers.append(f"Sec-WebSocket-Key: {key}")
else:
key = options['header']['Sec-WebSocket-Key']

if not options.get('header') or 'Sec-WebSocket-Version' not in options['header']:
headers.append("Sec-WebSocket-Version: {version}".format(version=VERSION))
headers.append(f"Sec-WebSocket-Version: {VERSION}")

if not options.get('connection'):
headers.append('Connection: Upgrade')
else:
headers.append(options['connection'])

if subprotocols := options.get("subprotocols"):
headers.append("Sec-WebSocket-Protocol: {protocols}".format(protocols=",".join(subprotocols)))
headers.append(f'Sec-WebSocket-Protocol: {",".join(subprotocols)}')

if header := options.get("header"):
if isinstance(header, dict):
Expand All @@ -128,7 +128,7 @@ def _get_handshake_headers(resource: str, url: str, host: str, port: int, option
client_cookie = options.get("cookie", None)

if cookie := "; ".join(filter(None, [server_cookie, client_cookie])):
headers.append("Cookie: {cookie}".format(cookie=cookie))
headers.append(f"Cookie: {cookie}")

headers.extend(("", ""))
return headers, key
Expand Down
2 changes: 1 addition & 1 deletion websocket/_url.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ def _is_address_in_network(ip: str, net: str) -> bool:

def _is_no_proxy_host(hostname: str, no_proxy: Optional[list]) -> bool:
if not no_proxy:
if v:= os.environ.get("no_proxy", os.environ.get("NO_PROXY", "")).replace(" ", "")
if v:= os.environ.get("no_proxy", os.environ.get("NO_PROXY", "")).replace(" ", ""):
no_proxy = v.split(",")
if not no_proxy:
no_proxy = DEFAULT_NO_PROXY_HOST
Expand Down

0 comments on commit 2f51937

Please sign in to comment.