From: Roland Häder Date: Fri, 2 Jun 2023 12:48:23 +0000 (+0200) Subject: Continued: X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=e40ec57d137fd8a88397b18edd453ed6c8d8253b;p=fba.git Continued: - timestamps are not handled over anymore - more checks on parameter --- diff --git a/fba.py b/fba.py index 95774e7..37e7384 100644 --- a/fba.py +++ b/fba.py @@ -192,7 +192,7 @@ def is_cache_key_set(key: str, sub: str) -> bool: def is_primitive(var: any) -> bool: #print(f"DEBUG: var[]='{type(var)}' - CALLED!") - return type(var) in {int, str, float, bool, NoneType} + return type(var) in {int, str, float, bool} or var == None def set_instance_data(key: str, domain: str, value: any): #print(f"DEBUG: key='{key}',domain='{domain}',value[]='{type(value)}' - CALLED!") @@ -1086,12 +1086,18 @@ def update_last_seen(blocker: str, blocked: str, block_level: str): def block_instance(blocker: str, blocked: str, reason: str, block_level: str): # DEBUG: print("DEBUG: blocker,blocked,reason,block_level:", blocker, blocked, reason, block_level) - if not validators.domain(blocker.split("/")[0]): - print("WARNING: Bad blocker:", blocker) - raise + if type(blocker) != str: + raise ValueError(f"Parameter blocker[]={type(blocker)} is not 'str'") + elif blocker == "": + raise ValueError(f"Parameter 'blocker' cannot be empty") + elif not validators.domain(blocker.split("/")[0]): + raise ValueError(f"Bad blocker='{blocker}'") + elif type(blocked) != str: + raise ValueError(f"Parameter blocked[]={type(blocked)} is not 'str'") + elif blocked == "": + raise ValueError(f"Parameter 'blocked' cannot be empty") elif not validators.domain(blocked.split("/")[0]): - print("WARNING: Bad blocked:", blocked) - raise + raise ValueError(f"Bad blocked='{blocked}'") print("INFO: New block:", blocker, blocked, reason, block_level, first_seen, last_seen) try: @@ -1108,7 +1114,7 @@ def block_instance(blocker: str, blocked: str, reason: str, block_level: str): ) except BaseException as e: - print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',first_seen='{first_seen}',last_seen='{last_seen}',exception[{type(e)}]:'{str(e)}'") + print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',exception[{type(e)}]:'{str(e)}'") sys.exit(255) # DEBUG: print("DEBUG: EXIT!")