str2bool() now converts '' to False.

Added some extra debug logging of blocklist parsing.
This commit is contained in:
Justin Warren 2023-01-14 10:43:17 +11:00
parent 9817c99e40
commit 894b133fbb
No known key found for this signature in database
1 changed files with 4 additions and 2 deletions

View File

@ -97,9 +97,10 @@ class BlocklistParserCSV(BlocklistParser):
origitem = blockitem.copy() origitem = blockitem.copy()
for key in origitem: for key in origitem:
if key not in self.import_fields: if key not in self.import_fields:
log.debug(f"ignoring field '{key}'")
del blockitem[key] del blockitem[key]
# Convert dict to NamedTuple with the double-star operator # Convert dict to DomainBlock with the double-star operator
# See: https://docs.python.org/3/tutorial/controlflow.html#tut-unpacking-arguments # See: https://docs.python.org/3/tutorial/controlflow.html#tut-unpacking-arguments
block = DomainBlock(**blockitem) block = DomainBlock(**blockitem)
if block.severity > self.max_severity: if block.severity > self.max_severity:
@ -162,7 +163,7 @@ def str2bool(boolstring: str) -> bool:
boolstring = boolstring.lower() boolstring = boolstring.lower()
if boolstring in ['true', 't', '1', 'y', 'yes']: if boolstring in ['true', 't', '1', 'y', 'yes']:
return True return True
elif boolstring in ['false', 'f', '0', 'n', 'no']: elif boolstring in ['', 'false', 'f', '0', 'n', 'no']:
return False return False
else: else:
raise ValueError(f"Cannot parse value '{boolstring}' as boolean") raise ValueError(f"Cannot parse value '{boolstring}' as boolean")
@ -183,4 +184,5 @@ def parse_blocklist(
"""Parse a blocklist in the given format """Parse a blocklist in the given format
""" """
parser = FORMAT_PARSERS[format](import_fields, max_severity) parser = FORMAT_PARSERS[format](import_fields, max_severity)
log.debug(f"parsing {format} blocklist with import_fields: {import_fields}...")
return parser.parse_blocklist(blockdata) return parser.parse_blocklist(blockdata)