From 54caf63f6aab9198d0e2038da38b2d7b0622bffc Mon Sep 17 00:00:00 2001 From: ed Date: Thu, 7 Aug 2025 15:18:59 +0000 Subject: [PATCH] optimize --- copyparty/__main__.py | 4 ++-- copyparty/httpcli.py | 13 +++++-------- copyparty/multicast.py | 6 +----- copyparty/svchub.py | 2 +- 4 files changed, 9 insertions(+), 16 deletions(-) diff --git a/copyparty/__main__.py b/copyparty/__main__.py index 86b6b031..eb44ef4f 100644 --- a/copyparty/__main__.py +++ b/copyparty/__main__.py @@ -536,7 +536,7 @@ def get_sects(): dedent( """ \033[33m-i\033[0m takes a comma-separated list of interfaces to listen on; - IP-addresses, unix-sockets and/or open file descriptors + IP-addresses, unix-sockets, and/or open file descriptors the default (\033[32m-i ::\033[0m) means all IPv4 and IPv6 addresses @@ -564,7 +564,7 @@ def get_sects(): \033[32m-i fd:\033[33m3\033[0m uses the socket passed to copyparty on file descriptor 3 - \033[33m-p\033[0m (tcp ports) is ignored for non ip-addresses + \033[33m-p\033[0m (tcp ports) is ignored for unix-sockets and FDs """ ), ], diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index b335fe4a..c982a812 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -262,7 +262,8 @@ class HttpCli(object): def _assert_safe_rem(self, rem: str) -> None: # sanity check to prevent any disasters - if rem.startswith("/") or rem.startswith("../") or "/../" in rem: + # (this function hopefully serves no purpose; validation has already happened at this point, this only exists as a last-ditch effort just in case) + if rem.startswith(("/", "../")) or "/../" in rem: raise Exception("that was close") def _gen_fk(self, alg: int, salt: str, fspath: str, fsize: int, inode: int) -> str: @@ -5031,7 +5032,7 @@ class HttpCli(object): wvol = [x for x in wvol if "unlistcw" not in allvols[x[1:-1]].flags] fmt = self.uparam.get("ls", "") - if not fmt and (self.ua.startswith("curl/") or self.ua.startswith("fetch")): + if not fmt and self.ua.startswith(("curl/", "fetch")): fmt = "v" if fmt in ["v", "t", "txt"]: @@ -5141,7 +5142,7 @@ class HttpCli(object): t = '

404 not found  ┐( ´ -`)┌

go home

' pt = "404 not found ┐( ´ -`)┌" - if self.ua.startswith("curl/") or self.ua.startswith("fetch"): + if self.ua.startswith(("curl/", "fetch")): pt = "# acct: %s\n%s\n" % (self.uname, pt) self.reply(pt.encode("utf-8"), status=rc) return True @@ -6267,11 +6268,7 @@ class HttpCli(object): is_ls = "ls" in self.uparam is_js = self.args.force_js or self.cookies.get("js") == "y" - if ( - not is_ls - and not add_og - and (self.ua.startswith("curl/") or self.ua.startswith("fetch")) - ): + if not is_ls and not add_og and self.ua.startswith(("curl/", "fetch")): self.uparam["ls"] = "v" is_ls = True diff --git a/copyparty/multicast.py b/copyparty/multicast.py index 6d6507f8..766dc15d 100644 --- a/copyparty/multicast.py +++ b/copyparty/multicast.py @@ -183,11 +183,7 @@ class MCast(object): srv.ips[oth_ip.split("/")[0]] = ipaddress.ip_network(oth_ip, False) # gvfs breaks if a linklocal ip appears in a dns reply - ll = { - k: v - for k, v in srv.ips.items() - if k.startswith("169.254") or k.startswith("fe80") - } + ll = {k: v for k, v in srv.ips.items() if k.startswith(("169.254", "fe80"))} rt = {k: v for k, v in srv.ips.items() if k not in ll} if self.args.ll or not rt: diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 9a00f890..07d85d83 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -878,7 +878,7 @@ class SvcHub(object): setattr(al, zs, False) zb = True if zb: - t = "no ip addresses provided; cannot enable zeroconf/mdns/ssdp as requested" + t = "not listening on any ip-addresses (only unix-sockets and/or FDs); cannot enable zeroconf/mdns/ssdp as requested" self.log("root", t, 3) if not self.args.no_dav: