From 894b133fbb956bddeb24c8c6ae6be6af563f4449 Mon Sep 17 00:00:00 2001 From: Justin Warren Date: Sat, 14 Jan 2023 10:43:17 +1100 Subject: [PATCH] str2bool() now converts '' to False. Added some extra debug logging of blocklist parsing. --- src/fediblockhole/blocklist_parser.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/fediblockhole/blocklist_parser.py b/src/fediblockhole/blocklist_parser.py index 38b0b59..d5d8394 100644 --- a/src/fediblockhole/blocklist_parser.py +++ b/src/fediblockhole/blocklist_parser.py @@ -97,9 +97,10 @@ class BlocklistParserCSV(BlocklistParser): origitem = blockitem.copy() for key in origitem: if key not in self.import_fields: + log.debug(f"ignoring field '{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 block = DomainBlock(**blockitem) if block.severity > self.max_severity: @@ -162,7 +163,7 @@ def str2bool(boolstring: str) -> bool: boolstring = boolstring.lower() if boolstring in ['true', 't', '1', 'y', 'yes']: return True - elif boolstring in ['false', 'f', '0', 'n', 'no']: + elif boolstring in ['', 'false', 'f', '0', 'n', 'no']: return False else: raise ValueError(f"Cannot parse value '{boolstring}' as boolean") @@ -183,4 +184,5 @@ def parse_blocklist( """Parse a blocklist in the given format """ parser = FORMAT_PARSERS[format](import_fields, max_severity) + log.debug(f"parsing {format} blocklist with import_fields: {import_fields}...") return parser.parse_blocklist(blockdata) \ No newline at end of file