Contstrain argparse integers to permitted range

In many casese we used type=int permitting any integer value, positive
or negative without a constratint in size.  However, in reality often
we're constrained to unsigned 8 or 16 bit ranges.  Let's use the
auto_uint{8,16} functions to enforce this within argparse before
we even try to encode something that won't work.

Change-Id: I35c81230bc18e2174ec1930aa81463f03bcd69c8
This commit is contained in:
Harald Welte
2024-02-03 13:46:05 +01:00
parent a30ee17246
commit afd89ca36d
3 changed files with 20 additions and 17 deletions

View File

@@ -927,6 +927,9 @@ def auto_uint7(x):
def auto_uint8(x):
return _auto_uint(x, 255)
def auto_uint16(x):
return _auto_uint(x, 65535)
def expand_hex(hexstring, length):
"""Expand a given hexstring to a specified length by replacing "." or ".."
with a filler that is derived from the neighboring nibbles respective