strip dev-only asserts at build stage

This commit is contained in:
ed 2024-09-14 22:17:35 +00:00
parent 0527b59180
commit 2927bbb2d6
11 changed files with 62 additions and 58 deletions

View file

@ -351,7 +351,7 @@ def configure_ssl_ver(al: argparse.Namespace) -> None:
# oh man i love openssl # oh man i love openssl
# check this out # check this out
# hold my beer # hold my beer
assert ssl # type: ignore assert ssl # type: ignore # !rm
ptn = re.compile(r"^OP_NO_(TLS|SSL)v") ptn = re.compile(r"^OP_NO_(TLS|SSL)v")
sslver = terse_sslver(al.ssl_ver).split(",") sslver = terse_sslver(al.ssl_ver).split(",")
flags = [k for k in ssl.__dict__ if ptn.match(k)] flags = [k for k in ssl.__dict__ if ptn.match(k)]
@ -385,7 +385,7 @@ def configure_ssl_ver(al: argparse.Namespace) -> None:
def configure_ssl_ciphers(al: argparse.Namespace) -> None: def configure_ssl_ciphers(al: argparse.Namespace) -> None:
assert ssl # type: ignore assert ssl # type: ignore # !rm
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH) ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
if al.ssl_ver: if al.ssl_ver:
ctx.options &= ~al.ssl_flags_en ctx.options &= ~al.ssl_flags_en

View file

@ -119,7 +119,7 @@ class Fstab(object):
self.srctab = srctab self.srctab = srctab
def relabel(self, path: str, nval: str) -> None: def relabel(self, path: str, nval: str) -> None:
assert self.tab assert self.tab # !rm
self.cache = {} self.cache = {}
if ANYWIN: if ANYWIN:
path = self._winpath(path) path = self._winpath(path)
@ -156,7 +156,7 @@ class Fstab(object):
self.log("failed to build tab:\n{}".format(min_ex()), 3) self.log("failed to build tab:\n{}".format(min_ex()), 3)
self.build_fallback() self.build_fallback()
assert self.tab assert self.tab # !rm
ret = self.tab._find(path)[0] ret = self.tab._find(path)[0]
if self.trusted or path == ret.vpath: if self.trusted or path == ret.vpath:
return ret.realpath.split("/")[0] return ret.realpath.split("/")[0]
@ -167,6 +167,6 @@ class Fstab(object):
if not self.tab: if not self.tab:
self.build_fallback() self.build_fallback()
assert self.tab assert self.tab # !rm
ret = self.tab._find(path)[0] ret = self.tab._find(path)[0]
return ret.realpath return ret.realpath

View file

