summaryrefslogtreecommitdiffstats
path: root/venv/lib/python3.9/site-packages/validators/truthy.py
diff options
context:
space:
mode:
Diffstat (limited to 'venv/lib/python3.9/site-packages/validators/truthy.py')
-rw-r--r--venv/lib/python3.9/site-packages/validators/truthy.py39
1 files changed, 39 insertions, 0 deletions
diff --git a/venv/lib/python3.9/site-packages/validators/truthy.py b/venv/lib/python3.9/site-packages/validators/truthy.py
new file mode 100644
index 00000000..517149aa
--- /dev/null
+++ b/venv/lib/python3.9/site-packages/validators/truthy.py
@@ -0,0 +1,39 @@
+from .utils import validator
+
+
+@validator
+def truthy(value):
+ """
+ Validate that given value is not a falsey value.
+
+ This validator is based on `WTForms DataRequired validator`_.
+
+ .. _WTForms DataRequired validator:
+ https://github.com/wtforms/wtforms/blob/master/wtforms/validators.py
+
+ Examples::
+
+ >>> truthy(1)
+ True
+
+ >>> truthy('someone')
+ True
+
+ >>> truthy(0)
+ ValidationFailure(func=truthy, args={'value': 0})
+
+ >>> truthy(' ')
+ ValidationFailure(func=truthy, args={'value': ' '})
+
+ >>> truthy(False)
+ ValidationFailure(func=truthy, args={'value': False})
+
+ >>> truthy(None)
+ ValidationFailure(func=truthy, args={'value': None})
+
+ .. versionadded:: 0.2
+ """
+ return (
+ value and
+ (not isinstance(value, str) or value.strip())
+ )