mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 09:02:15 -06:00
a bit faster
This commit is contained in:
parent
abff40519d
commit
cb6de0387d
|
@ -67,9 +67,9 @@ class AXS(object):
|
||||||
self.upget: set[str] = set(upget or [])
|
self.upget: set[str] = set(upget or [])
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "AXS({})".format(
|
return "AXS(%s)" % (
|
||||||
", ".join(
|
", ".join(
|
||||||
"{}={!r}".format(k, self.__dict__[k])
|
"%s=%r" % (k, self.__dict__[k])
|
||||||
for k in "uread uwrite umove udel uget upget".split()
|
for k in "uread uwrite umove udel uget upget".split()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
@ -304,9 +304,9 @@ class VFS(object):
|
||||||
self.all_vols = {}
|
self.all_vols = {}
|
||||||
|
|
||||||
def __repr__(self) -> str:
|
def __repr__(self) -> str:
|
||||||
return "VFS({})".format(
|
return "VFS(%s)" % (
|
||||||
", ".join(
|
", ".join(
|
||||||
"{}={!r}".format(k, self.__dict__[k])
|
"%s=%r" % (k, self.__dict__[k])
|
||||||
for k in "realpath vpath axs flags".split()
|
for k in "realpath vpath axs flags".split()
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
|
@ -266,7 +266,7 @@ class HttpCli(object):
|
||||||
)
|
)
|
||||||
self.host = self.headers.get("host") or ""
|
self.host = self.headers.get("host") or ""
|
||||||
if not self.host:
|
if not self.host:
|
||||||
zs = "{}:{}".format(*list(self.s.getsockname()[:2]))
|
zs = "%s:%s" % self.s.getsockname()[:2]
|
||||||
self.host = zs[7:] if zs.startswith("::ffff:") else zs
|
self.host = zs[7:] if zs.startswith("::ffff:") else zs
|
||||||
|
|
||||||
n = self.args.rproxy
|
n = self.args.rproxy
|
||||||
|
@ -536,7 +536,7 @@ class HttpCli(object):
|
||||||
mime: Optional[str] = None,
|
mime: Optional[str] = None,
|
||||||
headers: Optional[dict[str, str]] = None,
|
headers: Optional[dict[str, str]] = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
response = ["{} {} {}".format(self.http_ver, status, HTTPCODE[status])]
|
response = ["%s %s %s" % (self.http_ver, status, HTTPCODE[status])]
|
||||||
|
|
||||||
if length is not None:
|
if length is not None:
|
||||||
response.append("Content-Length: " + unicode(length))
|
response.append("Content-Length: " + unicode(length))
|
||||||
|
@ -560,7 +560,7 @@ class HttpCli(object):
|
||||||
self.out_headers["Content-Type"] = mime
|
self.out_headers["Content-Type"] = mime
|
||||||
|
|
||||||
for k, zs in list(self.out_headers.items()) + self.out_headerlist:
|
for k, zs in list(self.out_headers.items()) + self.out_headerlist:
|
||||||
response.append("{}: {}".format(k, zs))
|
response.append("%s: %s" % (k, zs))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# best practice to separate headers and body into different packets
|
# best practice to separate headers and body into different packets
|
||||||
|
@ -626,7 +626,7 @@ class HttpCli(object):
|
||||||
if not kv:
|
if not kv:
|
||||||
return ""
|
return ""
|
||||||
|
|
||||||
r = ["{}={}".format(k, quotep(zs)) if zs else k for k, zs in kv.items()]
|
r = ["%s=%s" % (k, quotep(zs)) if zs else k for k, zs in kv.items()]
|
||||||
return "?" + "&".join(r)
|
return "?" + "&".join(r)
|
||||||
|
|
||||||
def redirect(
|
def redirect(
|
||||||
|
@ -952,8 +952,10 @@ class HttpCli(object):
|
||||||
|
|
||||||
isdir = stat.S_ISDIR(st.st_mode)
|
isdir = stat.S_ISDIR(st.st_mode)
|
||||||
|
|
||||||
t = "<D:response><D:href>/{}{}</D:href><D:propstat><D:prop>"
|
ret += "<D:response><D:href>/%s%s</D:href><D:propstat><D:prop>" % (
|
||||||
ret += t.format(quotep(rp), "/" if isdir and rp else "")
|
quotep(rp),
|
||||||
|
"/" if isdir and rp else "",
|
||||||
|
)
|
||||||
|
|
||||||
pvs: dict[str, str] = {
|
pvs: dict[str, str] = {
|
||||||
"displayname": html_escape(rp.split("/")[-1]),
|
"displayname": html_escape(rp.split("/")[-1]),
|
||||||
|
@ -969,13 +971,13 @@ class HttpCli(object):
|
||||||
if k not in props:
|
if k not in props:
|
||||||
continue
|
continue
|
||||||
elif v:
|
elif v:
|
||||||
ret += "<D:{0}>{1}</D:{0}>".format(k, v)
|
ret += "<D:%s>%s</D:%s>" % (k, v, k)
|
||||||
else:
|
else:
|
||||||
ret += "<D:{}/>".format(k)
|
ret += "<D:%s/>" % (k,)
|
||||||
|
|
||||||
ret += "</D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat>"
|
ret += "</D:prop><D:status>HTTP/1.1 200 OK</D:status></D:propstat>"
|
||||||
|
|
||||||
missing = ["<D:{}/>".format(x) for x in props if x not in pvs]
|
missing = ["<D:%s/>" % (x,) for x in props if x not in pvs]
|
||||||
if missing and clen:
|
if missing and clen:
|
||||||
t = "<D:propstat><D:prop>{}</D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat>"
|
t = "<D:propstat><D:prop>{}</D:prop><D:status>HTTP/1.1 404 Not Found</D:status></D:propstat>"
|
||||||
ret += t.format("".join(missing))
|
ret += t.format("".join(missing))
|
||||||
|
@ -1641,7 +1643,7 @@ class HttpCli(object):
|
||||||
|
|
||||||
spd1 = get_spd(nbytes, self.t0)
|
spd1 = get_spd(nbytes, self.t0)
|
||||||
spd2 = get_spd(self.conn.nbyte, self.conn.t0)
|
spd2 = get_spd(self.conn.nbyte, self.conn.t0)
|
||||||
return "{} {} n{}".format(spd1, spd2, self.conn.nreq)
|
return "%s %s n%s" % (spd1, spd2, self.conn.nreq)
|
||||||
|
|
||||||
def handle_post_multipart(self) -> bool:
|
def handle_post_multipart(self) -> bool:
|
||||||
self.parser = MultipartParser(self.log, self.sr, self.headers)
|
self.parser = MultipartParser(self.log, self.sr, self.headers)
|
||||||
|
@ -3053,7 +3055,7 @@ class HttpCli(object):
|
||||||
if self.is_vproxied:
|
if self.is_vproxied:
|
||||||
parents = self.args.R.split("/")
|
parents = self.args.R.split("/")
|
||||||
for parent in parents[::-1]:
|
for parent in parents[::-1]:
|
||||||
ret = {"k{}".format(parent): ret, "a": []}
|
ret = {"k%s" % (parent,): ret, "a": []}
|
||||||
|
|
||||||
zs = json.dumps(ret)
|
zs = json.dumps(ret)
|
||||||
self.reply(zs.encode("utf-8"), mime="application/json")
|
self.reply(zs.encode("utf-8"), mime="application/json")
|
||||||
|
@ -3592,12 +3594,12 @@ class HttpCli(object):
|
||||||
if self.args.no_zip:
|
if self.args.no_zip:
|
||||||
margin = "DIR"
|
margin = "DIR"
|
||||||
else:
|
else:
|
||||||
margin = '<a href="{}?zip" rel="nofollow">zip</a>'.format(
|
margin = '<a href="%s?zip" rel="nofollow">zip</a>' % (quotep(href),)
|
||||||
quotep(href)
|
|
||||||
)
|
|
||||||
elif fn in hist:
|
elif fn in hist:
|
||||||
margin = '<a href="{}.hist/{}">#{}</a>'.format(
|
margin = '<a href="%s.hist/%s">#%s</a>' % (
|
||||||
base, html_escape(hist[fn][2], quot=True, crlf=True), hist[fn][0]
|
base,
|
||||||
|
html_escape(hist[fn][2], quot=True, crlf=True),
|
||||||
|
hist[fn][0],
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
margin = "-"
|
margin = "-"
|
||||||
|
@ -3621,7 +3623,7 @@ class HttpCli(object):
|
||||||
ext = "%"
|
ext = "%"
|
||||||
|
|
||||||
if add_fk:
|
if add_fk:
|
||||||
href = "{}?k={}".format(
|
href = "%s?k=%s" % (
|
||||||
quotep(href),
|
quotep(href),
|
||||||
self.gen_fk(
|
self.gen_fk(
|
||||||
self.args.fk_salt, fspath, sz, 0 if ANYWIN else inf.st_ino
|
self.args.fk_salt, fspath, sz, 0 if ANYWIN else inf.st_ino
|
||||||
|
|
|
@ -684,20 +684,20 @@ class SvcHub(object):
|
||||||
print("\033[36m{}\033[0m\n".format(dt.strftime("%Y-%m-%d")), end="")
|
print("\033[36m{}\033[0m\n".format(dt.strftime("%Y-%m-%d")), end="")
|
||||||
self._set_next_day()
|
self._set_next_day()
|
||||||
|
|
||||||
fmt = "\033[36m{} \033[33m{:21} \033[0m{}\n"
|
fmt = "\033[36m%s \033[33m%-21s \033[0m%s\n"
|
||||||
if not VT100:
|
if not VT100:
|
||||||
fmt = "{} {:21} {}\n"
|
fmt = "%s %-21s %s\n"
|
||||||
if "\033" in msg:
|
if "\033" in msg:
|
||||||
msg = ansi_re.sub("", msg)
|
msg = ansi_re.sub("", msg)
|
||||||
if "\033" in src:
|
if "\033" in src:
|
||||||
src = ansi_re.sub("", src)
|
src = ansi_re.sub("", src)
|
||||||
elif c:
|
elif c:
|
||||||
if isinstance(c, int):
|
if isinstance(c, int):
|
||||||
msg = "\033[3{}m{}\033[0m".format(c, msg)
|
msg = "\033[3%sm%s\033[0m" % (c, msg)
|
||||||
elif "\033" not in c:
|
elif "\033" not in c:
|
||||||
msg = "\033[{}m{}\033[0m".format(c, msg)
|
msg = "\033[%sm%s\033[0m" % (c, msg)
|
||||||
else:
|
else:
|
||||||
msg = "{}{}\033[0m".format(c, msg)
|
msg = "%s%s\033[0m" % (c, msg)
|
||||||
|
|
||||||
zd = datetime.utcfromtimestamp(now)
|
zd = datetime.utcfromtimestamp(now)
|
||||||
ts = "%02d:%02d:%02d.%03d" % (
|
ts = "%02d:%02d:%02d.%03d" % (
|
||||||
|
@ -706,7 +706,7 @@ class SvcHub(object):
|
||||||
zd.second,
|
zd.second,
|
||||||
zd.microsecond // 1000,
|
zd.microsecond // 1000,
|
||||||
)
|
)
|
||||||
msg = fmt.format(ts, src, msg)
|
msg = fmt % (ts, src, msg)
|
||||||
try:
|
try:
|
||||||
print(msg, end="")
|
print(msg, end="")
|
||||||
except UnicodeEncodeError:
|
except UnicodeEncodeError:
|
||||||
|
|
|
@ -380,9 +380,9 @@ class Up2k(object):
|
||||||
if rd.startswith("//") or fn.startswith("//"):
|
if rd.startswith("//") or fn.startswith("//"):
|
||||||
rd, fn = s3dec(rd, fn)
|
rd, fn = s3dec(rd, fn)
|
||||||
|
|
||||||
fvp = "{}/{}".format(rd, fn).strip("/")
|
fvp = ("%s/%s" % (rd, fn)).strip("/")
|
||||||
if vp:
|
if vp:
|
||||||
fvp = "{}/{}".format(vp, fvp)
|
fvp = "%s/%s" % (vp, fvp)
|
||||||
|
|
||||||
self._handle_rm(LEELOO_DALLAS, "", fvp, [])
|
self._handle_rm(LEELOO_DALLAS, "", fvp, [])
|
||||||
nrm += 1
|
nrm += 1
|
||||||
|
|
|
@ -1553,7 +1553,7 @@ def rand_name(fdir: str, fn: str, rnd: int) -> str:
|
||||||
def gen_filekey(salt: str, fspath: str, fsize: int, inode: int) -> str:
|
def gen_filekey(salt: str, fspath: str, fsize: int, inode: int) -> str:
|
||||||
return base64.urlsafe_b64encode(
|
return base64.urlsafe_b64encode(
|
||||||
hashlib.sha512(
|
hashlib.sha512(
|
||||||
"{} {} {} {}".format(salt, fspath, fsize, inode).encode("utf-8", "replace")
|
("%s %s %s %s" % (salt, fspath, fsize, inode)).encode("utf-8", "replace")
|
||||||
).digest()
|
).digest()
|
||||||
).decode("ascii")
|
).decode("ascii")
|
||||||
|
|
||||||
|
@ -1662,7 +1662,7 @@ def uncyg(path: str) -> str:
|
||||||
if len(path) > 2 and path[2] != "/":
|
if len(path) > 2 and path[2] != "/":
|
||||||
return path
|
return path
|
||||||
|
|
||||||
return "{}:\\{}".format(path[1], path[3:])
|
return "%s:\\%s" % (path[1], path[3:])
|
||||||
|
|
||||||
|
|
||||||
def undot(path: str) -> str:
|
def undot(path: str) -> str:
|
||||||
|
@ -1705,7 +1705,7 @@ def sanitize_fn(fn: str, ok: str, bad: list[str]) -> str:
|
||||||
|
|
||||||
bad = ["con", "prn", "aux", "nul"]
|
bad = ["con", "prn", "aux", "nul"]
|
||||||
for n in range(1, 10):
|
for n in range(1, 10):
|
||||||
bad += "com{0} lpt{0}".format(n).split(" ")
|
bad += ("com%s lpt%s" % (n, n)).split(" ")
|
||||||
|
|
||||||
if fn.lower().split(".")[0] in bad:
|
if fn.lower().split(".")[0] in bad:
|
||||||
fn = "_" + fn
|
fn = "_" + fn
|
||||||
|
|
Loading…
Reference in a new issue