scripts: Adopted dat tweak in other scripts

This just makes dat behave similarly to Python's getattr, etc:

- dat("bogus")       -> raises ValueError
- dat("bogus", 1234) -> returns 1234

This replaces try_dat, which is easy to forget about when copy-pasting
between scripts.

Though all of this wouldn't be necessary if only we could catch
exceptions in expressions...
This commit is contained in:
Christopher Haster
2025-03-10 20:31:13 -05:00
parent e780fd40f7
commit c60301719a
5 changed files with 102 additions and 94 deletions

View File

@@ -1296,11 +1296,11 @@ def punescape(s, attrs=None):
f = m.group('format')
if f[-1] in 'dboxX':
if isinstance(v, str):
v = try_dat(v) or 0
v = dat(v, 0)
v = int(v)
elif f[-1] in 'fFeEgG':
if isinstance(v, str):
v = try_dat(v) or 0
v = dat(v, 0)
v = float(v)
else:
f = ('<' if '-' in f else '>') + f.replace('-', '')