checker module.
Intended to be used by unittest/doctest for validation rules. It is recommended to use test case per validator, test method per attribute, split by success check first than fails.
mixin module.
Used primary by service layer to validate business rules.
Requirements: - self.errors
Example:
class MyService(ValidationMixin):
def __init__(self, repository, errors, locale):
# ...
def authenticate(self, credential):
if not self.factory.membership.authenticate(credentials):
self.error('The username or password provided '
'is incorrect.')
return False
# ...
return True
Used primary by service layer to validate domain model.
Requirements: - self.errors - self.translations
Example:
class MyService(ValidationMixin):
def __init__(self, repository, errors, translations, locale):
# ...
def authenticate(self, credential):
if not self.validate(credential, credential_validator):
return False
# ...
return True
model module.
Converts value to datetime.date.
Converts value to datetime.datetime.
patches module.
rules module.
Adapts value according to converter. This is useful when you need keep string input in model but validate as an integer.
Applies all rules regardless of validation result.
Ensures a valid base64 string input.
Compares attribute being validated with some other attribute value.
The idea behind this rule is to be able to substitute any validation rule by this one that always succeed:
from wheezy.validation.rules import ignore as regex
This way all regex rules are ignored within a scope of import.
Adapts value to an integer.
Applies rules to each item in value list.
Result of python function len() must fall within a range defined by this rule.
Any value evaluated to boolean False pass this rule.
None value will not pass this rule.
Value must match at least one element from items. Checks are case sensitive if items are strings.
Succeed if at least one rule in rules succeed.
Fails if predicate return False. Predicate is any callable of the following contract:
def predicate(model):
return True
Ensures value is in range defined by this rule.
Works with any numbers including Decimal.
Search for regular expression pattern.
Check if value is in relative date range local time.
Check if value is in relative datetime range local time.
Check if value is in relative date/time range.
>>> r = RelativeDeltaRule()
>>> r.now()
Traceback (most recent call last):
...
NotImplementedError: ...
Check if value is in relative date range TZ time.
Check if value is in relative date range TZ time.
Check if value is in relative date range UTC time.
Check if value is in relative datetime range UTC time.
Check if value is in relative unix range local time.
Any value evaluated to boolean True pass this rule. You can extend this validator by supplying additional false values to required_but_missing list.
Ensures a valid scientific string input.
Ensures only letters, numbers, underscores or hyphens.
Ensures a valid base64 URL-safe string input using an alphabet, which substitutes - instead of + and _ instead of / in the standard Base64 alphabet. The input can still contain =.
Fails if predicate return False. Predicate is any callable of the following contract:
def predicate(value):
return True
alias of AdapterRule
alias of CompareRule
alias of IgnoreRule
alias of IntAdapterRule
alias of IteratorRule
alias of LengthRule
alias of PredicateRule
alias of ValuePredicateRule
alias of PredicateRule
alias of RelativeDateDeltaRule
alias of RelativeDateTimeDeltaRule
alias of RelativeUnixTimeDeltaRule
alias of RelativeTZDateDeltaRule
alias of RelativeTZDateTimeDeltaRule
alias of RelativeUnixTimeDeltaRule
alias of RelativeUTCDateDeltaRule
alias of RelativeUTCDateTimeDeltaRule
alias of ValuePredicateRule
validator module.
Container of validation rules that all together provide object validation.
Validates given model with results of validation stored in results. Be default the validation stops on first rule fail, however with supplied stop argument set False the result will get all errors reported by a rule.
There is a way to internationalize validation errors with translations or gettext.