@ -128,7 +128,7 @@ class HttpCli(object):
""" """
def __init__(self, conn: "HttpConn") -> None: def __init__(self, conn: "HttpConn") -> None:
assert conn.sr assert conn.sr # !rm
self.t0 = time.time() self.t0 = time.time()
self.conn = conn self.conn = conn
@ -1396,7 +1396,7 @@ class HttpCli(object):
xroot = mkenod("D:orz") xroot = mkenod("D:orz")
xroot.insert(0, parse_xml(txt)) xroot.insert(0, parse_xml(txt))
xprop = xroot.find(r"./{DAV:}propertyupdate/{DAV:}set/{DAV:}prop") xprop = xroot.find(r"./{DAV:}propertyupdate/{DAV:}set/{DAV:}prop")
assert xprop assert xprop # !rm
for ze in xprop: for ze in xprop:
ze.clear() ze.clear()
@ -1404,12 +1404,12 @@ class HttpCli(object):
xroot = parse_xml(txt) xroot = parse_xml(txt)
el = xroot.find(r"./{DAV:}response") el = xroot.find(r"./{DAV:}response")
assert el assert el # !rm
e2 = mktnod("D:href", quotep(self.args.SRS + self.vpath)) e2 = mktnod("D:href", quotep(self.args.SRS + self.vpath))
el.insert(0, e2) el.insert(0, e2)
el = xroot.find(r"./{DAV:}response/{DAV:}propstat") el = xroot.find(r"./{DAV:}response/{DAV:}propstat")
assert el assert el # !rm
el.insert(0, xprop) el.insert(0, xprop)
ret = '<?xml version="1.0" encoding="{}"?>\n'.format(uenc) ret = '<?xml version="1.0" encoding="{}"?>\n'.format(uenc)
@ -1793,7 +1793,7 @@ class HttpCli(object):
fn = os.devnull fn = os.devnull
params.update(open_ka) params.update(open_ka)
assert fn assert fn # !rm
if not self.args.nw: if not self.args.nw:
if rnd: if rnd:
@ -2102,7 +2102,7 @@ class HttpCli(object):
raise Pebkac(422, 'invalid action "{}"'.format(act)) raise Pebkac(422, 'invalid action "{}"'.format(act))
def handle_zip_post(self) -> bool: def handle_zip_post(self) -> bool:
assert self.parser assert self.parser # !rm
try: try:
k = next(x for x in self.uparam if x in ("zip", "tar")) k = next(x for x in self.uparam if x in ("zip", "tar"))
except: except:
@ -2430,7 +2430,7 @@ class HttpCli(object):
return True return True
def handle_chpw(self) -> bool: def handle_chpw(self) -> bool:
assert self.parser assert self.parser # !rm
pwd = self.parser.require("pw", 64) pwd = self.parser.require("pw", 64)
self.parser.drop() self.parser.drop()
@ -2447,7 +2447,7 @@ class HttpCli(object):
return True return True
def handle_login(self) -> bool: def handle_login(self) -> bool:
assert self.parser assert self.parser # !rm
pwd = self.parser.require("cppwd", 64) pwd = self.parser.require("cppwd", 64)
try: try:
uhash = self.parser.require("uhash", 256) uhash = self.parser.require("uhash", 256)
@ -2475,7 +2475,7 @@ class HttpCli(object):
return True return True
def handle_logout(self) -> bool: def handle_logout(self) -> bool:
assert self.parser assert self.parser # !rm
self.parser.drop() self.parser.drop()
self.log("logout " + self.uname) self.log("logout " + self.uname)
@ -2529,7 +2529,7 @@ class HttpCli(object):
return dur > 0, msg return dur > 0, msg
def handle_mkdir(self) -> bool: def handle_mkdir(self) -> bool:
assert self.parser assert self.parser # !rm
new_dir = self.parser.require("name", 512) new_dir = self.parser.require("name", 512)
self.parser.drop() self.parser.drop()
@ -2575,7 +2575,7 @@ class HttpCli(object):
return True return True
def handle_new_md(self) -> bool: def handle_new_md(self) -> bool:
assert self.parser assert self.parser # !rm
new_file = self.parser.require("name", 512) new_file = self.parser.require("name", 512)
self.parser.drop() self.parser.drop()
@ -2983,7 +2983,7 @@ class HttpCli(object):
return True return True
def handle_text_upload(self) -> bool: def handle_text_upload(self) -> bool:
assert self.parser assert self.parser # !rm
try: try:
cli_lastmod3 = int(self.parser.require("lastmod", 16)) cli_lastmod3 = int(self.parser.require("lastmod", 16))
except: except:
@ -3068,7 +3068,7 @@ class HttpCli(object):
pass pass
wrename(self.log, fp, os.path.join(mdir, ".hist", mfile2), vfs.flags) wrename(self.log, fp, os.path.join(mdir, ".hist", mfile2), vfs.flags)
assert self.parser.gen assert self.parser.gen # !rm
p_field, _, p_data = next(self.parser.gen) p_field, _, p_data = next(self.parser.gen)
if p_field != "body": if p_field != "body":
raise Pebkac(400, "expected body, got {}".format(p_field)) raise Pebkac(400, "expected body, got {}".format(p_field))
@ -3169,7 +3169,7 @@ class HttpCli(object):
# some browser append "; length=573" # some browser append "; length=573"
cli_lastmod = cli_lastmod.split(";")[0].strip() cli_lastmod = cli_lastmod.split(";")[0].strip()
cli_dt = parsedate(cli_lastmod) cli_dt = parsedate(cli_lastmod)
assert cli_dt assert cli_dt # !rm
cli_ts = calendar.timegm(cli_dt) cli_ts = calendar.timegm(cli_dt)
return file_lastmod, int(file_ts) > int(cli_ts) return file_lastmod, int(file_ts) > int(cli_ts)
except Exception as ex: except Exception as ex:

