just moving some stuff around, not foreshadowing

This commit is contained in:
ed 2025-07-30 21:05:37 +00:00
parent 9d32564c68
commit 4f1eb89382
3 changed files with 22 additions and 16 deletions

View file

@ -53,13 +53,13 @@ from .util import (
PYFTPD_VER, PYFTPD_VER,
RAM_AVAIL, RAM_AVAIL,
RAM_TOTAL, RAM_TOTAL,
RE_ANSI,
SQLITE_VER, SQLITE_VER,
UNPLICATIONS, UNPLICATIONS,
URL_BUG, URL_BUG,
URL_PRJ, URL_PRJ,
Daemon, Daemon,
align_tab, align_tab,
ansi_re,
b64enc, b64enc,
dedent, dedent,
has_resource, has_resource,
@ -167,7 +167,7 @@ def lprint(*a: Any, **ka: Any) -> None:
txt: str = " ".join(unicode(x) for x in a) + eol txt: str = " ".join(unicode(x) for x in a) + eol
printed.append(txt) printed.append(txt)
if not VT100: if not VT100:
txt = ansi_re.sub("", txt) txt = RE_ANSI.sub("", txt)
print(txt, end="", **ka) print(txt, end="", **ka)

View file

@ -51,6 +51,7 @@ from .util import (
HAVE_PSUTIL, HAVE_PSUTIL,
HAVE_SQLITE3, HAVE_SQLITE3,
HAVE_ZMQ, HAVE_ZMQ,
RE_ANSI,
URL_BUG, URL_BUG,
UTC, UTC,
VERSIONS, VERSIONS,
@ -60,7 +61,6 @@ from .util import (
HMaccas, HMaccas,
ODict, ODict,
alltrace, alltrace,
ansi_re,
build_netmap, build_netmap,
expat_ver, expat_ver,
gzip, gzip,
@ -1409,9 +1409,9 @@ class SvcHub(object):
if self.no_ansi: if self.no_ansi:
fmt = "%s %-21s %s\n" fmt = "%s %-21s %s\n"
if "\033" in msg: if "\033" in msg:
msg = ansi_re.sub("", msg) msg = RE_ANSI.sub("", msg)
if "\033" in src: if "\033" in src:
src = ansi_re.sub("", src) src = RE_ANSI.sub("", src)
elif c: elif c:
if isinstance(c, int): if isinstance(c, int):
msg = "\033[3%sm%s\033[0m" % (c, msg) msg = "\033[3%sm%s\033[0m" % (c, msg)

View file

@ -243,7 +243,17 @@ except:
BITNESS = struct.calcsize("P") * 8 BITNESS = struct.calcsize("P") * 8
ansi_re = re.compile("\033\\[[^mK]*[mK]") RE_ANSI = re.compile("\033\\[[^mK]*[mK]")
RE_CTYPE = re.compile(r"^content-type: *([^; ]+)", re.IGNORECASE)
RE_CDISP = re.compile(r"^content-disposition: *([^; ]+)", re.IGNORECASE)
RE_CDISP_FIELD = re.compile(
r'^content-disposition:(?: *|.*; *)name="([^"]+)"', re.IGNORECASE
)
RE_CDISP_FILE = re.compile(
r'^content-disposition:(?: *|.*; *)filename="(.*)"', re.IGNORECASE
)
RE_MEMTOTAL = re.compile("^MemTotal:.* kB")
RE_MEMAVAIL = re.compile("^MemAvailable:.* kB")
BOS_SEP = ("%s" % (os.sep,)).encode("ascii") BOS_SEP = ("%s" % (os.sep,)).encode("ascii")
@ -488,11 +498,11 @@ def read_ram() -> tuple[float, float]:
with open("/proc/meminfo", "rb", 0x10000) as f: with open("/proc/meminfo", "rb", 0x10000) as f:
zsl = f.read(0x10000).decode("ascii", "replace").split("\n") zsl = f.read(0x10000).decode("ascii", "replace").split("\n")
p = re.compile("^MemTotal:.* kB") p = RE_MEMTOTAL
zs = next((x for x in zsl if p.match(x))) zs = next((x for x in zsl if p.match(x)))
a = int((int(zs.split()[1]) / 0x100000) * 100) / 100 a = int((int(zs.split()[1]) / 0x100000) * 100) / 100
p = re.compile("^MemAvailable:.* kB") p = RE_MEMAVAIL
zs = next((x for x in zsl if p.match(x))) zs = next((x for x in zsl if p.match(x)))
b = int((int(zs.split()[1]) / 0x100000) * 100) / 100 b = int((int(zs.split()[1]) / 0x100000) * 100) / 100
except: except:
@ -1698,14 +1708,10 @@ class MultipartParser(object):
self.args = args self.args = args
self.headers = http_headers self.headers = http_headers
self.re_ctype = re.compile(r"^content-type: *([^; ]+)", re.IGNORECASE) self.re_ctype = RE_CTYPE
self.re_cdisp = re.compile(r"^content-disposition: *([^; ]+)", re.IGNORECASE) self.re_cdisp = RE_CDISP
self.re_cdisp_field = re.compile( self.re_cdisp_field = RE_CDISP_FIELD
r'^content-disposition:(?: *|.*; *)name="([^"]+)"', re.IGNORECASE self.re_cdisp_file = RE_CDISP_FILE
)
self.re_cdisp_file = re.compile(
r'^content-disposition:(?: *|.*; *)filename="(.*)"', re.IGNORECASE
)
self.boundary = b"" self.boundary = b""
self.gen: Optional[ self.gen: Optional[