Validators¶
Built in validators¶
These validators are provided with odin.
Odin also includes a helper method for generating simple validators.
-
odin.validators.
simple_validator
(assertion=None, message='The supplied value is invalid', code='invalid')[source]¶ Create a simple validator.
Parameters: - assertion – An Validation exception will be raised if this check returns a none True value.
- message – Message to raised in Validation exception if validation fails.
- code – Code to included in Validation exception. This can be used to customise the message at the resource level.
Usage:
>>> none_validator = simple_validator(lambda x: x is not None, message="This value cannot be none")
This can also be used as a decorator:
@create_validator(message="This value cannot be none") def none_validator(v): return v is not None