View file

@ -190,7 +190,7 @@ class HttpConn(object):
if self.args.ssl_dbg and hasattr(self.s, "shared_ciphers"): if self.args.ssl_dbg and hasattr(self.s, "shared_ciphers"):
ciphers = self.s.shared_ciphers() ciphers = self.s.shared_ciphers()
assert ciphers assert ciphers # !rm
overlap = [str(y[::-1]) for y in ciphers] overlap = [str(y[::-1]) for y in ciphers]
self.log("TLS cipher overlap:" + "\n".join(overlap)) self.log("TLS cipher overlap:" + "\n".join(overlap))
for k, v in [ for k, v in [

View file

@ -237,7 +237,7 @@ class HttpSrv(object):
if self.args.log_htp: if self.args.log_htp:
self.log(self.name, "workers -= {} = {}".format(n, self.tp_nthr), 6) self.log(self.name, "workers -= {} = {}".format(n, self.tp_nthr), 6)
assert self.tp_q assert self.tp_q # !rm
for _ in range(n): for _ in range(n):
self.tp_q.put(None) self.tp_q.put(None)
@ -431,7 +431,7 @@ class HttpSrv(object):
) )
def thr_poolw(self) -> None: def thr_poolw(self) -> None:
assert self.tp_q assert self.tp_q # !rm
while True: while True:
task = self.tp_q.get() task = self.tp_q.get()
if not task: if not task:

View file

@ -419,8 +419,8 @@ class SvcHub(object):
r"insert into kv values ('sver', 1)", r"insert into kv values ('sver', 1)",
] ]
assert db # type: ignore assert db # type: ignore # !rm
assert cur # type: ignore assert cur # type: ignore # !rm
if create: if create:
for cmd in sch: for cmd in sch:
cur.execute(cmd) cur.execute(cmd)
@ -488,8 +488,8 @@ class SvcHub(object):
r"create index sh_t1 on sh(t1)", r"create index sh_t1 on sh(t1)",
] ]
assert db # type: ignore assert db # type: ignore # !rm
assert cur # type: ignore assert cur # type: ignore # !rm
if create: if create:
dver = 2 dver = 2
modified = True modified = True

View file

@ -479,7 +479,7 @@ class ThumbSrv(object):
if c == crops[-1]: if c == crops[-1]:
raise raise
assert img # type: ignore assert img # type: ignore # !rm
img.write_to_file(tpath, Q=40) img.write_to_file(tpath, Q=40)
def conv_ffmpeg(self, abspath: str, tpath: str, fmt: str, vn: VFS) -> None: def conv_ffmpeg(self, abspath: str, tpath: str, fmt: str, vn: VFS) -> None:

View file

@ -104,7 +104,7 @@ class U2idx(object):
if not HAVE_SQLITE3 or not self.args.shr: if not HAVE_SQLITE3 or not self.args.shr:
return None return None
assert sqlite3 # type: ignore assert sqlite3 # type: ignore # !rm
db = sqlite3.connect(self.args.shr_db, timeout=2, check_same_thread=False) db = sqlite3.connect(self.args.shr_db, timeout=2, check_same_thread=False)
cur = db.cursor() cur = db.cursor()
@ -120,7 +120,7 @@ class U2idx(object):
if not HAVE_SQLITE3 or "e2d" not in vn.flags: if not HAVE_SQLITE3 or "e2d" not in vn.flags:
return None return None
assert sqlite3 # type: ignore assert sqlite3 # type: ignore # !rm
ptop = vn.realpath ptop = vn.realpath
histpath = self.asrv.vfs.histtab.get(ptop) histpath = self.asrv.vfs.histtab.get(ptop)
@ -467,5 +467,5 @@ class U2idx(object):
return return
if identifier == self.active_id: if identifier == self.active_id:
assert self.active_cur assert self.active_cur # !rm
self.active_cur.connection.interrupt() self.active_cur.connection.interrupt()

View file

