mirror of
https://github.com/9001/copyparty.git
synced 2026-02-20 09:19:58 +10:00
small optimizations
This commit is contained in:
@@ -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)
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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))
|
||||
|
||||
Reference in New Issue
Block a user