boolstr
Full documentation pages are generated for docstring
reference only and may contain symbols imported from other
modules. Imported symbols are not distinguished from locally
defined symbols and will appear in any module that they are
imported into. For better information on where symbols should
be imported from, review the sourcecode on the
github.
FoSpy.parsing.validators.boolstr
false_values
module-attribute
false_values = ['false', 'f', 'no', 'n', '0', 'off']
true_values
module-attribute
true_values = ['true', 't', 'yes', 'y', '1', 'on']
_validator_rules
_validator_rules(*args, inherit_from=None)
Source code in FoSpy/_docs/properties/__init__.py
| def _validator_rules(*args, inherit_from=None):
from ..._docs.properties import val_rules
def decorator(func, a=args, ih=inherit_from):
inherited = val_rules.get(ih, [])
a = list(a)
a.extend(inherited)
a = tuple(a)
if len(a) > 0:
val_rules[func] = a
return func
return decorator
|
str_to_bool
Source code in FoSpy/parsing/validators/boolstr.py
| @_validator_rules(
"A boolen value (True or False)",
"Acceptable 'True' values (not case sensitive):",true_values,
"Acceptable 'False' values (not case sensitive):",false_values
)
def str_to_bool(s):
if isinstance(s, bool):
return s
if not isinstance(s, str):
raise TypeError("Expected a string or bool")
s = s.strip().lower()
if s in true_values:
return True
if s in false_values:
return False
raise ValueError(f"Could not parse '{s!r}' as a boolean")
|