@ -612,7 +612,7 @@ class Up2k(object):
return timeout return timeout
def _check_shares(self) -> float: def _check_shares(self) -> float:
assert sqlite3 # type: ignore assert sqlite3 # type: ignore # !rm
now = time.time() now = time.time()
timeout = now + 9001 timeout = now + 9001
@ -933,7 +933,7 @@ class Up2k(object):
with self.mutex, self.reg_mutex: with self.mutex, self.reg_mutex:
reg = self.register_vpath(vol.realpath, vol.flags) reg = self.register_vpath(vol.realpath, vol.flags)
assert reg assert reg # !rm
cur, _ = reg cur, _ = reg
with self.mutex: with self.mutex:
cur.connection.commit() cur.connection.commit()
@ -950,7 +950,7 @@ class Up2k(object):
reg = self.register_vpath(vol.realpath, vol.flags) reg = self.register_vpath(vol.realpath, vol.flags)
try: try:
assert reg assert reg # !rm
cur, db_path = reg cur, db_path = reg
if bos.path.getsize(db_path + "-wal") < 1024 * 1024 * 5: if bos.path.getsize(db_path + "-wal") < 1024 * 1024 * 5:
continue continue
@ -1185,7 +1185,7 @@ class Up2k(object):
with self.reg_mutex: with self.reg_mutex:
reg = self.register_vpath(top, vol.flags) reg = self.register_vpath(top, vol.flags)
assert reg and self.pp assert reg and self.pp # !rm
cur, db_path = reg cur, db_path = reg
db = Dbw(cur, 0, time.time()) db = Dbw(cur, 0, time.time())
@ -1306,7 +1306,7 @@ class Up2k(object):
th_cvd = self.args.th_coversd th_cvd = self.args.th_coversd
th_cvds = self.args.th_coversd_set th_cvds = self.args.th_coversd_set
assert self.pp and self.mem_cur assert self.pp and self.mem_cur # !rm
self.pp.msg = "a%d %s" % (self.pp.n, cdir) self.pp.msg = "a%d %s" % (self.pp.n, cdir)
rd = cdir[len(top) :].strip("/") rd = cdir[len(top) :].strip("/")
@ -1547,7 +1547,7 @@ class Up2k(object):
if n: if n:
t = "forgetting {} shadowed autoindexed files in [{}] > [{}]" t = "forgetting {} shadowed autoindexed files in [{}] > [{}]"
self.log(t.format(n, top, sh_rd)) self.log(t.format(n, top, sh_rd))
assert sh_erd # type: ignore assert sh_erd # type: ignore # !rm
q = "delete from dh where (d = ? or d like ?||'%')" q = "delete from dh where (d = ? or d like ?||'%')"
db.c.execute(q, (sh_erd, sh_erd + "/")) db.c.execute(q, (sh_erd, sh_erd + "/"))
@ -2266,7 +2266,7 @@ class Up2k(object):
# mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor # mp.pool.ThreadPool and concurrent.futures.ThreadPoolExecutor
# both do crazy runahead so lets reinvent another wheel # both do crazy runahead so lets reinvent another wheel
nw = max(1, self.args.mtag_mt) nw = max(1, self.args.mtag_mt)
assert self.mtag assert self.mtag # !rm
if not self.mpool_used: if not self.mpool_used:
self.mpool_used = True self.mpool_used = True
self.log("using {}x {}".format(nw, self.mtag.backend)) self.log("using {}x {}".format(nw, self.mtag.backend))
@ -2340,7 +2340,7 @@ class Up2k(object):
at: float, at: float,
) -> int: ) -> int:
"""will mutex(main)""" """will mutex(main)"""
assert self.mtag assert self.mtag # !rm
try: try:
st = bos.stat(abspath) st = bos.stat(abspath)
@ -2372,7 +2372,7 @@ class Up2k(object):
tags: dict[str, Union[str, float]], tags: dict[str, Union[str, float]],
) -> int: ) -> int:
"""mutex(main) me""" """mutex(main) me"""
assert self.mtag assert self.mtag # !rm
if not bos.path.isfile(abspath): if not bos.path.isfile(abspath):
return 0 return 0
@ -2842,7 +2842,7 @@ class Up2k(object):
c2 = cur c2 = cur
assert c2 assert c2 # !rm
c2.connection.commit() c2.connection.commit()
cur = jcur cur = jcur
@ -3308,7 +3308,7 @@ class Up2k(object):
t = "that chunk is already being written to:\n {}\n {} {}/{}\n {}" t = "that chunk is already being written to:\n {}\n {} {}/{}\n {}"
raise Pebkac(400, t.format(wark, chash, idx, nh, job["name"])) raise Pebkac(400, t.format(wark, chash, idx, nh, job["name"]))
assert chash # type: ignore assert chash # type: ignore # !rm
chunksize = up2k_chunksize(job["size"]) chunksize = up2k_chunksize(job["size"])
coffsets = [] coffsets = []
@ -3532,7 +3532,7 @@ class Up2k(object):
cur.connection.commit() cur.connection.commit()
except Exception as ex: except Exception as ex:
x = self.register_vpath(ptop, {}) x = self.register_vpath(ptop, {})
assert x assert x # !rm
db_ex_chk(self.log, ex, x[1]) db_ex_chk(self.log, ex, x[1])
raise raise
@ -3547,7 +3547,7 @@ class Up2k(object):
try: try:
r = db.execute(sql, (rd, fn)) r = db.execute(sql, (rd, fn))
except: except:
assert self.mem_cur assert self.mem_cur # !rm
r = db.execute(sql, s3enc(self.mem_cur, rd, fn)) r = db.execute(sql, s3enc(self.mem_cur, rd, fn))
if r.rowcount: if r.rowcount:
@ -3585,7 +3585,7 @@ class Up2k(object):
try: try:
db.execute(sql, v) db.execute(sql, v)
except: except:
assert self.mem_cur assert self.mem_cur # !rm
rd, fn = s3enc(self.mem_cur, rd, fn) rd, fn = s3enc(self.mem_cur, rd, fn)
v = (wark, int(ts), sz, rd, fn, db_ip, int(at or 0)) v = (wark, int(ts), sz, rd, fn, db_ip, int(at or 0))
db.execute(sql, v) db.execute(sql, v)
@ -3633,7 +3633,7 @@ class Up2k(object):
try: try:
db.execute(q, (cd, wark[:16], rd, fn)) db.execute(q, (cd, wark[:16], rd, fn))
except: except:
assert self.mem_cur assert self.mem_cur # !rm
rd, fn = s3enc(self.mem_cur, rd, fn) rd, fn = s3enc(self.mem_cur, rd, fn)
db.execute(q, (cd, wark[:16], rd, fn)) db.execute(q, (cd, wark[:16], rd, fn))
@ -4050,7 +4050,7 @@ class Up2k(object):
has_dupes = False has_dupes = False
if w: if w:
assert c1 assert c1 # !rm
if c2 and c2 != c1: if c2 and c2 != c1:
self._copy_tags(c1, c2, w) self._copy_tags(c1, c2, w)
@ -4188,7 +4188,7 @@ class Up2k(object):
try: try:
c = cur.execute(q, (rd, fn)) c = cur.execute(q, (rd, fn))
except: except:
assert self.mem_cur assert self.mem_cur # !rm
c = cur.execute(q, s3enc(self.mem_cur, rd, fn)) c = cur.execute(q, s3enc(self.mem_cur, rd, fn))
hit = c.fetchone() hit = c.fetchone()

