]> git.mxchange.org Git - fba.git/blobdiff - fba/federation/mastodon.py
Fixed some issues found by pylint:
[fba.git] / fba / federation / mastodon.py
index d00fa7ca259b77383dc31d88243b77139b231f2b..abbe8b8fb9ebcda6fb0efeb6904fc8d789e5e917 100644 (file)
@@ -53,10 +53,10 @@ language_mapping = {
 
 def fetch_blocks_from_about(domain: str) -> dict:
     # DEBUG: print(f"DEBUG: domain='{domain}' - 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")
+        raise ValueError("Parameter 'domain' is empty")
 
     # DEBUG: print("DEBUG: Fetching mastodon blocks from domain:", domain)
     blocklist = {
@@ -71,9 +71,9 @@ def fetch_blocks_from_about(domain: str) -> dict:
             network.fetch_response(domain, "/about/more", fba.headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
             "html.parser",
         )
-    except BaseException as e:
-        print("ERROR: Cannot fetch from domain:", domain, e)
-        instances.update_last_error(domain, e)
+    except BaseException as exception:
+        print("ERROR: Cannot fetch from domain:", domain, exception)
+        instances.update_last_error(domain, exception)
         return {}
 
     for header in doc.find_all("h3"):
@@ -108,18 +108,18 @@ def fetch_blocks_from_about(domain: str) -> dict:
 
 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:
         # json endpoint for newer mastodongs
@@ -142,8 +142,8 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 csrf = meta.find("meta", attrs={"name": "csrf-token"})["content"]
                 # DEBUG: print("DEBUG: Adding CSRF token:", domain, csrf)
                 reqheaders = {**fba.api_headers, **{"X-CSRF-Token": csrf}}
-            except BaseException as e:
-                # DEBUG: print("DEBUG: No CSRF token found, using normal headers:", domain, e)
+            except BaseException as exception:
+                # DEBUG: print("DEBUG: No CSRF token found, using normal headers:", domain, exception)
                 reqheaders = fba.api_headers
 
             # DEBUG: print("DEBUG: Querying API domain_blocks:", domain)
@@ -173,8 +173,8 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
                 else:
                     print("WARNING: Unknown severity:", block['severity'], block['domain'])
 
-        except BaseException as e:
-            # DEBUG: print(f"DEBUG: Failed, trying mastodon-specific fetches: domain='{domain}',exception[{type(e)}]={str(e)}")
+        except BaseException as exception:
+            # DEBUG: print(f"DEBUG: Failed, trying mastodon-specific fetches: domain='{domain}',exception[{type(exception)}]={str(exception)}")
             json = fetch_blocks_from_about(domain)
 
         print(f"INFO: Checking {len(json.items())} entries from domain='{domain}',software='mastodon' ...")
@@ -193,7 +193,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) if reason != None and reason != "" 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 == "":
@@ -209,7 +209,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}',blocked_hash='{blocked_hash}' - SKIPPED!")
                         continue
 
@@ -256,7 +256,7 @@ def fetch_blocks(domain: str, origin: str, nodeinfo_url: str):
 
         # DEBUG: print("DEBUG: Committing changes ...")
         fba.connection.commit()
-    except Exception as e:
-        print(f"ERROR: domain='{domain}',software='mastodon',exception[{type(e)}]:'{str(e)}'")
+    except Exception as exception:
+        print(f"ERROR: domain='{domain}',software='mastodon',exception[{type(exception)}]:'{str(exception)}'")
 
     # DEBUG: print("DEBUG: EXIT!")