built-in validators¶
The following are built in validators in records
-
class
ValidationToken¶ A base class for all object that should be interpreted as validators
-
class
AssertValidation(ValidationToken, ABC)¶ A validation token to check that a condition is upheld
-
__init__(*, err: Union[str, Exception] = 'validation failed', warn: Union[bool, logging.Logger] = False)¶ - Parameters
err – the error or warning to raise if the condition is not upheld.
warn – whether to issue a warning instead if raising an error. Can also be an instance of a Logger, to specify the logger to warn with.
-
-
class
AssertCallValidation(AssertValidation)¶ An assertion validation token to call arbitrary functions
-
class
CallValidation(AssertValidation)¶ An validation token to call arbitrary functions
-
__init__(func: Callable[[…], T], *args, **kwargs)¶ - Parameters
func – The callable to use as the validation callback.
args – Optional positional arguments to pass to
func, after the validation argument.kwargs – Optional keyword arguments to pass to
func.
Note
calling
CallValidationwithargsorkwargsis akin to calling it with afunctools.partial()asfunc.>>> CallValidation(foo, a, b, c=d) >>> # is equivalent to >>> CallValidation(lambda v: foo(v, a, b, c=d))
-
-
class
Clamp(ValidationToken)¶ - A validator class that constrains the value to be between two bounds, bringing it to the nearest bound if it
falls outside.
-
__init__(ge: Any = <records.fillers.builtin_validators._Least object>, le: Any = <records.fillers.builtin_validators._Greatest object>, **kwargs)¶ - Parameters
ge – the lower bound, defaults to no lower bound
le – the upper bound, defaults to no upper bound
-
class
Cyclic(ValidationToken)¶ - A validator class that constrains the value to be between two bounds, bringing it to the equivalent position as
though the domain is cyclic. Useful for angles and time of day.
-
__init__(minimum, maximum, **kwargs)¶ - Parameters
minimum – the inclusive lower bound
maximum – the exclusive upper bound.
-
class
Within(AssertValidation)¶ An assertion validation that raises an error if the value falls outside of bounds.
-
__init__(ge: Any = <records.fillers.builtin_validators._Least object>, lt: Any = <records.fillers.builtin_validators._Greatest object>, g_eq=True, l_eq=False, **kwargs)¶ - Parameters
ge – the lower bound, defaults to no lower bound
lt – the upper bound, defaults to no upper bound
g_eq – whether the lower bound is inclusive, defaults to True.
l_eq – whether the upper bound is inclusive, defaults to False.
kwargs – forwarded to
AssertValidation
-
-
class
FullMatch(AssertValidation)¶ An assertion validation that raises an error if the value does not match a regex pattern.
-
__init__(pattern: Union[Pattern, str, bytes], **kwargs)¶ - Parameters
pattern – either a compiled pattern or an uncompiled string or bytestring
kwargs – forwarded to
AssertValidation
Note
patternwill be compiled in accordance torecords.extras.re
-
-
class
Truth(AssertValidation)¶ An assertion validation that raises an error if the value does not evaluate as True.
-
__init__(*, err: Union[str, Exception] = 'validation failed', warn: Union[bool, logging.Logger] = False)¶ - Parameters
err – the error or warning to raise if the condition is not upheld.
warn – whether to issue a warning instead if raising an error. Can also be an instance of a Logger, to specify the logger to warn with.
-