View file

@ -440,7 +440,7 @@ def py_desc() -> str:
def _sqlite_ver() -> str: def _sqlite_ver() -> str:
assert sqlite3 # type: ignore assert sqlite3 # type: ignore # !rm
try: try:
co = sqlite3.connect(":memory:") co = sqlite3.connect(":memory:")
cur = co.cursor() cur = co.cursor()
@ -1030,7 +1030,7 @@ class MTHash(object):
if self.stop: if self.stop:
return nch, "", ofs0, chunk_sz return nch, "", ofs0, chunk_sz
assert f assert f # !rm
hashobj = hashlib.sha512() hashobj = hashlib.sha512()
while chunk_rem > 0: while chunk_rem > 0:
with self.imutex: with self.imutex:
@ -1448,7 +1448,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 # !rm
fp2 = "fn-trunc.%s.txt" % (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:
@ -1713,7 +1713,7 @@ class MultipartParser(object):
returns the value of the next field in the multipart body, returns the value of the next field in the multipart body,
raises if the field name is not as expected raises if the field name is not as expected
""" """
assert self.gen assert self.gen # !rm
p_field, p_fname, p_data = next(self.gen) p_field, p_fname, p_data = next(self.gen)
if p_field != field_name: if p_field != field_name:
raise WrongPostKey(field_name, p_field, p_fname, p_data) raise WrongPostKey(field_name, p_field, p_fname, p_data)
@ -1722,7 +1722,7 @@ class MultipartParser(object):
def drop(self) -> None: def drop(self) -> None:
"""discards the remaining multipart body""" """discards the remaining multipart body"""
assert self.gen assert self.gen # !rm
for _, _, data in self.gen: for _, _, data in self.gen:
for _ in data: for _ in data:
pass pass
@ -1815,7 +1815,7 @@ def gen_filekey_dbg(
) -> str: ) -> str:
ret = gen_filekey(alg, salt, fspath, fsize, inode) ret = gen_filekey(alg, salt, fspath, fsize, inode)
assert log_ptn assert log_ptn # !rm
if log_ptn.search(fspath): if log_ptn.search(fspath):
try: try:
import inspect import inspect
@ -2401,7 +2401,7 @@ def wunlink(log: "NamedLogger", abspath: str, flags: dict[str, Any]) -> bool:
def get_df(abspath: str) -> tuple[Optional[int], Optional[int]]: def get_df(abspath: str) -> tuple[Optional[int], Optional[int]]:
try: try:
# some fuses misbehave # some fuses misbehave
assert ctypes assert ctypes # type: ignore # !rm
if ANYWIN: if ANYWIN:
bfree = ctypes.c_ulonglong(0) bfree = ctypes.c_ulonglong(0)
ctypes.windll.kernel32.GetDiskFreeSpaceExW( # type: ignore ctypes.windll.kernel32.GetDiskFreeSpaceExW( # type: ignore
@ -2860,7 +2860,7 @@ def getalive(pids: list[int], pgid: int) -> list[int]:
alive.append(pid) alive.append(pid)
else: else:
# windows doesn't have pgroups; assume # windows doesn't have pgroups; assume
assert psutil assert psutil # type: ignore # !rm
psutil.Process(pid) psutil.Process(pid)
alive.append(pid) alive.append(pid)
except: except:
@ -2878,7 +2878,7 @@ def killtree(root: int) -> None:
pgid = 0 pgid = 0
if HAVE_PSUTIL: if HAVE_PSUTIL:
assert psutil assert psutil # type: ignore # !rm
pids = [root] pids = [root]
parent = psutil.Process(root) parent = psutil.Process(root)
for child in parent.children(recursive=True): for child in parent.children(recursive=True):
@ -3291,7 +3291,7 @@ def runhook(
at: float, at: float,
txt: str, txt: str,
) -> dict[str, Any]: ) -> dict[str, Any]:
assert broker or up2k assert broker or up2k # !rm
asrv = (broker or up2k).asrv asrv = (broker or up2k).asrv
args = (broker or up2k).args args = (broker or up2k).args
vp = vp.replace("\\", "/") vp = vp.replace("\\", "/")
@ -3485,7 +3485,7 @@ def termsize() -> tuple[int, int]:
def hidedir(dp) -> None: def hidedir(dp) -> None:
if ANYWIN: if ANYWIN:
try: try:
assert ctypes assert ctypes # type: ignore # !rm
k32 = ctypes.WinDLL("kernel32") k32 = ctypes.WinDLL("kernel32")
attrs = k32.GetFileAttributesW(dp) attrs = k32.GetFileAttributesW(dp)
if attrs >= 0: if attrs >= 0:

View file

@ -70,6 +70,10 @@ def uh2(fp):
continue continue
on = True on = True
if " # !rm" in ln:
continue
lns.append(ln) lns.append(ln)
cs = "\n".join(lns) cs = "\n".join(lns)