raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not 'str'")
elif block_level == "":
raise ValueError("Parameter 'block_level' is empty")
- elif block_level == "accept";
+ elif block_level == "accept":
raise ValueError("Accepted domains are not wanted here")
# DEBUG: print("DEBUG: Updating block reason:", reason, blocker, blocked, block_level)
- try:
- fba.cursor.execute(
- "UPDATE blocks SET reason = ?, last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND (reason IS NULL OR reason = '') LIMIT 1",
- (
- reason,
- time.time(),
- blocker,
- blocked,
- block_level
- ),
- )
-
- # DEBUG: print(f"DEBUG: fba.cursor.rowcount={fba.cursor.rowcount}")
- if fba.cursor.rowcount == 0:
- # DEBUG: print(f"DEBUG: Did not update any rows: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',reason='{reason}' - EXIT!")
- return
-
- except BaseException as exception:
- print(f"ERROR: failed SQL query: reason='{reason}',blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(exception)}]:'{str(exception)}'")
- sys.exit(255)
+ fba.cursor.execute(
+ "UPDATE blocks SET reason = ?, last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? AND (reason IS NULL OR reason = '') LIMIT 1",
+ [
+ reason,
+ time.time(),
+ blocker,
+ blocked,
+ block_level
+ ])
+
+ # DEBUG: print(f"DEBUG: fba.cursor.rowcount={fba.cursor.rowcount}")
+ if fba.cursor.rowcount == 0:
+ raise Exception(f"Did not update any rows: domain='{domain}',fields()={len(fields)}")
# DEBUG: print("DEBUG: EXIT!")
raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not 'str'")
elif block_level == "":
raise ValueError("Parameter 'block_level' is empty")
- elif block_level == "accept";
+ elif block_level == "accept":
raise ValueError("Accepted domains are not wanted here")
- try:
- fba.cursor.execute(
- "UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
- (
- time.time(),
- blocker,
- blocked,
- block_level
- )
- )
-
- # DEBUG: print(f"DEBUG: fba.cursor.rowcount={fba.cursor.rowcount}")
- if fba.cursor.rowcount == 0:
- # DEBUG: print(f"DEBUG: Did not update any rows: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}' - EXIT!")
- return
-
- except BaseException as exception:
- print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',block_level='{block_level}',exception[{type(exception)}]:'{str(exception)}'")
- sys.exit(255)
+ fba.cursor.execute(
+ "UPDATE blocks SET last_seen = ? WHERE blocker = ? AND blocked = ? AND block_level = ? LIMIT 1",
+ [
+ time.time(),
+ blocker,
+ blocked,
+ block_level
+ ])
+
+ # DEBUG: print(f"DEBUG: fba.cursor.rowcount={fba.cursor.rowcount}")
+ if fba.cursor.rowcount == 0:
+ raise Exception(f"Did not update any rows: domain='{domain}',fields()={len(fields)}")
# DEBUG: print("DEBUG: EXIT!")
raise ValueError(f"Parameter block_level[]='{type(block_level)}' is not of type 'str'")
elif block_level == "":
raise ValueError("Parameter 'block_level' is empty")
- elif block_level == "accept";
+ elif block_level == "accept":
raise ValueError("Accepted domains are not wanted here")
fba.cursor.execute(
raise Exception(f"blocker='{blocker}' is blacklisted but function invoked")
elif blacklist.is_blacklisted(blocked):
raise Exception(f"blocked='{blocked}' is blacklisted but function invoked")
- elif block_level == "accept";
+ elif block_level == "accept":
raise ValueError("Accepted domains are not wanted here")
if reason is not None:
reason = tidyup.reason(reason)
print(f"INFO: New block: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}'")
- try:
- fba.cursor.execute(
- "INSERT INTO blocks (blocker, blocked, reason, block_level, first_seen, last_seen) VALUES (?, ?, ?, ?, ?, ?)",
- (
- blocker,
- blocked,
- reason,
- block_level,
- time.time(),
- time.time()
- ),
- )
- except BaseException as exception:
- print(f"ERROR: failed SQL query: blocker='{blocker}',blocked='{blocked}',reason='{reason}',block_level='{block_level}',exception[{type(exception)}]:'{str(exception)}'")
- sys.exit(255)
+
+ fba.cursor.execute(
+ "INSERT INTO blocks (blocker, blocked, reason, block_level, first_seen, last_seen) VALUES (?, ?, ?, ?, ?, ?)",
+ [
+ blocker,
+ blocked,
+ reason,
+ block_level,
+ time.time(),
+ time.time()
+ ])
# DEBUG: print("DEBUG: EXIT!")
raise ValueError("Parameter 'domain' is empty")
elif not has_pending(domain):
raise Exception(f"domain='{domain}' has no pending instance data, but function invoked")
+ elif not is_registered(domain):
+ raise Exception(f"domain='{domain}' cannot be updated while not being registered")
# DEBUG: print(f"DEBUG: Updating instance data for domain='{domain}' ...")
sql_string = ""
sql_string = "UPDATE instances SET" + sql_string + " last_updated = ? WHERE domain = ? LIMIT 1"
# DEBUG: print("DEBUG: sql_string:", sql_string)
- try:
- # DEBUG: print("DEBUG: Executing SQL:", sql_string)
- fba.cursor.execute(sql_string, fields)
-
- # DEBUG: print(f"DEBUG: Success! (rowcount={fba.cursor.rowcount })")
- if fba.cursor.rowcount == 0:
- print(f"WARNING: Did not update any rows: domain='{domain}',fields()={len(fields)} - EXIT!")
- return
+ # DEBUG: print("DEBUG: Executing SQL:", sql_string)
+ fba.cursor.execute(sql_string, fields)
- # DEBUG: print("DEBUG: Committing changes ...")
- fba.connection.commit()
+ # DEBUG: print(f"DEBUG: Success! (rowcount={fba.cursor.rowcount })")
+ if fba.cursor.rowcount == 0:
+ raise Exception(f"Did not update any rows: domain='{domain}',fields()={len(fields)}")
- # DEBUG: print(f"DEBUG: Deleting _pending for domain='{domain}'")
- for key in _pending:
- # DEBUG: print(f"DEBUG: domain='{domain}',key='{key}'")
- if domain in _pending[key]:
- del _pending[key][domain]
+ # DEBUG: print("DEBUG: Committing changes ...")
+ fba.connection.commit()
- except BaseException as exception:
- print(f"ERROR: failed SQL query: domain='{domain}',sql_string='{sql_string}',exception[{type(exception)}]:'{str(exception)}'")
- sys.exit(255)
+ # DEBUG: print(f"DEBUG: Deleting _pending for domain='{domain}'")
+ for key in _pending:
+ # DEBUG: print(f"DEBUG: domain='{domain}',key='{key}'")
+ if domain in _pending[key]:
+ del _pending[key][domain]
# DEBUG: print("DEBUG: EXIT!")