Skip to content

Commit

Permalink
cosmetic: make code more readable
Browse files Browse the repository at this point in the history
  • Loading branch information
totaam committed Sep 2, 2022
1 parent 61ed242 commit 1f94ad7
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 63 deletions.
12 changes: 6 additions & 6 deletions xpra/net/websockets/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,16 @@ def get_headers(host, port):
try:
header_module = __import__(f"xpra.net.websockets.headers.{mod_name}", {}, {}, ["get_headers"])
v = header_module.get_headers(host, port)
log("%s.get_headers(%s, %s)=%s", mod_name, host, port, v)
log(f"{mod_name}.get_headers({host}, {port})={v}")
headers.update(v)
except ImportError as e:
log("import %s", mod_name, exc_info=True)
log.error("Error: websocket header module %s not available", mod_name)
log.error(f"Error: websocket header module {mod_name!r} not available")
log.error(" %s", e)
except Exception as e:
log("get_headers %s", mod_name, exc_info=True)
log.error("Error: cannot get headers from '%s'", mod_name)
log.error(" %s", e)
log.error(f"Error: cannot get headers from module {mod_name!r}")
log.estr(e)
return headers


Expand All @@ -55,7 +55,7 @@ def client_upgrade(read, write, host, port, path=""):

def get_client_upgrade_request(host, port, path, key):
request = f"GET /{path} HTTP/1.1"
log("client_upgrade: http request: %s", request)
log(f"client websocket upgrade request: {request!r}")
lines = [request.encode("latin1")]
headers = get_headers(host, port)
headers[b"Sec-WebSocket-Key"] = key
Expand Down Expand Up @@ -95,7 +95,7 @@ def parse_response_header(response):
return headers

def verify_response_headers(headers, key):
log("verify_response_headers(%s)", headers)
log(f"verify_response_headers({headers!r})")
if not headers:
raise Exception("no http headers found in response")
if headers.get("www-authenticate"):
Expand Down
8 changes: 4 additions & 4 deletions xpra/net/websockets/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def handle_websocket(self):
self.finish = super().finish

def do_GET(self):
log("do_GET() path=%s, headers=%s", self.path, self.headers)
log(f"do_GET() path={self.path!r}, headers={self.headers!r}")
upgrade_requested = (self.headers.get('upgrade') or "").lower() == 'websocket'
if self.only_upgrade or upgrade_requested:
if not upgrade_requested:
Expand All @@ -85,8 +85,8 @@ def do_GET(self):
except Exception as e:
log("do_GET()", exc_info=True)
log.error("Error: cannot handle websocket upgrade:")
log.error(" %s", e)
self.send_error(403, "failed to handle websocket: %s" % e)
log.estr(e)
self.send_error(403, f"failed to handle websocket: {e}")
return
if self.headers.get("Upgrade-Insecure-Requests", "")=="1" and self.redirect_https:
self.do_redirect_https()
Expand Down Expand Up @@ -124,6 +124,6 @@ def handle_request(self):

def finish(self):
super().finish()
log("finish() close_connection=%s, connection=%s", self.close_connection, self.connection)
log(f"finish() close_connection={self.close_connection}, connection={self.connection}")
if self.close_connection:
self.connection.close()
Loading

0 comments on commit 1f94ad7

Please sign in to comment.