]> git.mxchange.org Git - fba.git/blobdiff - fba/federation/pleroma.py
WIP:
[fba.git] / fba / federation / pleroma.py
index a9345725e53f18768fdebeab4a24fe942d323f11..5e3bbf1c9ed6fa46b6f76d0143a5fc7caf0b7a0c 100644 (file)
@@ -24,38 +24,38 @@ from fba import instances
 
 def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
     # DEBUG: print(f"DEBUG: domain='{domain}',origin='{origin}',nodeinfo_url='{nodeinfo_url}' - CALLED!")
-    if type(domain) != str:
+    if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
     elif domain == "":
-        raise ValueError(f"Parameter 'domain' is empty")
-    elif type(origin) != str and origin != None:
+        raise ValueError("Parameter 'domain' is empty")
+    elif not isinstance(origin, str) and origin is not None:
         raise ValueError(f"Parameter origin[]={type(origin)} is not 'str'")
     elif origin == "":
-        raise ValueError(f"Parameter 'origin' is empty")
-    elif type(nodeinfo_url) != str:
+        raise ValueError("Parameter 'origin' is empty")
+    elif not isinstance(nodeinfo_url, str):
         raise ValueError(f"Parameter nodeinfo_url[]={type(nodeinfo_url)} is not 'str'")
     elif nodeinfo_url == "":
-        raise ValueError(f"Parameter 'nodeinfo_url' is empty")
+        raise ValueError("Parameter 'nodeinfo_url' is empty")
 
     try:
         # Blocks
         blockdict = list()
-        json = fba.fetch_nodeinfo(domain, nodeinfo_url)
+        rows = fba.fetch_nodeinfo(domain, nodeinfo_url)
 
-        if json is None:
+        if rows is None:
             print("WARNING: Could not fetch nodeinfo from domain:", domain)
             return
-        elif not "metadata" in json:
-            print(f"WARNING: json()={len(json)} does not have key 'metadata', domain='{domain}'")
+        elif not "metadata" in rows:
+            print(f"WARNING: rows()={len(rows)} does not have key 'metadata', domain='{domain}'")
             return
-        elif not "federation" in json["metadata"]:
-            print(f"WARNING: json()={len(json['metadata'])} does not have key 'federation', domain='{domain}'")
+        elif not "federation" in rows["metadata"]:
+            print(f"WARNING: rows()={len(rows['metadata'])} does not have key 'federation', domain='{domain}'")
             return
 
         # DEBUG: print("DEBUG: Updating nodeinfo:", domain)
         instances.update_last_nodeinfo(domain)
 
-        federation = json["metadata"]["federation"]
+        federation = rows["metadata"]["federation"]
 
         if "enabled" in federation:
             # DEBUG: print("DEBUG: Instance has no block list to analyze:", domain)
@@ -94,7 +94,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                         searchres = fba.cursor.fetchone()
                         # DEBUG: print("DEBUG: searchres[]:", type(searchres))
 
-                        if searchres == None:
+                        if searchres is None:
                             print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
                             continue
 
@@ -152,7 +152,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 for blocked, reason in info.items():
                     # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - BEFORE!")
                     blocked = fba.tidyup_domain(blocked)
-                    reason  = fba.tidyup_reason(reason) if reason != None else None
+                    reason  = fba.tidyup_reason(reason) if reason is not None and reason != "" else None
                     # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - AFTER!")
 
                     if blocked == "":
@@ -171,7 +171,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                         )
                         searchres = fba.cursor.fetchone()
 
-                        if searchres == None:
+                        if searchres is None:
                             print(f"WARNING: Cannot deobsfucate blocked='{blocked}' - SKIPPED!")
                             continue
 
@@ -187,14 +187,14 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                     # DEBUG: print("DEBUG: Updating block reason:", domain, blocked, reason["reason"])
                     blocks.update_reason(reason["reason"], domain, blocked, block_level)
 
-                    # DEBUG: print(f"DEBUG: blockdict()={count(blockdict)")
+                    # DEBUG: print(f"DEBUG: blockdict()={len(blockdict)}")
                     for entry in blockdict:
                         if entry["blocked"] == blocked:
                             # DEBUG: print("DEBUG: Updating entry reason:", blocked)
                             entry["reason"] = reason["reason"]
 
         fba.connection.commit()
-    except Exception as e:
-        print(f"ERROR: domain='{domain}',software='pleroma',exception[{type(e)}]:'{str(e)}'")
+    except BaseException as exception:
+        print(f"ERROR: domain='{domain}',software='pleroma',exception[{type(exception)}]:'{str(exception)}'")
 
     # DEBUG: print("DEBUG: EXIT!")