From: Roland Häder Date: Sat, 9 Dec 2023 07:15:42 +0000 (+0100) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=6d9a882af7f49fd8038a19ad03a523b91b8e49e5;p=fba.git Continued: - combined None and "" (empty string) for lesser code - added/improved debug messages - got rid of one local variable, added another one ;-) --- diff --git a/fba/http/nodeinfo.py b/fba/http/nodeinfo.py index 9c944cd..5f78a44 100644 --- a/fba/http/nodeinfo.py +++ b/fba/http/nodeinfo.py @@ -207,7 +207,7 @@ def fetch_wellknown_nodeinfo(domain: str) -> dict: elif "href" not in link: logger.warning("link[rel]='%s' has no element 'href' - SKIPPED!", link["rel"]) continue - elif link["href"] is None or link["href"] == "": + elif link["href"] in [None, ""]: logger.debug("link[href]='%s',link[rel]='%s' - SKIPPED!", link["href"], link["rel"]) continue diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index a78ead4..6ee00a6 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -86,6 +86,7 @@ def fetch_blocks(domain: str) -> list: logger.warning("Exception '%s' during fetching nodeinfo from domain='%s'", type(exception), domain) instances.set_last_error(domain, exception) + logger.debug("rows[]='%s'", type(rows)) if rows is None: logger.warning("Could not fetch nodeinfo from domain='%s' - EXIT!", domain) return list() @@ -96,10 +97,10 @@ def fetch_blocks(domain: str) -> list: logger.warning("rows()=%d does not have key 'federation', domain='%s' - EXIT!", len(rows["metadata"]), domain) return list() - data = rows["metadata"]["federation"] found = False - + data = rows["metadata"]["federation"] logger.debug("data[]='%s'", type(data)) + if "mrf_simple" in data: logger.debug("Found mrf_simple in API response from domain='%s'", domain) found = True @@ -139,7 +140,7 @@ def fetch_blocks(domain: str) -> list: logger.debug("Invoking utils.deobfuscate(%s, %s) ...", blocked, domain) blocked = utils.deobfuscate(blocked, domain) - logger.debug("blocked='%s' - DEOBFUSCATED!", blocked) + logger.debug("blocked[%s]='%s' - DEOBFUSCATED!", type(blocked), blocked) if blocked in [None, ""]: logger.warning("instance[host]='%s' is None or empty after tidyup.domain() - SKIPPED!", instance["host"]) @@ -165,8 +166,8 @@ def fetch_blocks(domain: str) -> list: for blocked in data["quarantined_instances"]: logger.debug("blocked='%s' - BEFORE!", blocked) blocked = tidyup.domain(blocked) if blocked != "" else None - logger.debug("blocked='%s' - AFTER!", blocked) + if blocked in [None, ""]: logger.warning("blocked is empty after tidyup.domain(): domain='%s',block_level='%s'", domain, block_level) continue @@ -248,7 +249,7 @@ def fetch_blocks(domain: str) -> list: rows = data["quarantined_instances_info"]["quarantined_instances"] for blocked in rows: logger.debug("blocked='%s' - BEFORE!", blocked) - reason = tidyup.reason(rows[blocked]["reason"]) + reason = tidyup.reason(rows[blocked]["reason"]) if rows[blocked]["reason"] != "" else None blocked = tidyup.domain(blocked) if blocked != "" else None logger.debug("blocked='%s',reason='%s' - AFTER!", blocked, reason) @@ -276,11 +277,8 @@ def fetch_blocks(domain: str) -> list: if len(blocklist) > 0: logger.info("Checking %d different blocklist(s) ...", len(blocklist)) for block_level in blocklist: - logger.debug("block_level='%s'", block_level) - rows = blocklist[block_level] - - logger.debug("rows[%s]()=%d'", type(rows), len(rows)) - for block in rows: + logger.debug("Checking blocklist[%s]()=%d entries ...", block_level, blocklist[block_level]) + for block in blocklist[block_level]: logger.debug("Appending blocker='%s',block[blocked]='%s',block[reason]='%s',block_level='%s' ...",domain, block["blocked"], block["reason"], block_level) blockdict.append({ "blocker" : domain, @@ -378,14 +376,15 @@ def fetch_blocks_from_about(domain: str) -> dict: for line in header.find_next("table").find_all("tr")[1:]: logger.debug("line[]='%s'", type(line)) blocked = line.find_all("td")[0].text - logger.debug("blocked='%s'", blocked) + reason = line.find_all("td")[1].text + logger.debug("blocked='%s',reason='%s'", blocked, reason) blocked = tidyup.domain(blocked) if blocked != "" else None - reason = tidyup.reason(line.find_all("td")[1].text) + reason = tidyup.reason(reason) if reason != "" else None logger.debug("blocked='%s',reason='%s' - AFTER!", blocked, reason) - if blocked is None or blocked == "": - logger.debug("domain='%s',block_level='%s': blocked is empty - SKIPPED!", domain, block_level) + if blocked in [None, ""]: + logger.debug("domain='%s',block_level='%s': blocked='%s' is empty - SKIPPED!", domain, block_level, blocked) continue elif not domain_helper.is_wanted(blocked): logger.debug("blocked='%s' is not wanted - SKIPPED!", blocked)