]> git.mxchange.org Git - fba.git/commitdiff
Continued:
authorRoland Häder <roland@mxchange.org>
Thu, 8 Jun 2023 19:18:54 +0000 (21:18 +0200)
committerRoland Häder <roland@mxchange.org>
Thu, 8 Jun 2023 19:20:35 +0000 (21:20 +0200)
- added missing check for reason != None
- empty strings are now NoneType, too

fba/commands.py
fba/federation/mastodon.py
fba/federation/misskey.py
fba/federation/pleroma.py

index 799d6db58161e041f2a4c192a96405d58a9c182b..f6706d5e8d7004b727e97295eba5457bc7e721e6 100644 (file)
@@ -175,7 +175,7 @@ def fetch_blocks(args: argparse.Namespace):
                         blocked, reason = block.values()
                         # 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 != None and reason != "" else None
                         # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - AFTER!")
 
                         if blocked == "":
index 4752ca1792d41815b74b89a39262e155f7b152ff..51f147380a4e91d184732b5db4a54eb4af94b7ca 100644 (file)
@@ -192,7 +192,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 blocked, blocked_hash, reason = block.values()
                 # DEBUG: print(f"DEBUG: blocked='{blocked}',blocked_hash='{blocked_hash}',reason='{reason}':")
                 blocked = fba.tidyup_domain(blocked)
-                reason  = fba.tidyup_reason(reason)
+                reason  = fba.tidyup_reason(reason) if reason != None and reason != "" else None
                 # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - AFTER!")
 
                 if blocked == "":
index 598e80e0edc8b9ea6f3ff8f8118ddb1d10aca371..325c5284d8e80138f345cd98e5041ba95fd3fc14 100644 (file)
@@ -108,13 +108,13 @@ def fetch_peers(domain: str) -> list:
     return peers
 
 def fetch_blocks(domain: str) -> dict:
-    print(f"DEBUG: domain='{domain}' - CALLED!")
+    # DEBUG: print(f"DEBUG: domain='{domain}' - CALLED!")
     if type(domain) != str:
         raise ValueError(f"Parameter domain[]={type(domain)} is not 'str'")
     elif domain == "":
         raise ValueError(f"Parameter 'domain' is empty")
 
