]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Sat, 9 Dec 2023 07:15:42 +0000 (08:15 +0100)
committerRoland Häder <roland@mxchange.org>
Sat, 9 Dec 2023 07:15:42 +0000 (08:15 +0100)
- combined None and "" (empty string) for lesser code
- added/improved debug messages
- got rid of one local variable, added another one ;-)

fba/http/nodeinfo.py
fba/networks/pleroma.py

index 9c944cda5f3cf880b5ed9650040d5a6b4bcd7ac4..5f78a44050e80e68d74586db23147f0b43119850 100644 (file)
@@ -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
 
index a78ead4736f343030510bedbeede5f087246f7ca..6ee00a6b83ab428f99f66dfcbbf5416484ec0cb3 100644 (file)
@@ -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)