mirror of
https://github.com/9001/copyparty.git
synced 2025-08-17 00:52:16 -06:00
suboptimizations and some future safeguards
This commit is contained in:
parent
f1358dbaba
commit
86419b8f47
|
@ -1057,14 +1057,13 @@ class Ctl(object):
|
||||||
self.uploader_busy += 1
|
self.uploader_busy += 1
|
||||||
self.t0_up = self.t0_up or time.time()
|
self.t0_up = self.t0_up or time.time()
|
||||||
|
|
||||||
zs = "{0}/{1}/{2}/{3} {4}/{5} {6}"
|
stats = "%d/%d/%d/%d %d/%d %s" % (
|
||||||
stats = zs.format(
|
|
||||||
self.up_f,
|
self.up_f,
|
||||||
len(self.recheck),
|
len(self.recheck),
|
||||||
self.uploader_busy,
|
self.uploader_busy,
|
||||||
self.nfiles - self.up_f,
|
self.nfiles - self.up_f,
|
||||||
int(self.nbytes / (1024 * 1024)),
|
self.nbytes // (1024 * 1024),
|
||||||
int((self.nbytes - self.up_b) / (1024 * 1024)),
|
(self.nbytes - self.up_b) // (1024 * 1024),
|
||||||
self.eta,
|
self.eta,
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -1432,7 +1432,7 @@ def main(argv: Optional[list[str]] = None) -> None:
|
||||||
|
|
||||||
_, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
_, hard = resource.getrlimit(resource.RLIMIT_NOFILE)
|
||||||
if hard > 0: # -1 == infinite
|
if hard > 0: # -1 == infinite
|
||||||
nc = min(nc, hard // 4)
|
nc = min(nc, int(hard / 4))
|
||||||
except:
|
except:
|
||||||
nc = 512
|
nc = 512
|
||||||
|
|
||||||
|
|
|
@ -76,7 +76,7 @@ class MpWorker(BrokerCli):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def logw(self, msg: str, c: Union[int, str] = 0) -> None:
|
def logw(self, msg: str, c: Union[int, str] = 0) -> None:
|
||||||
self.log("mp{}".format(self.n), msg, c)
|
self.log("mp%d" % (self.n,), msg, c)
|
||||||
|
|
||||||
def main(self) -> None:
|
def main(self) -> None:
|
||||||
while True:
|
while True:
|
||||||
|
|
|
@ -190,7 +190,7 @@ class HttpCli(object):
|
||||||
|
|
||||||
def unpwd(self, m: Match[str]) -> str:
|
def unpwd(self, m: Match[str]) -> str:
|
||||||
a, b, c = m.groups()
|
a, b, c = m.groups()
|
||||||
return "{}\033[7m {} \033[27m{}".format(a, self.asrv.iacct[b], c)
|
return "%s\033[7m %s \033[27m%s" % (a, self.asrv.iacct[b], c)
|
||||||
|
|
||||||
def _check_nonfatal(self, ex: Pebkac, post: bool) -> bool:
|
def _check_nonfatal(self, ex: Pebkac, post: bool) -> bool:
|
||||||
if post:
|
if post:
|
||||||
|
@ -557,16 +557,16 @@ class HttpCli(object):
|
||||||
self.keepalive = False
|
self.keepalive = False
|
||||||
|
|
||||||
em = str(ex)
|
em = str(ex)
|
||||||
msg = em if pex == ex else min_ex()
|
msg = em if pex is ex else min_ex()
|
||||||
if pex.code != 404 or self.do_log:
|
if pex.code != 404 or self.do_log:
|
||||||
self.log(
|
self.log(
|
||||||
"{}\033[0m, {}".format(msg, self.vpath),
|
"%s\033[0m, %s" % (msg, self.vpath),
|
||||||
6 if em.startswith("client d/c ") else 3,
|
6 if em.startswith("client d/c ") else 3,
|
||||||
)
|
)
|
||||||
|
|
||||||
msg = "{}\r\nURL: {}\r\n".format(em, self.vpath)
|
msg = "%s\r\nURL: %s\r\n" % (em, self.vpath)
|
||||||
if self.hint:
|
if self.hint:
|
||||||
msg += "hint: {}\r\n".format(self.hint)
|
msg += "hint: %s\r\n" % (self.hint,)
|
||||||
|
|
||||||
if "database is locked" in em:
|
if "database is locked" in em:
|
||||||
self.conn.hsrv.broker.say("log_stacks")
|
self.conn.hsrv.broker.say("log_stacks")
|
||||||
|
@ -809,7 +809,7 @@ class HttpCli(object):
|
||||||
if k in skip:
|
if k in skip:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
t = "{}={}".format(quotep(k), quotep(v))
|
t = "%s=%s" % (quotep(k), quotep(v))
|
||||||
ret.append(t.replace(" ", "+").rstrip("="))
|
ret.append(t.replace(" ", "+").rstrip("="))
|
||||||
|
|
||||||
if not ret:
|
if not ret:
|
||||||
|
@ -857,7 +857,8 @@ class HttpCli(object):
|
||||||
oh = self.out_headers
|
oh = self.out_headers
|
||||||
origin = origin.lower()
|
origin = origin.lower()
|
||||||
good_origins = self.args.acao + [
|
good_origins = self.args.acao + [
|
||||||
"{}://{}".format(
|
"%s://%s"
|
||||||
|
% (
|
||||||
"https" if self.is_https else "http",
|
"https" if self.is_https else "http",
|
||||||
self.host.lower().split(":")[0],
|
self.host.lower().split(":")[0],
|
||||||
)
|
)
|
||||||
|
@ -1054,7 +1055,7 @@ class HttpCli(object):
|
||||||
self.can_read = self.can_write = self.can_get = False
|
self.can_read = self.can_write = self.can_get = False
|
||||||
|
|
||||||
if not self.can_read and not self.can_write and not self.can_get:
|
if not self.can_read and not self.can_write and not self.can_get:
|
||||||
self.log("inaccessible: [{}]".format(self.vpath))
|
self.log("inaccessible: [%s]" % (self.vpath,))
|
||||||
raise Pebkac(401, "authenticate")
|
raise Pebkac(401, "authenticate")
|
||||||
|
|
||||||
from .dxml import parse_xml
|
from .dxml import parse_xml
|
||||||
|
@ -1404,7 +1405,7 @@ class HttpCli(object):
|
||||||
if txt and len(txt) == orig_len:
|
if txt and len(txt) == orig_len:
|
||||||
raise Pebkac(500, "chunk slicing failed")
|
raise Pebkac(500, "chunk slicing failed")
|
||||||
|
|
||||||
buf = "{:x}\r\n".format(len(buf)).encode(enc) + buf
|
buf = ("%x\r\n" % (len(buf),)).encode(enc) + buf
|
||||||
self.s.sendall(buf + b"\r\n")
|
self.s.sendall(buf + b"\r\n")
|
||||||
return txt
|
return txt
|
||||||
|
|
||||||
|
@ -4231,7 +4232,7 @@ class HttpCli(object):
|
||||||
if icur:
|
if icur:
|
||||||
lmte = list(mte)
|
lmte = list(mte)
|
||||||
if self.can_admin:
|
if self.can_admin:
|
||||||
lmte += ["up_ip", ".up_at"]
|
lmte.extend(("up_ip", ".up_at"))
|
||||||
|
|
||||||
taglist = [k for k in lmte if k in tagset]
|
taglist = [k for k in lmte if k in tagset]
|
||||||
for fe in dirs:
|
for fe in dirs:
|
||||||
|
|
|
@ -93,7 +93,7 @@ class HttpConn(object):
|
||||||
self.rproxy = ip
|
self.rproxy = ip
|
||||||
|
|
||||||
self.ip = ip
|
self.ip = ip
|
||||||
self.log_src = "{} \033[{}m{}".format(ip, color, self.addr[1]).ljust(26)
|
self.log_src = ("%s \033[%dm%d" % (ip, color, self.addr[1])).ljust(26)
|
||||||
return self.log_src
|
return self.log_src
|
||||||
|
|
||||||
def respath(self, res_name: str) -> str:
|
def respath(self, res_name: str) -> str:
|
||||||
|
@ -176,7 +176,7 @@ class HttpConn(object):
|
||||||
|
|
||||||
self.s = ctx.wrap_socket(self.s, server_side=True)
|
self.s = ctx.wrap_socket(self.s, server_side=True)
|
||||||
msg = [
|
msg = [
|
||||||
"\033[1;3{:d}m{}".format(c, s)
|
"\033[1;3%dm%s" % (c, s)
|
||||||
for c, s in zip([0, 5, 0], self.s.cipher()) # type: ignore
|
for c, s in zip([0, 5, 0], self.s.cipher()) # type: ignore
|
||||||
]
|
]
|
||||||
self.log(" ".join(msg) + "\033[0m")
|
self.log(" ".join(msg) + "\033[0m")
|
||||||
|
|
|
@ -366,7 +366,7 @@ class HttpSrv(object):
|
||||||
if not self.t_periodic:
|
if not self.t_periodic:
|
||||||
name = "hsrv-pt"
|
name = "hsrv-pt"
|
||||||
if self.nid:
|
if self.nid:
|
||||||
name += "-{}".format(self.nid)
|
name += "-%d" % (self.nid,)
|
||||||
|
|
||||||
self.t_periodic = Daemon(self.periodic, name)
|
self.t_periodic = Daemon(self.periodic, name)
|
||||||
|
|
||||||
|
@ -385,7 +385,7 @@ class HttpSrv(object):
|
||||||
|
|
||||||
Daemon(
|
Daemon(
|
||||||
self.thr_client,
|
self.thr_client,
|
||||||
"httpconn-{}-{}".format(addr[0].split(".", 2)[-1][-6:], addr[1]),
|
"httpconn-%s-%d" % (addr[0].split(".", 2)[-1][-6:], addr[1]),
|
||||||
(sck, addr),
|
(sck, addr),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -402,9 +402,7 @@ class HttpSrv(object):
|
||||||
try:
|
try:
|
||||||
sck, addr = task
|
sck, addr = task
|
||||||
me = threading.current_thread()
|
me = threading.current_thread()
|
||||||
me.name = "httpconn-{}-{}".format(
|
me.name = "httpconn-%s-%d" % (addr[0].split(".", 2)[-1][-6:], addr[1])
|
||||||
addr[0].split(".", 2)[-1][-6:], addr[1]
|
|
||||||
)
|
|
||||||
self.thr_client(sck, addr)
|
self.thr_client(sck, addr)
|
||||||
me.name = self.name + "-poolw"
|
me.name = self.name + "-poolw"
|
||||||
except Exception as ex:
|
except Exception as ex:
|
||||||
|
|
|
@ -27,13 +27,13 @@ class Ico(object):
|
||||||
c1 = colorsys.hsv_to_rgb(zb[0] / 256.0, 1, 0.3)
|
c1 = colorsys.hsv_to_rgb(zb[0] / 256.0, 1, 0.3)
|
||||||
c2 = colorsys.hsv_to_rgb(zb[0] / 256.0, 0.8 if HAVE_PILF else 1, 1)
|
c2 = colorsys.hsv_to_rgb(zb[0] / 256.0, 0.8 if HAVE_PILF else 1, 1)
|
||||||
ci = [int(x * 255) for x in list(c1) + list(c2)]
|
ci = [int(x * 255) for x in list(c1) + list(c2)]
|
||||||
c = "".join(["{:02x}".format(x) for x in ci])
|
c = "".join(["%02x" % (x,) for x in ci])
|
||||||
|
|
||||||
w = 100
|
w = 100
|
||||||
h = 30
|
h = 30
|
||||||
if not self.args.th_no_crop and as_thumb:
|
if not self.args.th_no_crop and as_thumb:
|
||||||
sw, sh = self.args.th_size.split("x")
|
sw, sh = self.args.th_size.split("x")
|
||||||
h = int(100 / (float(sw) / float(sh)))
|
h = int(100.0 / (float(sw) / float(sh)))
|
||||||
w = 100
|
w = 100
|
||||||
|
|
||||||
if chrome:
|
if chrome:
|
||||||
|
@ -47,12 +47,12 @@ class Ico(object):
|
||||||
# [.lt] are hard to see lowercase / unspaced
|
# [.lt] are hard to see lowercase / unspaced
|
||||||
ext2 = re.sub("(.)", "\\1 ", ext).upper()
|
ext2 = re.sub("(.)", "\\1 ", ext).upper()
|
||||||
|
|
||||||
h = int(128 * h / w)
|
h = int(128.0 * h / w)
|
||||||
w = 128
|
w = 128
|
||||||
img = Image.new("RGB", (w, h), "#" + c[:6])
|
img = Image.new("RGB", (w, h), "#" + c[:6])
|
||||||
pb = ImageDraw.Draw(img)
|
pb = ImageDraw.Draw(img)
|
||||||
_, _, tw, th = pb.textbbox((0, 0), ext2, font_size=16)
|
_, _, tw, th = pb.textbbox((0, 0), ext2, font_size=16)
|
||||||
xy = ((w - tw) // 2, (h - th) // 2)
|
xy = (int((w - tw) / 2), int((h - th) / 2))
|
||||||
pb.text(xy, ext2, fill="#" + c[6:], font_size=16)
|
pb.text(xy, ext2, fill="#" + c[6:], font_size=16)
|
||||||
|
|
||||||
img = img.resize((w * 2, h * 2), Image.NEAREST)
|
img = img.resize((w * 2, h * 2), Image.NEAREST)
|
||||||
|
@ -68,7 +68,7 @@ class Ico(object):
|
||||||
# svg: 3s, cache: 6s, this: 8s
|
# svg: 3s, cache: 6s, this: 8s
|
||||||
from PIL import Image, ImageDraw
|
from PIL import Image, ImageDraw
|
||||||
|
|
||||||
h = int(64 * h / w)
|
h = int(64.0 * h / w)
|
||||||
w = 64
|
w = 64
|
||||||
img = Image.new("RGB", (w, h), "#" + c[:6])
|
img = Image.new("RGB", (w, h), "#" + c[:6])
|
||||||
pb = ImageDraw.Draw(img)
|
pb = ImageDraw.Draw(img)
|
||||||
|
|
|
@ -240,7 +240,7 @@ def parse_ffprobe(txt: str) -> tuple[dict[str, tuple[int, Any]], dict[str, list[
|
||||||
if "/" in fps:
|
if "/" in fps:
|
||||||
fa, fb = fps.split("/")
|
fa, fb = fps.split("/")
|
||||||
try:
|
try:
|
||||||
fps = int(fa) * 1.0 / int(fb)
|
fps = float(fa) / float(fb)
|
||||||
except:
|
except:
|
||||||
fps = 9001
|
fps = 9001
|
||||||
|
|
||||||
|
|
|
@ -65,21 +65,21 @@ class StreamTar(StreamArc):
|
||||||
cmp = re.sub(r"[^a-z0-9]*pax[^a-z0-9]*", "", cmp)
|
cmp = re.sub(r"[^a-z0-9]*pax[^a-z0-9]*", "", cmp)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cmp, lv = cmp.replace(":", ",").split(",")
|
cmp, zs = cmp.replace(":", ",").split(",")
|
||||||
lv = int(lv)
|
lv = int(zs)
|
||||||
except:
|
except:
|
||||||
lv = None
|
lv = -1
|
||||||
|
|
||||||
arg = {"name": None, "fileobj": self.qfile, "mode": "w", "format": fmt}
|
arg = {"name": None, "fileobj": self.qfile, "mode": "w", "format": fmt}
|
||||||
if cmp == "gz":
|
if cmp == "gz":
|
||||||
fun = tarfile.TarFile.gzopen
|
fun = tarfile.TarFile.gzopen
|
||||||
arg["compresslevel"] = lv if lv is not None else 3
|
arg["compresslevel"] = lv if lv >= 0 else 3
|
||||||
elif cmp == "bz2":
|
elif cmp == "bz2":
|
||||||
fun = tarfile.TarFile.bz2open
|
fun = tarfile.TarFile.bz2open
|
||||||
arg["compresslevel"] = lv if lv is not None else 2
|
arg["compresslevel"] = lv if lv >= 0 else 2
|
||||||
elif cmp == "xz":
|
elif cmp == "xz":
|
||||||
fun = tarfile.TarFile.xzopen
|
fun = tarfile.TarFile.xzopen
|
||||||
arg["preset"] = lv if lv is not None else 1
|
arg["preset"] = lv if lv >= 0 else 1
|
||||||
else:
|
else:
|
||||||
fun = tarfile.open
|
fun = tarfile.open
|
||||||
arg["mode"] = "w|"
|
arg["mode"] = "w|"
|
||||||
|
|
|
@ -474,7 +474,7 @@ class SvcHub(object):
|
||||||
import resource
|
import resource
|
||||||
|
|
||||||
soft, hard = [
|
soft, hard = [
|
||||||
x if x > 0 else 1024 * 1024
|
int(x) if x > 0 else 1024 * 1024
|
||||||
for x in list(resource.getrlimit(resource.RLIMIT_NOFILE))
|
for x in list(resource.getrlimit(resource.RLIMIT_NOFILE))
|
||||||
]
|
]
|
||||||
except:
|
except:
|
||||||
|
@ -791,7 +791,7 @@ class SvcHub(object):
|
||||||
self.logf.flush()
|
self.logf.flush()
|
||||||
|
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if now >= self.next_day:
|
if int(now) >= self.next_day:
|
||||||
self._set_next_day()
|
self._set_next_day()
|
||||||
|
|
||||||
def _set_next_day(self) -> None:
|
def _set_next_day(self) -> None:
|
||||||
|
@ -819,7 +819,7 @@ class SvcHub(object):
|
||||||
"""handles logging from all components"""
|
"""handles logging from all components"""
|
||||||
with self.log_mutex:
|
with self.log_mutex:
|
||||||
now = time.time()
|
now = time.time()
|
||||||
if now >= self.next_day:
|
if int(now) >= self.next_day:
|
||||||
dt = datetime.fromtimestamp(now, UTC)
|
dt = datetime.fromtimestamp(now, UTC)
|
||||||
zs = "{}\n" if self.no_ansi else "\033[36m{}\033[0m\n"
|
zs = "{}\n" if self.no_ansi else "\033[36m{}\033[0m\n"
|
||||||
zs = zs.format(dt.strftime("%Y-%m-%d"))
|
zs = zs.format(dt.strftime("%Y-%m-%d"))
|
||||||
|
|
|
@ -102,7 +102,7 @@ def thumb_path(histpath: str, rem: str, mtime: float, fmt: str, ffa: set[str]) -
|
||||||
rd += "\n" + fmt
|
rd += "\n" + fmt
|
||||||
h = hashlib.sha512(afsenc(rd)).digest()
|
h = hashlib.sha512(afsenc(rd)).digest()
|
||||||
b64 = base64.urlsafe_b64encode(h).decode("ascii")[:24]
|
b64 = base64.urlsafe_b64encode(h).decode("ascii")[:24]
|
||||||
rd = "{}/{}/".format(b64[:2], b64[2:4]).lower() + b64
|
rd = ("%s/%s/" % (b64[:2], b64[2:4])).lower() + b64
|
||||||
|
|
||||||
# could keep original filenames but this is safer re pathlen
|
# could keep original filenames but this is safer re pathlen
|
||||||
h = hashlib.sha512(afsenc(fn)).digest()
|
h = hashlib.sha512(afsenc(fn)).digest()
|
||||||
|
@ -115,7 +115,7 @@ def thumb_path(histpath: str, rem: str, mtime: float, fmt: str, ffa: set[str]) -
|
||||||
fmt = "webp" if fc == "w" else "png" if fc == "p" else "jpg"
|
fmt = "webp" if fc == "w" else "png" if fc == "p" else "jpg"
|
||||||
cat = "th"
|
cat = "th"
|
||||||
|
|
||||||
return "{}/{}/{}/{}.{:x}.{}".format(histpath, cat, rd, fn, int(mtime), fmt)
|
return "%s/%s/%s/%s.%x.%s" % (histpath, cat, rd, fn, int(mtime), fmt)
|
||||||
|
|
||||||
|
|
||||||
class ThumbSrv(object):
|
class ThumbSrv(object):
|
||||||
|
@ -382,7 +382,7 @@ class ThumbSrv(object):
|
||||||
# method 0 = pillow-default, fast
|
# method 0 = pillow-default, fast
|
||||||
# method 4 = ffmpeg-default
|
# method 4 = ffmpeg-default
|
||||||
# method 6 = max, slow
|
# method 6 = max, slow
|
||||||
fmts += ["RGBA", "LA"]
|
fmts.extend(("RGBA", "LA"))
|
||||||
args["method"] = 6
|
args["method"] = 6
|
||||||
else:
|
else:
|
||||||
# default q = 75
|
# default q = 75
|
||||||
|
|
|
@ -987,7 +987,7 @@ class Up2k(object):
|
||||||
excl = [x.replace("/", "\\") for x in excl]
|
excl = [x.replace("/", "\\") for x in excl]
|
||||||
else:
|
else:
|
||||||
# ~/.wine/dosdevices/z:/ and such
|
# ~/.wine/dosdevices/z:/ and such
|
||||||
excl += ["/dev", "/proc", "/run", "/sys"]
|
excl.extend(("/dev", "/proc", "/run", "/sys"))
|
||||||
|
|
||||||
rtop = absreal(top)
|
rtop = absreal(top)
|
||||||
n_add = n_rm = 0
|
n_add = n_rm = 0
|
||||||
|
@ -1089,7 +1089,7 @@ class Up2k(object):
|
||||||
cv = ""
|
cv = ""
|
||||||
|
|
||||||
assert self.pp and self.mem_cur
|
assert self.pp and self.mem_cur
|
||||||
self.pp.msg = "a{} {}".format(self.pp.n, cdir)
|
self.pp.msg = "a%d %s" % (self.pp.n, cdir)
|
||||||
|
|
||||||
rd = cdir[len(top) :].strip("/")
|
rd = cdir[len(top) :].strip("/")
|
||||||
if WINDOWS:
|
if WINDOWS:
|
||||||
|
@ -1164,8 +1164,8 @@ class Up2k(object):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if not sz and (
|
if not sz and (
|
||||||
"{}.PARTIAL".format(iname) in partials
|
"%s.PARTIAL" % (iname,) in partials
|
||||||
or ".{}.PARTIAL".format(iname) in partials
|
or ".%s.PARTIAL" % (iname,) in partials
|
||||||
):
|
):
|
||||||
# placeholder for unfinished upload
|
# placeholder for unfinished upload
|
||||||
continue
|
continue
|
||||||
|
@ -1261,7 +1261,7 @@ class Up2k(object):
|
||||||
else:
|
else:
|
||||||
at = 0
|
at = 0
|
||||||
|
|
||||||
self.pp.msg = "a{} {}".format(self.pp.n, abspath)
|
self.pp.msg = "a%d %s" % (self.pp.n, abspath)
|
||||||
|
|
||||||
if nohash or not sz:
|
if nohash or not sz:
|
||||||
wark = up2k_wark_from_metadata(self.salt, sz, lmod, rd, fn)
|
wark = up2k_wark_from_metadata(self.salt, sz, lmod, rd, fn)
|
||||||
|
@ -1361,7 +1361,7 @@ class Up2k(object):
|
||||||
rd = drd
|
rd = drd
|
||||||
|
|
||||||
abspath = djoin(top, rd)
|
abspath = djoin(top, rd)
|
||||||
self.pp.msg = "b{} {}".format(ndirs - nchecked, abspath)
|
self.pp.msg = "b%d %s" % (ndirs - nchecked, abspath)
|
||||||
try:
|
try:
|
||||||
if os.path.isdir(abspath):
|
if os.path.isdir(abspath):
|
||||||
continue
|
continue
|
||||||
|
@ -1713,7 +1713,7 @@ class Up2k(object):
|
||||||
cur.execute(q, (w[:16],))
|
cur.execute(q, (w[:16],))
|
||||||
|
|
||||||
abspath = djoin(ptop, rd, fn)
|
abspath = djoin(ptop, rd, fn)
|
||||||
self.pp.msg = "c{} {}".format(nq, abspath)
|
self.pp.msg = "c%d %s" % (nq, abspath)
|
||||||
if not mpool:
|
if not mpool:
|
||||||
n_tags = self._tagscan_file(cur, entags, w, abspath, ip, at)
|
n_tags = self._tagscan_file(cur, entags, w, abspath, ip, at)
|
||||||
else:
|
else:
|
||||||
|
@ -1770,7 +1770,7 @@ class Up2k(object):
|
||||||
if c2.execute(q, (row[0][:16],)).fetchone():
|
if c2.execute(q, (row[0][:16],)).fetchone():
|
||||||
continue
|
continue
|
||||||
|
|
||||||
gf.write("{}\n".format("\x00".join(row)).encode("utf-8"))
|
gf.write(("%s\n" % ("\x00".join(row),)).encode("utf-8"))
|
||||||
n += 1
|
n += 1
|
||||||
|
|
||||||
c2.close()
|
c2.close()
|
||||||
|
@ -2700,7 +2700,7 @@ class Up2k(object):
|
||||||
else:
|
else:
|
||||||
dip = self.hub.iphash.s(ip)
|
dip = self.hub.iphash.s(ip)
|
||||||
|
|
||||||
suffix = "-{:.6f}-{}".format(ts, dip)
|
suffix = "-%.6f-%s" % (ts, dip)
|
||||||
with ren_open(fname, "wb", fdir=fdir, suffix=suffix) as zfw:
|
with ren_open(fname, "wb", fdir=fdir, suffix=suffix) as zfw:
|
||||||
return zfw["orz"][1]
|
return zfw["orz"][1]
|
||||||
|
|
||||||
|
@ -2915,7 +2915,7 @@ class Up2k(object):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
z2 += [upt]
|
z2.append(upt)
|
||||||
if self.idx_wark(vflags, *z2):
|
if self.idx_wark(vflags, *z2):
|
||||||
del self.registry[ptop][wark]
|
del self.registry[ptop][wark]
|
||||||
else:
|
else:
|
||||||
|
@ -3208,9 +3208,9 @@ class Up2k(object):
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
volpath = "{}/{}".format(vrem, fn).strip("/")
|
volpath = ("%s/%s" % (vrem, fn)).strip("/")
|
||||||
vpath = "{}/{}".format(dbv.vpath, volpath).strip("/")
|
vpath = ("%s/%s" % (dbv.vpath, volpath)).strip("/")
|
||||||
self.log("rm {}\n {}".format(vpath, abspath))
|
self.log("rm %s\n %s" % (vpath, abspath))
|
||||||
_ = dbv.get(volpath, uname, *permsets[0])
|
_ = dbv.get(volpath, uname, *permsets[0])
|
||||||
if xbd:
|
if xbd:
|
||||||
if not runhook(
|
if not runhook(
|
||||||
|
@ -3742,7 +3742,7 @@ class Up2k(object):
|
||||||
return []
|
return []
|
||||||
|
|
||||||
if self.pp:
|
if self.pp:
|
||||||
mb = int(fsz / 1024 / 1024)
|
mb = fsz // (1024 * 1024)
|
||||||
self.pp.msg = prefix + str(mb) + suffix
|
self.pp.msg = prefix + str(mb) + suffix
|
||||||
|
|
||||||
hashobj = hashlib.sha512()
|
hashobj = hashlib.sha512()
|
||||||
|
@ -3807,7 +3807,7 @@ class Up2k(object):
|
||||||
else:
|
else:
|
||||||
dip = self.hub.iphash.s(job["addr"])
|
dip = self.hub.iphash.s(job["addr"])
|
||||||
|
|
||||||
suffix = "-{:.6f}-{}".format(job["t0"], dip)
|
suffix = "-%.6f-%s" % (job["t0"], dip)
|
||||||
with ren_open(tnam, "wb", fdir=pdir, suffix=suffix) as zfw:
|
with ren_open(tnam, "wb", fdir=pdir, suffix=suffix) as zfw:
|
||||||
f, job["tnam"] = zfw["orz"]
|
f, job["tnam"] = zfw["orz"]
|
||||||
abspath = djoin(pdir, job["tnam"])
|
abspath = djoin(pdir, job["tnam"])
|
||||||
|
@ -4138,6 +4138,6 @@ def up2k_wark_from_hashlist(salt: str, filesize: int, hashes: list[str]) -> str:
|
||||||
|
|
||||||
|
|
||||||
def up2k_wark_from_metadata(salt: str, sz: int, lastmod: int, rd: str, fn: str) -> str:
|
def up2k_wark_from_metadata(salt: str, sz: int, lastmod: int, rd: str, fn: str) -> str:
|
||||||
ret = sfsenc("{}\n{}\n{}\n{}\n{}".format(salt, lastmod, sz, rd, fn))
|
ret = sfsenc("%s\n%d\n%d\n%s\n%s" % (salt, lastmod, sz, rd, fn))
|
||||||
ret = base64.urlsafe_b64encode(hashlib.sha512(ret).digest())
|
ret = base64.urlsafe_b64encode(hashlib.sha512(ret).digest())
|
||||||
return "#{}".format(ret.decode("ascii"))[:44]
|
return ("#%s" % (ret.decode("ascii"),))[:44]
|
||||||
|
|
|
@ -849,7 +849,7 @@ class MTHash(object):
|
||||||
ex = ex or str(qe)
|
ex = ex or str(qe)
|
||||||
|
|
||||||
if pp:
|
if pp:
|
||||||
mb = int((fsz - nch * chunksz) / 1024 / 1024)
|
mb = (fsz - nch * chunksz) // (1024 * 1024)
|
||||||
pp.msg = prefix + str(mb) + suffix
|
pp.msg = prefix + str(mb) + suffix
|
||||||
|
|
||||||
if ex:
|
if ex:
|
||||||
|
@ -1071,7 +1071,7 @@ def uprint(msg: str) -> None:
|
||||||
|
|
||||||
|
|
||||||
def nuprint(msg: str) -> None:
|
def nuprint(msg: str) -> None:
|
||||||
uprint("{}\n".format(msg))
|
uprint("%s\n" % (msg,))
|
||||||
|
|
||||||
|
|
||||||
def dedent(txt: str) -> str:
|
def dedent(txt: str) -> str:
|
||||||
|
@ -1094,10 +1094,10 @@ def rice_tid() -> str:
|
||||||
def trace(*args: Any, **kwargs: Any) -> None:
|
def trace(*args: Any, **kwargs: Any) -> None:
|
||||||
t = time.time()
|
t = time.time()
|
||||||
stack = "".join(
|
stack = "".join(
|
||||||
"\033[36m{}\033[33m{}".format(x[0].split(os.sep)[-1][:-3], x[1])
|
"\033[36m%s\033[33m%s" % (x[0].split(os.sep)[-1][:-3], x[1])
|
||||||
for x in traceback.extract_stack()[3:-1]
|
for x in traceback.extract_stack()[3:-1]
|
||||||
)
|
)
|
||||||
parts = ["{:.6f}".format(t), rice_tid(), stack]
|
parts = ["%.6f" % (t,), rice_tid(), stack]
|
||||||
|
|
||||||
if args:
|
if args:
|
||||||
parts.append(repr(args))
|
parts.append(repr(args))
|
||||||
|
@ -1114,17 +1114,17 @@ def alltrace() -> str:
|
||||||
threads: dict[str, types.FrameType] = {}
|
threads: dict[str, types.FrameType] = {}
|
||||||
names = dict([(t.ident, t.name) for t in threading.enumerate()])
|
names = dict([(t.ident, t.name) for t in threading.enumerate()])
|
||||||
for tid, stack in sys._current_frames().items():
|
for tid, stack in sys._current_frames().items():
|
||||||
name = "{} ({:x})".format(names.get(tid), tid)
|
name = "%s (%x)" % (names.get(tid), tid)
|
||||||
threads[name] = stack
|
threads[name] = stack
|
||||||
|
|
||||||
rret: list[str] = []
|
rret: list[str] = []
|
||||||
bret: list[str] = []
|
bret: list[str] = []
|
||||||
for name, stack in sorted(threads.items()):
|
for name, stack in sorted(threads.items()):
|
||||||
ret = ["\n\n# {}".format(name)]
|
ret = ["\n\n# %s" % (name,)]
|
||||||
pad = None
|
pad = None
|
||||||
for fn, lno, name, line in traceback.extract_stack(stack):
|
for fn, lno, name, line in traceback.extract_stack(stack):
|
||||||
fn = os.sep.join(fn.split(os.sep)[-3:])
|
fn = os.sep.join(fn.split(os.sep)[-3:])
|
||||||
ret.append('File: "{}", line {}, in {}'.format(fn, lno, name))
|
ret.append('File: "%s", line %d, in %s' % (fn, lno, name))
|
||||||
if line:
|
if line:
|
||||||
ret.append(" " + str(line.strip()))
|
ret.append(" " + str(line.strip()))
|
||||||
if "self.not_empty.wait()" in line:
|
if "self.not_empty.wait()" in line:
|
||||||
|
@ -1133,7 +1133,7 @@ def alltrace() -> str:
|
||||||
if pad:
|
if pad:
|
||||||
bret += [ret[0]] + [pad + x for x in ret[1:]]
|
bret += [ret[0]] + [pad + x for x in ret[1:]]
|
||||||
else:
|
else:
|
||||||
rret += ret
|
rret.extend(ret)
|
||||||
|
|
||||||
return "\n".join(rret + bret) + "\n"
|
return "\n".join(rret + bret) + "\n"
|
||||||
|
|
||||||
|
@ -1229,9 +1229,9 @@ def vol_san(vols: list["VFS"], txt: bytes) -> bytes:
|
||||||
def min_ex(max_lines: int = 8, reverse: bool = False) -> str:
|
def min_ex(max_lines: int = 8, reverse: bool = False) -> str:
|
||||||
et, ev, tb = sys.exc_info()
|
et, ev, tb = sys.exc_info()
|
||||||
stb = traceback.extract_tb(tb)
|
stb = traceback.extract_tb(tb)
|
||||||
fmt = "{} @ {} <{}>: {}"
|
fmt = "%s @ %d <%s>: %s"
|
||||||
ex = [fmt.format(fp.split(os.sep)[-1], ln, fun, txt) for fp, ln, fun, txt in stb]
|
ex = [fmt % (fp.split(os.sep)[-1], ln, fun, txt) for fp, ln, fun, txt in stb]
|
||||||
ex.append("[{}] {}".format(et.__name__ if et else "(anonymous)", ev))
|
ex.append("[%s] %s" % (et.__name__ if et else "(anonymous)", ev))
|
||||||
return "\n".join(ex[-max_lines:][:: -1 if reverse else 1])
|
return "\n".join(ex[-max_lines:][:: -1 if reverse else 1])
|
||||||
|
|
||||||
|
|
||||||
|
@ -1282,7 +1282,7 @@ def ren_open(
|
||||||
with fun(fsenc(fpath), *args, **kwargs) as f:
|
with fun(fsenc(fpath), *args, **kwargs) as f:
|
||||||
if b64:
|
if b64:
|
||||||
assert fdir
|
assert fdir
|
||||||
fp2 = "fn-trunc.{}.txt".format(b64)
|
fp2 = "fn-trunc.%s.txt" % (b64,)
|
||||||
fp2 = os.path.join(fdir, fp2)
|
fp2 = os.path.join(fdir, fp2)
|
||||||
with open(fsenc(fp2), "wb") as f2:
|
with open(fsenc(fp2), "wb") as f2:
|
||||||
f2.write(orig_name.encode("utf-8"))
|
f2.write(orig_name.encode("utf-8"))
|
||||||
|
@ -1311,7 +1311,7 @@ def ren_open(
|
||||||
raise
|
raise
|
||||||
|
|
||||||
if not b64:
|
if not b64:
|
||||||
zs = "{}\n{}".format(orig_name, suffix).encode("utf-8", "replace")
|
zs = ("%s\n%s" % (orig_name, suffix)).encode("utf-8", "replace")
|
||||||
zs = hashlib.sha512(zs).digest()[:12]
|
zs = hashlib.sha512(zs).digest()[:12]
|
||||||
b64 = base64.urlsafe_b64encode(zs).decode("utf-8")
|
b64 = base64.urlsafe_b64encode(zs).decode("utf-8")
|
||||||
|
|
||||||
|
@ -1331,7 +1331,7 @@ def ren_open(
|
||||||
# okay do the first letter then
|
# okay do the first letter then
|
||||||
ext = "." + ext[2:]
|
ext = "." + ext[2:]
|
||||||
|
|
||||||
fname = "{}~{}{}".format(bname, b64, ext)
|
fname = "%s~%s%s" % (bname, b64, ext)
|
||||||
|
|
||||||
|
|
||||||
class MultipartParser(object):
|
class MultipartParser(object):
|
||||||
|
@ -1608,7 +1608,7 @@ def rand_name(fdir: str, fn: str, rnd: int) -> str:
|
||||||
break
|
break
|
||||||
|
|
||||||
nc = rnd + extra
|
nc = rnd + extra
|
||||||
nb = int((6 + 6 * nc) / 8)
|
nb = (6 + 6 * nc) // 8
|
||||||
zb = os.urandom(nb)
|
zb = os.urandom(nb)
|
||||||
zb = base64.urlsafe_b64encode(zb)
|
zb = base64.urlsafe_b64encode(zb)
|
||||||
fn = zb[:nc].decode("utf-8") + ext
|
fn = zb[:nc].decode("utf-8") + ext
|
||||||
|
@ -1711,7 +1711,7 @@ def get_spd(nbyte: int, t0: float, t: Optional[float] = None) -> str:
|
||||||
bps = nbyte / ((t - t0) + 0.001)
|
bps = nbyte / ((t - t0) + 0.001)
|
||||||
s1 = humansize(nbyte).replace(" ", "\033[33m").replace("iB", "")
|
s1 = humansize(nbyte).replace(" ", "\033[33m").replace("iB", "")
|
||||||
s2 = humansize(bps).replace(" ", "\033[35m").replace("iB", "")
|
s2 = humansize(bps).replace(" ", "\033[35m").replace("iB", "")
|
||||||
return "{} \033[0m{}/s\033[0m".format(s1, s2)
|
return "%s \033[0m%s/s\033[0m" % (s1, s2)
|
||||||
|
|
||||||
|
|
||||||
def s2hms(s: float, optional_h: bool = False) -> str:
|
def s2hms(s: float, optional_h: bool = False) -> str:
|
||||||
|
@ -1719,9 +1719,9 @@ def s2hms(s: float, optional_h: bool = False) -> str:
|
||||||
h, s = divmod(s, 3600)
|
h, s = divmod(s, 3600)
|
||||||
m, s = divmod(s, 60)
|
m, s = divmod(s, 60)
|
||||||
if not h and optional_h:
|
if not h and optional_h:
|
||||||
return "{}:{:02}".format(m, s)
|
return "%d:%02d" % (m, s)
|
||||||
|
|
||||||
return "{}:{:02}:{:02}".format(h, m, s)
|
return "%d:%02d:%02d" % (h, m, s)
|
||||||
|
|
||||||
|
|
||||||
def djoin(*paths: str) -> str:
|
def djoin(*paths: str) -> str:
|
||||||
|
@ -2191,7 +2191,7 @@ def read_socket_chunked(
|
||||||
raise Pebkac(400, t.format(x))
|
raise Pebkac(400, t.format(x))
|
||||||
|
|
||||||
if log:
|
if log:
|
||||||
log("receiving {} byte chunk".format(chunklen))
|
log("receiving %d byte chunk" % (chunklen,))
|
||||||
|
|
||||||
for chunk in read_socket(sr, chunklen):
|
for chunk in read_socket(sr, chunklen):
|
||||||
yield chunk
|
yield chunk
|
||||||
|
@ -2964,7 +2964,7 @@ def visual_length(txt: str) -> int:
|
||||||
pend = None
|
pend = None
|
||||||
else:
|
else:
|
||||||
if ch == "\033":
|
if ch == "\033":
|
||||||
pend = "{0}".format(ch)
|
pend = "%s" % (ch,)
|
||||||
else:
|
else:
|
||||||
co = ord(ch)
|
co = ord(ch)
|
||||||
# the safe parts of latin1 and cp437 (no greek stuff)
|
# the safe parts of latin1 and cp437 (no greek stuff)
|
||||||
|
|
|
@ -262,7 +262,7 @@ def unpack():
|
||||||
final = opj(top, name)
|
final = opj(top, name)
|
||||||
san = opj(final, "copyparty/up2k.py")
|
san = opj(final, "copyparty/up2k.py")
|
||||||
for suf in range(0, 9001):
|
for suf in range(0, 9001):
|
||||||
withpid = "{}.{}.{}".format(name, os.getpid(), suf)
|
withpid = "%s.%d.%s" % (name, os.getpid(), suf)
|
||||||
mine = opj(top, withpid)
|
mine = opj(top, withpid)
|
||||||
if not ofe(mine):
|
if not ofe(mine):
|
||||||
break
|
break
|
||||||
|
@ -285,8 +285,8 @@ def unpack():
|
||||||
|
|
||||||
ck = hashfile(tar)
|
ck = hashfile(tar)
|
||||||
if ck != CKSUM:
|
if ck != CKSUM:
|
||||||
t = "\n\nexpected {} ({} byte)\nobtained {} ({} byte)\nsfx corrupt"
|
t = "\n\nexpected %s (%d byte)\nobtained %s (%d byte)\nsfx corrupt"
|
||||||
raise Exception(t.format(CKSUM, SIZE, ck, sz))
|
raise Exception(t % (CKSUM, SIZE, ck, sz))
|
||||||
|
|
||||||
with tarfile.open(tar, "r:bz2") as tf:
|
with tarfile.open(tar, "r:bz2") as tf:
|
||||||
# this is safe against traversal
|
# this is safe against traversal
|
||||||
|
|
Loading…
Reference in a new issue