-    print("DEBUG: Fetching misskey blocks from domain:", domain)
+    # DEBUG: print("DEBUG: Fetching misskey blocks from domain:", domain)
     blocklist = {
         "suspended": [],
         "blocked"  : []
@@ -127,9 +127,9 @@ def fetch_blocks(domain: str) -> dict:
         # instances page-by-page, since that troonware doesn't support
         # sending them all at once
         try:
-            print(f"DEBUG: Fetching offset='{offset}' from '{domain}' ...")
+            # DEBUG: print(f"DEBUG: Fetching offset='{offset}' from '{domain}' ...")
             if offset == 0:
-                print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+                # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
                 fetched = fba.post_json_api(domain, "/api/federation/instances", json.dumps({
                     "sort"     : "+pubAt",
                     "host"     : None,
@@ -139,7 +139,7 @@ def fetch_blocks(domain: str) -> dict:
                     "Origin": domain
                 })
             else:
-                print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+                # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
                 fetched = fba.post_json_api(domain, "/api/federation/instances", json.dumps({
                     "sort"     : "+pubAt",
                     "host"     : None,
@@ -150,15 +150,15 @@ def fetch_blocks(domain: str) -> dict:
                     "Origin": domain
                 })
 
-            print("DEBUG: fetched():", len(fetched))
+            # DEBUG: print("DEBUG: fetched():", len(fetched))
             if len(fetched) == 0:
-                print("DEBUG: Returned zero bytes, exiting loop:", domain)
+                # DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
                 break
             elif len(fetched) != config.get("misskey_limit"):
-                print(f"DEBUG: Fetched '{len(fetched)}' row(s) but expected: '{config.get('misskey_limit')}'")
+                # DEBUG: print(f"DEBUG: Fetched '{len(fetched)}' row(s) but expected: '{config.get('misskey_limit')}'")
                 offset = offset + (config.get("misskey_limit") - len(fetched))
             else:
-                print("DEBUG: Raising offset by step:", step)
+                # DEBUG: print("DEBUG: Raising offset by step:", step)
                 offset = offset + step
 
             count = 0
@@ -174,9 +174,9 @@ def fetch_blocks(domain: str) -> dict:
                         }
                     )
 
-            print(f"DEBUG: count={count}")
+            # DEBUG: print(f"DEBUG: count={count}")
             if count == 0:
-                print(f"DEBUG: API is no more returning new instances, aborting loop!")
+                # DEBUG: print(f"DEBUG: API is no more returning new instances, aborting loop!")
                 break
 
         except BaseException as e:
@@ -189,7 +189,7 @@ def fetch_blocks(domain: str) -> dict:
         # same shit, different asshole ("blocked" aka full suspend)
         try:
             if offset == 0:
-                print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+                # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
                 fetched = fba.post_json_api(domain, "/api/federation/instances", json.dumps({
                     "sort"   : "+pubAt",
                     "host"   : None,
@@ -199,7 +199,7 @@ def fetch_blocks(domain: str) -> dict:
                     "Origin": domain
                 })
             else:
-                print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
+                # DEBUG: print("DEBUG: Sending JSON API request to domain,step,offset:", domain, step, offset)
                 fetched = fba.post_json_api(domain, "/api/federation/instances", json.dumps({
                     "sort"   : "+pubAt",
                     "host"   : None,
@@ -210,15 +210,15 @@ def fetch_blocks(domain: str) -> dict:
                     "Origin": domain
                 })
 
-            print("DEBUG: fetched():", len(fetched))
+            # DEBUG: print("DEBUG: fetched():", len(fetched))
             if len(fetched) == 0:
-                print("DEBUG: Returned zero bytes, exiting loop:", domain)
+                # DEBUG: print("DEBUG: Returned zero bytes, exiting loop:", domain)
                 break
             elif len(fetched) != config.get("misskey_limit"):
-                print(f"DEBUG: Fetched '{len(fetched)}' row(s) but expected: '{config.get('misskey_limit')}'")
+                # DEBUG: print(f"DEBUG: Fetched '{len(fetched)}' row(s) but expected: '{config.get('misskey_limit')}'")
                 offset = offset + (config.get("misskey_limit") - len(fetched))
             else:
-                print("DEBUG: Raising offset by step:", step)
+                # DEBUG: print("DEBUG: Raising offset by step:", step)
                 offset = offset + step
 
             count = 0
@@ -231,9 +231,9 @@ def fetch_blocks(domain: str) -> dict:
                         "reason": None
                     })
 
-            print(f"DEBUG: count={count}")
+            # DEBUG: print(f"DEBUG: count={count}")
             if count == 0:
-                print(f"DEBUG: API is no more returning new instances, aborting loop!")
+                # DEBUG: print(f"DEBUG: API is no more returning new instances, aborting loop!")
                 break
 
         except BaseException as e:
@@ -242,10 +242,10 @@ def fetch_blocks(domain: str) -> dict:
             offset = 0
             break
 
-    print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
+    # DEBUG: print(f"DEBUG: Updating last_instance_fetch for domain='{domain}' ...")
     instances.update_last_instance_fetch(domain)
 
-    print(f"DEBUG: Returning for domain='{domain}',blocked()={len(blocklist['blocked'])},suspended()={len(blocklist['suspended'])}")
+    # DEBUG: print(f"DEBUG: Returning for domain='{domain}',blocked()={len(blocklist['blocked'])},suspended()={len(blocklist['suspended'])}")
     return {
         "reject"        : blocklist["blocked"],
         "followers_only": blocklist["suspended"]
index a9345725e53f18768fdebeab4a24fe942d323f11..06b7a4d869219875b5888392cfb4224d30e27102 100644 (file)
@@ -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 != None and reason != "" else None
                     # DEBUG: print(f"DEBUG: blocked='{blocked}',reason='{reason}' - AFTER!")
 
                     if blocked == "":