]> git.mxchange.org Git - fba.git/blobdiff - fba/network.py
Fixed some issues found by pylint:
[fba.git] / fba / network.py
index a60e0e89782c4c5c32793bbff6a9d8644481a151..8d6414494839520c8a292f293572cf14f25c01da 100644 (file)
@@ -23,15 +23,15 @@ from fba import instances
 
 def post_json_api(domain: str, path: str, parameter: str, extra_headers: dict = {}) -> dict:
     # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}',parameter='{parameter}',extra_headers()={len(extra_headers)} - 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(path) != str:
+        raise ValueError("Parameter 'domain' is empty")
+    elif not isinstance(path, str):
         raise ValueError(f"path[]={type(path)} is not 'str'")
     elif path == "":
         raise ValueError("Parameter 'path' cannot be empty")
-    elif type(parameter) != str:
+    elif not isinstance(parameter, str):
         raise ValueError(f"parameter[]={type(parameter)} is not 'str'")
 
     # DEBUG: print("DEBUG: Sending POST to domain,path,parameter:", domain, path, parameter, extra_headers)
@@ -50,22 +50,22 @@ def post_json_api(domain: str, path: str, parameter: str, extra_headers: dict =
             print(f"WARNING: Cannot query JSON API: domain='{domain}',path='{path}',parameter()={len(parameter)},response.status_code='{response.status_code}',data[]='{type(data)}'")
             instances.update_last_error(domain, response)
 
-    except BaseException as e:
-        print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception[{type(e)}]:'{str(e)}'")
+    except BaseException as exception:
+        print(f"WARNING: Some error during post(): domain='{domain}',path='{path}',parameter()={len(parameter)},exception[{type(exception)}]:'{str(exception)}'")
 
     # DEBUG: print(f"DEBUG: Returning data({len(data)})=[]:{type(data)}")
     return data
 
 def send_bot_post(instance: str, blocklist: dict):
     # DEBUG: print(f"DEBUG: instance={instance},blocklist()={len(blocklist)} - CALLED!")
-    if type(domain) != str:
+    if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
-    elif type(blocklist) != dict:
+    elif not isinstance(blocklist, dict):
         raise ValueError(f"Parameter blocklist[]='{type(blocklist)}' is not 'dict'")
 
-    message = instance + " has blocked the following instances:\n\n"
+    message = f"{instance} has blocked the following instances:\n\n"
     truncated = False
 
     if len(blocklist) > 20:
@@ -75,7 +75,7 @@ def send_bot_post(instance: str, blocklist: dict):
     # DEBUG: print(f"DEBUG: blocklist()={len(blocklist)}")
     for block in blocklist:
         # DEBUG: print(f"DEBUG: block['{type(block)}']={block}")
-        if block["reason"] == None or block["reason"] == '':
+        if block["reason"] is None or block["reason"] == '':
             message = message + block["blocked"] + " with unspecified reason\n"
         else:
             if len(block["reason"]) > 420:
@@ -103,10 +103,10 @@ def send_bot_post(instance: str, blocklist: dict):
 
 def fetch_friendica_blocks(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 friendica blocks from domain:", domain)
     blocked = list()
@@ -116,9 +116,9 @@ def fetch_friendica_blocks(domain: str) -> dict:
             fetch_response(domain, "/friendica", headers, (config.get("connection_timeout"), config.get("read_timeout"))).text,
             "html.parser",
         )
-    except BaseException as e:
-        print("WARNING: Failed to fetch /friendica from domain:", domain, e)
-        instances.update_last_error(domain, e)
+    except BaseException as exception:
+        print("WARNING: Failed to fetch /friendica from domain:", domain, exception)
+        instances.update_last_error(domain, exception)
         return {}
 
     blocklist = doc.find(id="about_blocklist")
@@ -152,11 +152,11 @@ def fetch_friendica_blocks(domain: str) -> dict:
 
 def fetch_response(domain: str, path: str, headers: dict, timeout: list) -> requests.models.Response:
     # DEBUG: print(f"DEBUG: domain='{domain}',path='{path}',headers()={len(headers)},timeout={timeout} - CALLED!")
-    if type(domain) != str:
+    if not isinstance(domain, str):
         raise ValueError(f"Parameter domain[]='{type(domain)}' is not 'str'")
     elif domain == "":
         raise ValueError("Parameter 'domain' is empty")
-    elif type(path) != str:
+    elif not isinstance(path, str):
         raise ValueError(f"Parameter path[]='{type(path)}' is not 'str'")
     elif path == "":
         raise ValueError("Parameter 'path' is empty")
@@ -168,10 +168,10 @@ def fetch_response(domain: str, path: str, headers: dict, timeout: list) -> requ
             headers=headers,
             timeout=timeout
         );
-    except requests.exceptions.ConnectionError as e:
-        # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(e)}]='{str(e)}'")
-        instances.update_last_error(domain, e)
-        raise e
+    except requests.exceptions.ConnectionError as exception:
+        # DEBUG: print(f"DEBUG: Fetching '{path}' from '{domain}' failed. exception[{type(exception)}]='{str(exception)}'")
+        instances.update_last_error(domain, exception)
+        raise exception
 
     # DEBUG: print(f"DEBUG: response[]='{type(response)}' - EXXIT!")
     return response