more cleanup

This commit is contained in:
ed 2022-06-08 01:05:35 +02:00
parent f4a3bbd237
commit 4e5a323c62
6 changed files with 39 additions and 32 deletions

View file

@ -32,7 +32,7 @@ try:
except: except:
HAVE_SSL = False HAVE_SSL = False
printed = "" printed = []
class RiceFormatter(argparse.HelpFormatter): class RiceFormatter(argparse.HelpFormatter):
@ -65,10 +65,8 @@ class Dodge11874(RiceFormatter):
def lprint(*a, **ka): def lprint(*a, **ka):
global printed
txt = " ".join(unicode(x) for x in a) + ka.get("end", "\n") txt = " ".join(unicode(x) for x in a) + ka.get("end", "\n")
printed += txt printed.append(txt)
if not VT100: if not VT100:
txt = ansi_re.sub("", txt) txt = ansi_re.sub("", txt)
@ -722,7 +720,7 @@ def main(argv=None):
# signal.signal(signal.SIGINT, sighandler) # signal.signal(signal.SIGINT, sighandler)
SvcHub(al, argv, printed).run() SvcHub(al, argv, "".join(printed)).run()
if __name__ == "__main__": if __name__ == "__main__":

View file

@ -160,12 +160,12 @@ class TcpSrv(object):
continue continue
if ln == ln.lstrip(): if ln == ln.lstrip():
dev = re.split(r'[: ]', ln)[0] dev = re.split(r"[: ]", ln)[0]
if "UP" in re.split(r'[<>, \t]', ln): if "UP" in re.split(r"[<>, \t]", ln):
up = True up = True
m = re.match(r'^\s+inet\s+([^ ]+)', ln) m = re.match(r"^\s+inet\s+([^ ]+)", ln)
if m: if m:
ip = m.group(1) ip = m.group(1)

View file

@ -9,7 +9,6 @@ import hashlib
import threading import threading
import subprocess as sp import subprocess as sp
from .__init__ import PY2, unicode
from .util import fsenc, vsplit, statdir, runcmd, Queue, Cooldown, BytesIO, min_ex from .util import fsenc, vsplit, statdir, runcmd, Queue, Cooldown, BytesIO, min_ex
from .bos import bos from .bos import bos
from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe from .mtag import HAVE_FFMPEG, HAVE_FFPROBE, ffprobe
@ -39,7 +38,7 @@ try:
pass pass
try: try:
import pillow_avif import pillow_avif # noqa: F401 # pylint: disable=unused-import
HAVE_AVIF = True HAVE_AVIF = True
except: except:
@ -398,7 +397,7 @@ class ThumbSrv(object):
def _run_ff(self, cmd): def _run_ff(self, cmd):
# self.log((b" ".join(cmd)).decode("utf-8")) # self.log((b" ".join(cmd)).decode("utf-8"))
ret, sout, serr = runcmd(cmd, timeout=self.args.th_convt) ret, _, serr = runcmd(cmd, timeout=self.args.th_convt)
if not ret: if not ret:
return return
@ -583,7 +582,7 @@ class ThumbSrv(object):
if age > maxage: if age > maxage:
with self.mutex: with self.mutex:
safe = True safe = True
for k in self.busy.keys(): for k in self.busy:
if k.lower().replace("\\", "/").startswith(cmp): if k.lower().replace("\\", "/").startswith(cmp):
safe = False safe = False
break break

View file

@ -38,6 +38,8 @@ class U2idx(object):
self.log("your python does not have sqlite3; searching will be disabled") self.log("your python does not have sqlite3; searching will be disabled")
return return
self.active_id = None
self.active_cur = None
self.cur = {} self.cur = {}
self.mem_cur = sqlite3.connect(":memory:") self.mem_cur = sqlite3.connect(":memory:")
self.mem_cur.execute(r"create table a (b text)") self.mem_cur.execute(r"create table a (b text)")

View file

