aboutsummaryrefslogtreecommitdiff
path: root/gn_libs/mysqldb.py
diff options
context:
space:
mode:
authorFrederick Muriuki Muriithi2024-12-09 10:39:41 -0600
committerFrederick Muriuki Muriithi2024-12-09 11:33:41 -0600
commit0e26bfd28f27603e7039b51cbdf596c58065c6c6 (patch)
tree28854599ca3afd0e3bb6f405828c4985424f7931 /gn_libs/mysqldb.py
parent709991993e3aa9e9f8fbdd8453660b7a43547486 (diff)
downloadgn-libs-0e26bfd28f27603e7039b51cbdf596c58065c6c6.tar.gz
Check for non-negative integers.
Diffstat (limited to 'gn_libs/mysqldb.py')
-rw-r--r--gn_libs/mysqldb.py7
1 files changed, 6 insertions, 1 deletions
diff --git a/gn_libs/mysqldb.py b/gn_libs/mysqldb.py
index c738d96..d620b11 100644
--- a/gn_libs/mysqldb.py
+++ b/gn_libs/mysqldb.py
@@ -24,6 +24,11 @@ def __parse_boolean__(val: str) -> bool:
return val.strip().lower() in true_vals
+def __non_negative_int__(val: str) -> int:
+ """Convert a value to a non-negative int."""
+ _val = int(val)
+ assert (val >= 0), f"Expected a non-negative value. Got {_val}"
+ return _val
def __parse_db_opts__(opts: str) -> dict:
"""Parse database options into their appropriate values.
@@ -36,7 +41,7 @@ def __parse_db_opts__(opts: str) -> dict:
"local_infile", "autocommit", "binary_prefix")
conversion_fns: dict[str, Callable] = {
**{opt: str for opt in allowed_opts},
- "connect_timeout": int,
+ "connect_timeout": __non_negative_int__,
"compress": __parse_boolean__,
"use_unicode": __parse_boolean__,
# "cursorclass": __load_cursor_class__