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
# check this out
# hold my beer
assert ssl # type: ignore
assert ssl # type: ignore # !rm
ptn = re.compile(r"^OP_NO_(TLS|SSL)v")
sslver = terse_sslver(al.ssl_ver).split(",")
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:
assert ssl # type: ignore
assert ssl # type: ignore # !rm
ctx = ssl.create_default_context(ssl.Purpose.CLIENT_AUTH)
if al.ssl_ver:
ctx.options &= ~al.ssl_flags_en

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -479,7 +479,7 @@ class ThumbSrv(object):
if c == crops[-1]:
raise
assert img # type: ignore
assert img # type: ignore # !rm
img.write_to_file(tpath, Q=40)
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:
return None
assert sqlite3 # type: ignore
assert sqlite3 # type: ignore # !rm
db = sqlite3.connect(self.args.shr_db, timeout=2, check_same_thread=False)
cur = db.cursor()
@ -120,7 +120,7 @@ class U2idx(object):
if not HAVE_SQLITE3 or "e2d" not in vn.flags:
return None
assert sqlite3 # type: ignore
assert sqlite3 # type: ignore # !rm
ptop = vn.realpath
histpath = self.asrv.vfs.histtab.get(ptop)
@ -467,5 +467,5 @@ class U2idx(object):
return
if identifier == self.active_id:
assert self.active_cur
assert self.active_cur # !rm
self.active_cur.connection.interrupt()

View file

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

View file

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

View file

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