From 68b5c81b73edd146625fba6b867ffe3e0b19a4bf Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Sun, 12 Jan 2025 23:27:20 +0100 Subject: [PATCH] Continued: - renamed obfuscation.is_added() to has() to streamline naming functions in model modules --- fba/commands.py | 8 ++++---- fba/models/obfuscation.py | 8 ++++---- fba/networks/pleroma.py | 3 +-- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 81ac728..88f6e2c 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -392,7 +392,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: if records is None: logger.warning("Cannot deobfuscate block[blocked]='%s',row[domain]='%s',row[software]='%s' - SKIPPED!", block["blocked"], row["domain"], row["software"]) - if not obfuscation.is_added(block["blocked"]): + if not obfuscation.has(block["blocked"]): logger.debug("Invoking obfuscation.add(%s) ...", block["blocked"]) obfuscation.add(block["blocked"]) else: @@ -417,7 +417,7 @@ def fetch_blocks(args: argparse.Namespace) -> int: if records is None: logger.warning("Cannot deobfuscate block[blocked]='%s',row[domain]='%s',row[software]='%s' - SKIPPED!", block["blocked"], row["domain"], row["software"]) - if not obfuscation.is_added(block["blocked"]): + if not obfuscation.has(block["blocked"]): logger.debug("Invoking obfuscation.add(%s) ...", block["blocked"]) obfuscation.add(block["blocked"]) else: @@ -1455,7 +1455,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: elif blocks.is_instance_blocked(row["domain"], blocked): logger.debug("blocked='%s' is already blocked by domain='%s' - SKIPPED!", blocked, row["domain"]) continue - elif obfuscation.is_added(block["blocked"]): + elif obfuscation.has(block["blocked"]): logger.debug("Deleting deobfuscated pattern block[blocked]='%s' ...", block["blocked"]) obfuscation.delete(block["blocked"]) @@ -1471,7 +1471,7 @@ def recheck_obfuscation(args: argparse.Namespace) -> int: }) elif blocked is not None: logger.debug("blocked='%s' is maybe added and needs update.", blocked) - if not obfuscation.is_added(block["blocked"]): + if not obfuscation.has(block["blocked"]): logger.debug("Invoking obfuscation.add(%s) ...", block["blocked"]) obfuscation.add(block["blocked"]) else: diff --git a/fba/models/obfuscation.py b/fba/models/obfuscation.py index c8d9e29..fcbd363 100644 --- a/fba/models/obfuscation.py +++ b/fba/models/obfuscation.py @@ -24,7 +24,7 @@ logging.basicConfig(level=logging.INFO) logger = logging.getLogger(__name__) #logger.setLevel(logging.DEBUG) -def is_added(pattern: str) -> bool: +def has(pattern: str) -> bool: logger.debug("pattern='%s' - CALLED!", pattern) if not isinstance(pattern, str): raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'") @@ -47,7 +47,7 @@ def add(pattern: str) -> None: raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'") elif pattern == "": raise ValueError("Parametern 'pattern' is an empty string") - elif is_added(pattern): + elif has(pattern): raise Exception(f"pattern='{pattern}' is already added but function was invoked") database.cursor.execute("INSERT INTO obfuscation (pattern, added) VALUES (?, ?)", ( @@ -63,7 +63,7 @@ def update (pattern: str) -> None: raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'") elif pattern == "": raise ValueError("Parametern 'pattern' is an empty string") - elif not is_added(pattern): + elif not has(pattern): raise Exception(f"pattern='{pattern}' is not added but function was invoked") database.cursor.execute("UPDATE obfuscation SET last_used=? WHERE pattern=? LIMIT 1", ( @@ -79,7 +79,7 @@ def delete (pattern: str) -> None: raise ValueError(f"pattern[]='{type(pattern)}' is not of type 'str'") elif pattern == "": raise ValueError("Parametern 'pattern' is an empty string") - elif not is_added(pattern): + elif not has(pattern): raise Exception(f"pattern='{pattern}' is not added but function was invoked") database.cursor.execute("DELETE FROM obfuscation WHERE pattern=? LIMIT 1", [pattern]) diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 7e66bc3..fc92f88 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -170,7 +170,6 @@ def fetch_blocks(domain: str) -> list: "reason" : None, "block_level": block_level, }) - else: logger.warning("Cannot find 'mrf_simple' or 'quarantined_instances' in JSON reply: domain='%s'", domain) @@ -307,7 +306,7 @@ def fetch_blocks_from_about(domain: str) -> dict: ) logger.debug("response.ok='%s',response.status_code=%d,response.text()=%d", response.ok, response.status_code, len(response.text)) - if not response.ok or response.text.strip() == "": + if not response.ok or response.status_code >= 400 or response.text.strip() == "": logger.warning("path='%s' does not exist on domain='%s' - SKIPPED!", path, domain) continue -- 2.39.5