From c41510ea7e38271d5aea26ec8c8a18983242a5a4 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Roland=20H=C3=A4der?= Date: Tue, 16 Jan 2024 20:18:16 +0100 Subject: [PATCH] Continued/WIP: - in commands.fetch_instances() added initialization of variables 'rows' - also moved fetching rows into if() block - commented some more code --- fba/commands.py | 5 ++++- fba/http/federation.py | 4 +++- fba/networks/mastodon.py | 5 ++++- fba/networks/pleroma.py | 10 +++++++--- 4 files changed, 18 insertions(+), 6 deletions(-) diff --git a/fba/commands.py b/fba/commands.py index 8d176af..8da0331 100644 --- a/fba/commands.py +++ b/fba/commands.py @@ -958,6 +958,9 @@ def fetch_instances(args: argparse.Namespace) -> int: logger.debug("Invoking locking.acquire() ...") locking.acquire() + # Init variables + rows = list() + # Is domain or software set? if args.domain != "": logger.debug("args.domain='%s' - checking ...", args.domain) @@ -974,8 +977,8 @@ def fetch_instances(args: argparse.Namespace) -> int: # Fetch record database.cursor.execute("SELECT domain, origin, software FROM instances WHERE domain = ? LIMIT 1", [domain]) + rows = database.cursor.fetchall() - rows = database.cursor.fetchall() logger.info("Checking %d entries ...", len(rows)) for row in rows: logger.debug("row[domain]='%s',row[origin]='%s',row[software]='%s'", row["domain"], row["origin"], row["software"]) diff --git a/fba/http/federation.py b/fba/http/federation.py index 2c35fc6..fbb7f74 100644 --- a/fba/http/federation.py +++ b/fba/http/federation.py @@ -538,7 +538,9 @@ def add_peers(rows: dict) -> list: elif len(rows) == 0: raise ValueError("Parameter 'rows' is empty") + # Init variables peers = list() + for key in ["linked", "allowed", "blocked"]: logger.debug("key='%s'", key) if key not in rows or rows[key] is None: @@ -553,7 +555,7 @@ def add_peers(rows: dict) -> list: continue elif isinstance(peer, dict) and "domain" in peer: logger.debug("peer[domain]='%s'", peer["domain"]) - peer = tidyup.domain(peer["domain"]) + peer = tidyup.domain(peer["domain"]) if peer["domain"] != "" else None elif isinstance(peer, str): logger.debug("peer='%s'", peer) peer = tidyup.domain(peer) diff --git a/fba/networks/mastodon.py b/fba/networks/mastodon.py index e7d00b6..0f5953b 100644 --- a/fba/networks/mastodon.py +++ b/fba/networks/mastodon.py @@ -69,8 +69,10 @@ def fetch_blocks_from_about(domain: str) -> dict: elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") - logger.info("Fetching mastodon blocks from domain='%s'", domain) + # Init variables doc = None + + logger.info("Fetching mastodon blocks from domain='%s'", domain) for path in ["/about/more", "/about"]: try: logger.debug("Fetching path='%s' from domain='%s' ...", path, domain) @@ -156,6 +158,7 @@ def fetch_blocks(domain: str) -> list: elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") + # Init variables blocklist = list() logger.debug("Invoking fetch_blocks_from_about(%s) ...", domain) diff --git a/fba/networks/pleroma.py b/fba/networks/pleroma.py index 6ee00a6..4126999 100644 --- a/fba/networks/pleroma.py +++ b/fba/networks/pleroma.py @@ -61,6 +61,7 @@ def fetch_blocks(domain: str) -> list: elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") + # Init variables blockdict = list() rows = None @@ -269,6 +270,7 @@ def fetch_blocks(domain: str) -> list: else: logger.warning("Cannot find 'mrf_simple_info' or 'quarantined_instances_info' in JSON reply: domain='%s'", domain) + logger.debug("found='%s'", found) if not found: logger.debug("Did not find any useable JSON elements, domain='%s', continuing with /about page ...", domain) blocklist = fetch_blocks_from_about(domain) @@ -299,8 +301,10 @@ def fetch_blocks_from_about(domain: str) -> dict: elif not instances.is_registered(domain): raise Exception(f"domain='{domain}' is not registered but function is invoked.") - logger.debug("Fetching mastodon blocks from domain='%s'", domain) + # Init variables doc = None + + logger.debug("Fetching mastodon blocks from domain='%s'", domain) for path in ["/instance/about/index.html"]: try: # Resetting doc type @@ -378,9 +382,9 @@ def fetch_blocks_from_about(domain: str) -> dict: blocked = line.find_all("td")[0].text reason = line.find_all("td")[1].text - logger.debug("blocked='%s',reason='%s'", blocked, reason) + logger.debug("blocked='%s',reason='%s' - BEFORE!", blocked, reason) blocked = tidyup.domain(blocked) if blocked != "" else None - reason = tidyup.reason(reason) if reason != "" else None + reason = tidyup.reason(reason) if reason != "" else None logger.debug("blocked='%s',reason='%s' - AFTER!", blocked, reason) if blocked in [None, ""]: -- 2.39.5