From 08b0abdbddb07957febb55b606ba2bbe1fbf2ce1 Mon Sep 17 00:00:00 2001 From: ed Date: Fri, 30 Jan 2026 20:08:29 +0000 Subject: [PATCH] small optimizations --- copyparty/httpcli.py | 10 +++------- copyparty/mdns.py | 4 ++-- copyparty/qrkode.py | 4 ++-- copyparty/svchub.py | 8 ++++++-- copyparty/util.py | 4 ++-- 5 files changed, 15 insertions(+), 15 deletions(-) diff --git a/copyparty/httpcli.py b/copyparty/httpcli.py index 7ca6ceee..d5bdbb9d 100644 --- a/copyparty/httpcli.py +++ b/copyparty/httpcli.py @@ -572,13 +572,12 @@ class HttpCli(object): ptn_cc = RE_CC k_safe = UPARAM_CC_OK for k in arglist.split("&"): + sv = "" if "=" in k: k, zs = k.split("=", 1) # x-www-form-urlencoded (url query part) uses # either + or %20 for 0x20 so handle both sv = unquotep(zs.strip().replace("+", " ")) - else: - sv = "" m = re_k.search(k) if m: @@ -1550,6 +1549,7 @@ class HttpCli(object): hits = idx.run_query(self.uname, [self.vn], uq, uv, False, False, nmax)[0] + q_pw = a_pw = "" pwk = self.args.pw_urlp if pwk in self.ouparam and "nopw" not in self.ouparam: zs = self.ouparam[pwk] @@ -1557,8 +1557,6 @@ class HttpCli(object): a_pw = "&%s=%s" % (pwk, quotep(zs)) for i in hits: i["rp"] += a_pw if "?" in i["rp"] else q_pw - else: - q_pw = a_pw = "" title = self.uparam.get("title") or self.vpath.split("/")[-1] etitle = html_escape(title, True, True) @@ -1929,7 +1927,6 @@ class HttpCli(object): pvs["getcontentlength"] = str(st.st_size) elif df: pvs.update(df) - df = {} for k, v in pvs.items(): if k not in props: @@ -4554,14 +4551,13 @@ class HttpCli(object): if stat.S_ISDIR(st.st_mode): continue + sz = st.st_size if stat.S_ISBLK(st.st_mode): fd = bos.open(fs_path, os.O_RDONLY) try: sz = os.lseek(fd, 0, os.SEEK_END) finally: os.close(fd) - else: - sz = st.st_size file_ts = max(file_ts, st.st_mtime) editions[ext or "plain"] = (fs_path, sz) diff --git a/copyparty/mdns.py b/copyparty/mdns.py index f64ce605..bc87ef51 100644 --- a/copyparty/mdns.py +++ b/copyparty/mdns.py @@ -16,7 +16,7 @@ from .multicast import MC_Sck, MCast from .util import IP6_LL, CachedSet, Daemon, Netdev, list_ips, min_ex try: - if os.getenv("PRTY_SYS_ALL") or os.getenv("PRTY_SYS_DNSLIB"): + if os.environ.get("PRTY_SYS_ALL") or os.environ.get("PRTY_SYS_DNSLIB"): raise ImportError() from .stolen.dnslib import ( AAAA, @@ -66,7 +66,7 @@ if TYPE_CHECKING: if True: # pylint: disable=using-constant-test from typing import Any, Optional, Union -if os.getenv("PRTY_MODSPEC"): +if os.environ.get("PRTY_MODSPEC"): from inspect import getsourcefile print("PRTY_MODSPEC: dnslib:", getsourcefile(A)) diff --git a/copyparty/qrkode.py b/copyparty/qrkode.py index 34ebbcca..10e08233 100644 --- a/copyparty/qrkode.py +++ b/copyparty/qrkode.py @@ -4,7 +4,7 @@ from __future__ import print_function, unicode_literals import os try: - if os.getenv("PRTY_SYS_ALL") or os.getenv("PRTY_SYS_QRCG"): + if os.environ.get("PRTY_SYS_ALL") or os.environ.get("PRTY_SYS_QRCG"): raise ImportError() from .stolen.qrcodegen import QrCode @@ -14,7 +14,7 @@ except ImportError: VENDORED = False from qrcodegen import QrCode -if os.getenv("PRTY_MODSPEC"): +if os.environ.get("PRTY_MODSPEC"): from inspect import getsourcefile print("PRTY_MODSPEC: qrcode:", getsourcefile(QrCode)) diff --git a/copyparty/svchub.py b/copyparty/svchub.py index 39c0491a..e872b595 100644 --- a/copyparty/svchub.py +++ b/copyparty/svchub.py @@ -1033,7 +1033,11 @@ class SvcHub(object): t = "WARNING:\nDisabling WebDAV support because dxml selftest failed. Please report this bug;\n%s\n...and include the following information in the bug-report:\n%s | expat %s\n" self.log("root", t % (URL_BUG, VERSIONS, expat_ver()), 1) - if not E.scfg and not al.unsafe_state and not os.getenv("PRTY_UNSAFE_STATE"): + if ( + not E.scfg + and not al.unsafe_state + and not os.environ.get("PRTY_UNSAFE_STATE") + ): t = "because runtime config is currently being stored in an untrusted emergency-fallback location. Please fix your environment so either XDG_CONFIG_HOME or ~/.config can be used instead, or disable this safeguard with --unsafe-state or env-var PRTY_UNSAFE_STATE=1." if not al.no_ses: al.no_ses = True @@ -1741,7 +1745,7 @@ class SvcHub(object): def sd_notify(self) -> None: try: - zb = os.getenv("NOTIFY_SOCKET") + zb = os.environ.get("NOTIFY_SOCKET") if not zb: return diff --git a/copyparty/util.py b/copyparty/util.py index a2e0e784..fd99ef4b 100644 --- a/copyparty/util.py +++ b/copyparty/util.py @@ -150,7 +150,7 @@ try: if os.environ.get("PRTY_NO_IFADDR"): raise Exception() try: - if os.getenv("PRTY_SYS_ALL") or os.getenv("PRTY_SYS_IFADDR"): + if os.environ.get("PRTY_SYS_ALL") or os.environ.get("PRTY_SYS_IFADDR"): raise ImportError() from .stolen.ifaddr import get_adapters @@ -202,7 +202,7 @@ try: except: pass -if os.getenv("PRTY_MODSPEC"): +if os.environ.get("PRTY_MODSPEC"): from inspect import getsourcefile print("PRTY_MODSPEC: ifaddr:", getsourcefile(get_adapters))