small optimizations

This commit is contained in:
ed 2026-01-30 20:08:29 +00:00
parent ed6a8d5a73
commit 08b0abdbdd
5 changed files with 15 additions and 15 deletions

View file

@ -572,13 +572,12 @@ class HttpCli(object):
ptn_cc = RE_CC ptn_cc = RE_CC
k_safe = UPARAM_CC_OK k_safe = UPARAM_CC_OK
for k in arglist.split("&"): for k in arglist.split("&"):
sv = ""
if "=" in k: if "=" in k:
k, zs = k.split("=", 1) k, zs = k.split("=", 1)
# x-www-form-urlencoded (url query part) uses # x-www-form-urlencoded (url query part) uses
# either + or %20 for 0x20 so handle both # either + or %20 for 0x20 so handle both
sv = unquotep(zs.strip().replace("+", " ")) sv = unquotep(zs.strip().replace("+", " "))
else:
sv = ""
m = re_k.search(k) m = re_k.search(k)
if m: if m:
@ -1550,6 +1549,7 @@ class HttpCli(object):
hits = idx.run_query(self.uname, [self.vn], uq, uv, False, False, nmax)[0] hits = idx.run_query(self.uname, [self.vn], uq, uv, False, False, nmax)[0]
q_pw = a_pw = ""
pwk = self.args.pw_urlp pwk = self.args.pw_urlp
if pwk in self.ouparam and "nopw" not in self.ouparam: if pwk in self.ouparam and "nopw" not in self.ouparam:
zs = self.ouparam[pwk] zs = self.ouparam[pwk]
@ -1557,8 +1557,6 @@ class HttpCli(object):
a_pw = "&%s=%s" % (pwk, quotep(zs)) a_pw = "&%s=%s" % (pwk, quotep(zs))
for i in hits: for i in hits:
i["rp"] += a_pw if "?" in i["rp"] else q_pw 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] title = self.uparam.get("title") or self.vpath.split("/")[-1]
etitle = html_escape(title, True, True) etitle = html_escape(title, True, True)
@ -1929,7 +1927,6 @@ class HttpCli(object):
pvs["getcontentlength"] = str(st.st_size) pvs["getcontentlength"] = str(st.st_size)
elif df: elif df:
pvs.update(df) pvs.update(df)
df = {}
for k, v in pvs.items(): for k, v in pvs.items():
if k not in props: if k not in props:
@ -4554,14 +4551,13 @@ class HttpCli(object):
if stat.S_ISDIR(st.st_mode): if stat.S_ISDIR(st.st_mode):
continue continue
sz = st.st_size
if stat.S_ISBLK(st.st_mode): if stat.S_ISBLK(st.st_mode):
fd = bos.open(fs_path, os.O_RDONLY) fd = bos.open(fs_path, os.O_RDONLY)
try: try:
sz = os.lseek(fd, 0, os.SEEK_END) sz = os.lseek(fd, 0, os.SEEK_END)
finally: finally:
os.close(fd) os.close(fd)
else:
sz = st.st_size
file_ts = max(file_ts, st.st_mtime) file_ts = max(file_ts, st.st_mtime)
editions[ext or "plain"] = (fs_path, sz) editions[ext or "plain"] = (fs_path, sz)

View file

@ -16,7 +16,7 @@ from .multicast import MC_Sck, MCast
from .util import IP6_LL, CachedSet, Daemon, Netdev, list_ips, min_ex from .util import IP6_LL, CachedSet, Daemon, Netdev, list_ips, min_ex
try: 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() raise ImportError()
from .stolen.dnslib import ( from .stolen.dnslib import (
AAAA, AAAA,
@ -66,7 +66,7 @@ if TYPE_CHECKING:
if True: # pylint: disable=using-constant-test if True: # pylint: disable=using-constant-test
from typing import Any, Optional, Union from typing import Any, Optional, Union
if os.getenv("PRTY_MODSPEC"): if os.environ.get("PRTY_MODSPEC"):
from inspect import getsourcefile from inspect import getsourcefile
print("PRTY_MODSPEC: dnslib:", getsourcefile(A)) print("PRTY_MODSPEC: dnslib:", getsourcefile(A))

View file

@ -4,7 +4,7 @@ from __future__ import print_function, unicode_literals
import os import os
try: 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() raise ImportError()
from .stolen.qrcodegen import QrCode from .stolen.qrcodegen import QrCode
@ -14,7 +14,7 @@ except ImportError:
VENDORED = False VENDORED = False
from qrcodegen import QrCode from qrcodegen import QrCode
if os.getenv("PRTY_MODSPEC"): if os.environ.get("PRTY_MODSPEC"):
from inspect import getsourcefile from inspect import getsourcefile
print("PRTY_MODSPEC: qrcode:", getsourcefile(QrCode)) print("PRTY_MODSPEC: qrcode:", getsourcefile(QrCode))

View file

@ -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" 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) 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." 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: if not al.no_ses:
al.no_ses = True al.no_ses = True
@ -1741,7 +1745,7 @@ class SvcHub(object):
def sd_notify(self) -> None: def sd_notify(self) -> None:
try: try:
zb = os.getenv("NOTIFY_SOCKET") zb = os.environ.get("NOTIFY_SOCKET")
if not zb: if not zb:
return return

View file

@ -150,7 +150,7 @@ try:
if os.environ.get("PRTY_NO_IFADDR"): if os.environ.get("PRTY_NO_IFADDR"):
raise Exception() raise Exception()
try: 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() raise ImportError()
from .stolen.ifaddr import get_adapters from .stolen.ifaddr import get_adapters
@ -202,7 +202,7 @@ try:
except: except:
pass pass
if os.getenv("PRTY_MODSPEC"): if os.environ.get("PRTY_MODSPEC"):
from inspect import getsourcefile from inspect import getsourcefile
print("PRTY_MODSPEC: ifaddr:", getsourcefile(get_adapters)) print("PRTY_MODSPEC: ifaddr:", getsourcefile(get_adapters))