summaryrefslogtreecommitdiff
path: root/kvmd/validators/basic.py
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2019-10-24 03:09:06 +0300
committerDevaev Maxim <[email protected]>2019-10-24 03:09:06 +0300
commitb4ef91838e16cdb70ae1152c320a3973f07c5f89 (patch)
treea98b222952940dedb07cdb1ebe89025af3c50e46 /kvmd/validators/basic.py
parentc124e63d6d6cdd07b6d0fa4439fed878ed164fbb (diff)
improved validation
Diffstat (limited to 'kvmd/validators/basic.py')
-rw-r--r--kvmd/validators/basic.py18
1 files changed, 16 insertions, 2 deletions
diff --git a/kvmd/validators/basic.py b/kvmd/validators/basic.py
index 0328490d..24387be4 100644
--- a/kvmd/validators/basic.py
+++ b/kvmd/validators/basic.py
@@ -36,13 +36,27 @@ from . import check_in_list
# =====
+def valid_stripped_string(arg: Any, name: str="") -> str:
+ if not name:
+ name = "stripped string"
+ return check_not_none_string(arg, name)
+
+
+def valid_stripped_string_not_empty(arg: Any, name: str="") -> str:
+ if not name:
+ name = "not empty stripped string"
+ if len(str(arg).strip()) == 0:
+ arg = None
+ return valid_stripped_string(arg, name)
+
+
def valid_bool(arg: Any) -> bool:
true_args = ["1", "true", "yes"]
false_args = ["0", "false", "no"]
name = f"bool ({true_args!r} or {false_args!r})"
- arg = check_not_none_string(arg, name).lower()
+ arg = valid_stripped_string_not_empty(arg, name).lower()
arg = check_in_list(arg, name, true_args + false_args)
return (arg in true_args)
@@ -57,7 +71,7 @@ def valid_number(
name = (name or type.__name__)
- arg = check_not_none_string(arg, name)
+ arg = valid_stripped_string_not_empty(arg, name)
try:
arg = type(arg)
except Exception: