From: Roland Häder Date: Thu, 8 Jun 2023 19:18:54 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=94e4818fc707fe3f08ac84c3f3944552c8f57f99;p=fba.git Continued: - added missing check for reason != None - empty strings are now NoneType, too --- diff --git a/fba/commands.py b/fba/commands.py index 799d6db..f6706d5 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -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 == "": diff --git a/fba/federation/mastodon.py b/fba/federation/mastodon.py index 4752ca1..51f1473 100644 --- a/fba/federation/mastodon.py +++ b/fba/federation/mastodon.py @@ -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 == "": diff --git a/fba/federation/misskey.py b/fba/federation/misskey.py index 598e80e..325c528 100644 --- a/fba/federation/misskey.py +++ b/fba/federation/misskey.py @@ -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"] diff --git a/fba/federation/pleroma.py b/fba/federation/pleroma.py index a934572..06b7a4d 100644 --- a/fba/federation/pleroma.py +++ b/fba/federation/pleroma.py @@ -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 == "":