@ -22,7 +22,6 @@ from .util import (
Queue, Queue,
ProgressPrinter, ProgressPrinter,
SYMTIME, SYMTIME,
fsdec,
fsenc, fsenc,
absreal, absreal,
sanitize_fn, sanitize_fn,
@ -948,7 +947,7 @@ class Up2k(object):
in_progress.pop(w) in_progress.pop(w)
n_done += 1 n_done += 1
for w in to_delete.keys(): for w in to_delete:
q = "delete from mt where w = ? and +k = 't:mtp'" q = "delete from mt where w = ? and +k = 't:mtp'"
cur.execute(q, (w,)) cur.execute(q, (w,))

View file

@ -21,16 +21,16 @@ import subprocess as sp # nosec
from datetime import datetime from datetime import datetime
from collections import Counter from collections import Counter
from .__init__ import PY2, WINDOWS, ANYWIN, VT100, unicode from .__init__ import PY2, WINDOWS, ANYWIN, VT100
from .stolen import surrogateescape from .stolen import surrogateescape
FAKE_MP = False FAKE_MP = False
try: try:
if FAKE_MP: if FAKE_MP:
import multiprocessing.dummy as mp # noqa: F401 import multiprocessing.dummy as mp # noqa: F401 # pylint: disable=unused-import
else: else:
import multiprocessing as mp # noqa: F401 import multiprocessing as mp # noqa: F401 # pylint: disable=unused-import
except ImportError: except ImportError:
# support jython # support jython
mp = None mp = None
@ -38,13 +38,13 @@ except ImportError:
if not PY2: if not PY2:
from urllib.parse import unquote_to_bytes as unquote from urllib.parse import unquote_to_bytes as unquote
from urllib.parse import quote_from_bytes as quote from urllib.parse import quote_from_bytes as quote
from queue import Queue from queue import Queue # pylint: disable=unused-import
from io import BytesIO from io import BytesIO # pylint: disable=unused-import
else: else:
from urllib import unquote # pylint: disable=no-name-in-module from urllib import unquote # pylint: disable=no-name-in-module
from urllib import quote # pylint: disable=no-name-in-module from urllib import quote # pylint: disable=no-name-in-module
from Queue import Queue # pylint: disable=import-error,no-name-in-module from Queue import Queue # pylint: disable=import-error,no-name-in-module
from StringIO import StringIO as BytesIO from StringIO import StringIO as BytesIO # pylint: disable=unused-import
try: try:
@ -114,6 +114,9 @@ MIMES = {
"m4a": "audio/mp4", "m4a": "audio/mp4",
"jpg": "image/jpeg", "jpg": "image/jpeg",
} }
def _add_mimes():
for ln in """text css html csv for ln in """text css html csv
application json wasm xml pdf rtf zip application json wasm xml pdf rtf zip
image webp jpeg png gif bmp image webp jpeg png gif bmp
@ -126,6 +129,9 @@ font woff woff2 otf ttf
MIMES[v] = "{}/{}".format(k, v) MIMES[v] = "{}/{}".format(k, v)
_add_mimes()
REKOBO_KEY = { REKOBO_KEY = {
v: ln.split(" ", 1)[0] v: ln.split(" ", 1)[0]
for ln in """ for ln in """
@ -175,8 +181,8 @@ class Cooldown(object):
now = time.time() now = time.time()
ret = False ret = False
v = self.hist.get(key, 0) pv = self.hist.get(key, 0)
if now - v > self.maxage: if now - pv > self.maxage:
self.hist[key] = now self.hist[key] = now
ret = True ret = True
@ -395,7 +401,7 @@ def nuprint(msg):
def rice_tid(): def rice_tid():
tid = threading.current_thread().ident tid = threading.current_thread().ident
c = sunpack(b"B" * 5, spack(b">Q", tid)[-5:]) c = sunpack(b"B" * 5, spack(b">Q", tid)[-5:])
return "".join("\033[1;37;48;5;{}m{:02x}".format(x, x) for x in c) + "\033[0m" return "".join("\033[1;37;48;5;{0}m{0:02x}".format(x) for x in c) + "\033[0m"
def trace(*args, **kwargs): def trace(*args, **kwargs):
@ -616,6 +622,9 @@ class MultipartParser(object):
r'^content-disposition:(?: *|.*; *)filename="(.*)"', re.IGNORECASE r'^content-disposition:(?: *|.*; *)filename="(.*)"', re.IGNORECASE
) )
self.boundary = None
self.gen = None
def _read_header(self): def _read_header(self):
""" """
returns [fieldname, filename] after eating a block of multipart headers returns [fieldname, filename] after eating a block of multipart headers
@ -1101,17 +1110,17 @@ def s3enc(mem_cur, rd, fn):
ret.append(v) ret.append(v)
except: except:
ret.append("//" + w8b64enc(v)) ret.append("//" + w8b64enc(v))
# self.log("mojien/{} [{}] {}".format(k, v, ret[-1][2:])) # self.log("mojien [{}] {}".format(v, ret[-1][2:]))
return tuple(ret) return tuple(ret)
def s3dec(rd, fn): def s3dec(rd, fn):
ret = [] ret = []
for k, v in [["d", rd], ["f", fn]]: for v in [rd, fn]:
if v.startswith("//"): if v.startswith("//"):
ret.append(w8b64dec(v[2:])) ret.append(w8b64dec(v[2:]))
# self.log("mojide/{} [{}] {}".format(k, ret[-1], v[2:])) # self.log("mojide [{}] {}".format(ret[-1], v[2:]))
else: else:
ret.append(v) ret.append(v)