From 4bda162e1bf04d1154fe5bdd8b588d9984c8e963 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sat, 11 May 2024 21:30:26 +0200 Subject: [PATCH] Continued: - fetch_blocks_from_about() does return a 2-dimensional array, not a flat one --- fba/networks/mastodon.py | 66 ++++++++++++++++++++-------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index 0f5953b..b0c2244 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -167,39 +167,39 @@ def fetch_blocks(domain: str) -> list: logger.debug("rows[%s]()=%d", type(rows), len(rows)) if len(rows) > 0: logger.debug("Checking %d entries from domain='%s' ...", len(rows), domain) - for block in rows: - # Check type - logger.debug("block[]='%s'", type(block)) - if not isinstance(block, dict): - logger.debug("block[]='%s' is of type 'dict' - SKIPPED!", type(block)) - continue - elif "domain" not in block: - logger.debug("block='%s'", block) - logger.warning("block()=%d does not contain element 'domain' - SKIPPED!", len(block)) - continue - elif not domain_helper.is_wanted(block["domain"]): - logger.debug("block[domain]='%s' is not wanted - SKIPPED!", block["domain"]) - continue - elif "severity" not in block: - logger.warning("block()=%d does not contain element 'severity' - SKIPPED!", len(block)) - continue - elif block["severity"] in ["accept", "accepted"]: - logger.debug("block[domain]='%s' has unwanted severity level '%s' - SKIPPED!", block["domain"], block["severity"]) - continue - elif "digest" in block and not validators.hashes.sha256(block["digest"]): - logger.warning("block[domain]='%s' has invalid block[digest]='%s' - SKIPPED!", block["domain"], block["digest"]) - continue - - reason = tidyup.reason(block["comment"]) if "comment" in block and block["comment"] is not None and block["comment"] != "" else None - - logger.debug("Appending blocker='%s',blocked='%s',reason='%s',block_level='%s' ...", domain, block["domain"], reason, block["severity"]) - blocklist.append({ - "blocker" : domain, - "blocked" : block["domain"], - "digest" : block["digest"] if "digest" in block else None, - "reason" : reason, - "block_level": blocks.alias_block_level(block["severity"]), - }) + for block_level in rows: + blocklists = rows[block_level] + + logger.debug("block_level='%s',blocklists()=%d", block_level, len(blocklists)) + for block in blocklists: + # Check type + if not isinstance(block, dict): + logger.debug("block[]='%s' is of type 'dict' - SKIPPED!", type(block)) + continue + elif "domain" not in block: + logger.debug("block='%s'", block) + logger.warning("block()=%d does not contain element 'domain' - SKIPPED!", len(block)) + continue + elif not domain_helper.is_wanted(block["domain"]): + logger.debug("block[domain]='%s' is not wanted - SKIPPED!", block["domain"]) + continue + elif block_level in ["accept", "accepted"]: + logger.debug("block[domain]='%s' has unwanted severity level '%s' - SKIPPED!", block["domain"], block_level) + continue + elif "digest" in block and not validators.hashes.sha256(block["digest"]): + logger.warning("block[domain]='%s' has invalid block[digest]='%s' - SKIPPED!", block["domain"], block["digest"]) + continue + + reason = tidyup.reason(block["reason"]) if "reason" in block and block["reason"] is not None and block["reason"] != "" else None + + logger.debug("Appending blocker='%s',blocked='%s',reason='%s',block_level='%s' ...", domain, block["domain"], reason, block_level) + blocklist.append({ + "blocker" : domain, + "blocked" : block["domain"], + "digest" : block["digest"] if "digest" in block else None, + "reason" : reason, + "block_level": blocks.alias_block_level(block_level), + }) else: logger.debug("domain='%s' has no block list", domain) -- 2.39.5