throw ValueError when requesting unknown hash types

This commit is contained in:
Kevin Baensch 2024-11-25 11:03:34 +01:00
parent 69ecfce9ff
commit 7210a9d0b1
Signed by: derped
GPG key ID: C0F1D326C7626543

View file

@ -18,12 +18,14 @@ def resolve(fname: str, esum: Optional[str] = None, cstype: str = ""):
If neither is applicable it defaults to CRC32. If neither is applicable it defaults to CRC32.
""" """
cstype = cstype.upper() cstype = cstype.upper()
if cstype in CKTYPES: if cstype != "":
if esum is None and (match := CKTYPES[cstype].REGEX.search(fname)): if cstype in CKTYPES:
esum = match.group(0) if esum is None and (match := CKTYPES[cstype].REGEX.search(fname)):
return CKTYPES[cstype](), esum esum = match.group(0)
return CKTYPES[cstype](), esum
raise ValueError(f"Unknown checksum type: {cstype}")
for cstname, csclass in CKTYPES.items(): for csclass in CKTYPES.values():
if match := csclass.REGEX.search(fname): if match := csclass.REGEX.search(fname):
if esum is None: if esum is None:
esum = match.group(0) esum = match.group(0)