Bases: flatland.validation.base.Validator
Validates that a value is present.
Messages
Emitted if the u string value of the element is empty, as in the case for an HTML form submitted with an input box left blank.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates that a value evaluates to true.
Messages
Emitted if bool(element.value) is not True.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates that a value evaluates to false.
Messages
Emitted if bool(element.value) is not False.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates that the value is within a set of possible values.
Example:
import flatland
from flatland.validation import ValueIn
is_yesno = ValueIn(valid_options=['yes', 'no'])
schema = flatland.String('yn', validators=[is_yesno])
Attributes
A list, set, or other container of valid element values.
Messages
Emitted if the element’s value is not within the valid_options.
Bases: flatland.validation.base.Validator
Validates that an element was converted to a Python value.
Example:
import flatland
from flatland.validation import Converted
not_bogus = Converted(incorrect='Please enter a valid date.')
schema = flatland.DateTime('when', validators=[not_bogus])
Messages
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates the length of an element’s string value is less than a bound.
Example:
import flatland
from flatland.validation import ShorterThan
valid_length = ShorterThan(8)
schema = flatland.String('password', validators=[valid_length])
Attributes
A maximum character length for the u.
This attribute may be supplied as the first positional argument to the constructor.
Messages
Emitted if the length of the element’s string value exceeds maxlength.
alias of ShorterThan
Bases: flatland.validation.base.Validator
Validates the length of an element’s string value is more than a bound.
Example:
import flatland
from flatland.validation import LongerThan
valid_length = LongerThan(4)
schema = flatland.String('password', validators=[valid_length])
Attributes
A minimum character length for the u.
This attribute may be supplied as the first positional argument to the constructor.
Messages
Emitted if the length of the element’s string value falls short of minlength.
Bases: flatland.validation.base.Validator
Validates the length of an element’s string value is within bounds.
Example:
import flatland
from flatland.validation import LengthBetween
valid_length = LengthBetween(4, 8)
schema = flatland.String('password', validators=[valid_length])
Attributes
A minimum character length for the u.
This attribute may be supplied as the first positional argument to the constructor.
A maximum character length for the u.
This attribute may be supplied as the second positional argument to the constructor.
Messages
Emitted if the length of the element’s string value is less than minlength or greater than maxlength.
Bases: flatland.validation.base.Validator
A validator that ensures that the value is less than a limit.
Example:
import flatland
from flatland.validation import ValueLessThan
schema = flatland.Integer('wishes', validators=[ValueLessThan(boundary=4)])
Attributes
Any comparable object.
Messages
Bases: flatland.validation.base.Validator
A validator that enforces a maximum value.
Example:
import flatland
from flatland.validation import ValueAtMost
schema = flatland.Integer('wishes', validators=[ValueAtMost(maximum=3)])
Attributes
Any comparable object.
Messages
Bases: flatland.validation.base.Validator
A validator that ensures that a value is greater than a limit.
Example:
import flatland
from flatland.validation import ValueGreaterThan
schema = flatland.Integer('wishes', validators=[ValueGreaterThan(boundary=4)])
Attributes
Any comparable object.
Messages
Bases: flatland.validation.base.Validator
A validator that enforces a minimum value.
Example:
import flatland
from flatland.validation import ValueAtLeast
schema = flatland.Integer('wishes', validators=[ValueAtLeast(minimum=3)])
Attributes
Any comparable object.
Messages
Bases: flatland.validation.base.Validator
A validator that enforces minimum and maximum values.
Example:
import flatland
from flatland.validation import ValueBetween
schema = flatland.Integer('wishes',
validators=[ValueBetween(minimum=1, maximum=3)])
Attributes
Any comparable object.
Any comparable object.
Boolean value indicating that minimum and maximum are included in the range. Defaults to True.
Messages
Bases: flatland.validation.base.Validator
A general field equality validator.
Validates that two or more fields are equal.
Attributes
A sequence of field names or field paths. Path names will be evaluated at validation time and relative path names are resolved relative to the element holding this validator. See ValuesEqual for an example.
Messages
Emitted if the transform(element) of all elements are not equal. labels will substitute to a comma-separated list of the label of all but the last element; last_label is the label of the last.
Construct a MapEqual.
Parameters: |
|
---|
Bases: flatland.validation.scalars.MapEqual
Validates that the values of multiple elements are equal.
A MapEqual that compares the value of each element.
Example:
from flatland import Form, String
from flatland.validation import ValuesEqual
class MyForm(Form):
password = String
password_again = String
validators = [ValuesEqual('password', 'password_again')]
attrgetter(‘value’)
Construct a MapEqual.
Parameters: |
|
---|
Bases: flatland.validation.scalars.MapEqual
Validates that the Unicode values of multiple elements are equal.
A MapEqual that compares the u of each element.
attrgetter(‘u’)
Construct a MapEqual.
Parameters: |
|
---|
Bases: flatland.validation.base.Validator
A sequence member validator that ensures all sibling values are unique.
Marks the second and any subsequent occurrences of a value as invalid. Only useful on immediate children of sequence fields such as flatland.List.
Example:
import flatland
from flatland.validation import NotDuplicated
validator = NotDuplicated(failure="Please enter each color only once.")
schema = List.of(String.named('favorite_color')).\
using(validators=[validator])
Attributes
A callable boolean predicate, by default operator.eq. Called positionally with two arguments, element and sibling.
Can be used as a filter, for example ignoring any siblings that have been marked as “deleted” by a checkbox in a web form:
from flatland import Form, List, String, Integer, Boolean
from flatland.validation import NotDuplicated
def live_addrs(element, sibling):
thisval, thatval = element.value, sibling.value
# data marked as deleted is never considered a dupe
if thisval['deleted'] or thatval['deleted']:
return False
# compare elements on 'street' & 'city', ignoring 'id'
return (thisval['street'] == thatval['street'] and
thisval['city'] == thatval['city'])
class Address(Form):
validators = [NotDuplicated(comparator=live_addrs)]
id = Integer.using(optional=True)
deleted = Boolean
street = String
city = String
schema = List.of(Address)
Messages
Emitted on an element that has already appeared in a parent sequence. container_label will substitute the label of the container. position is the position of the element in the parent sequence, counting up from 1.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
eq(a, b) – Same as a==b.
Bases: flatland.validation.base.Validator
A sequence validator that ensures a minimum number of members.
May be applied to a sequence type such as a List.
Example:
from flatland import List, String
from flatland.validation import HasAtLeast
schema = List.of(String.named('wish')).\
using(validators=[HasAtLeast(minimum=3)])
Attributes
Any positive integer.
Messages
Emitted if the sequence contains less than minimum members. child_label will substitute the label of the child schema.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
A sequence validator that ensures a maximum number of members.
May be applied to a sequence type such as a List.
Example:
from flatland import List, String
from flatland.validation import HasAtMost
schema = List.of(String.named('wish')).\
using(validators=[HasAtMost(maximum=3)])
Attributes
Any positive integer.
Messages
Emitted if the sequence contains more than maximum members. child_label will substitute the label of the child schema.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates that the number of members of a sequence lies within a range.
May be applied to a sequence type such as a List.
Example:
from flatland import List, String
from flatland.validation import HasBetween
schema = List.of(String.named('wish')).\
using(validators=[HasBetween(minimum=1, maximum=3)])
Attributes
Any positive integer.
Any positive integer.
Messages
Bases: flatland.validation.base.Validator
Integer
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates NPA and NXX compound elements.
Bases: flatland.validation.base.Validator
Int or Long
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates email addresses.
The default behavior takes a very permissive stance on allowed characters in the local-part and a relatively strict stance on the domain. Given local-part@domain:
Attributes
Default True. When true, require at minimum two domain name components and reject local email addresses such as postmaster@localhost or user@workstation.
No default. If present, a compiled regular expression that will be matched to the local-part. Override this to implement more stringent checking such as RFC-compliant addresses.
Defaults to a basic domain-validating regular expression with no notion of valid top level domains. Override this to require certain TLDs (or alternately and more simply, add another validator to your chain that checks the endings of the string against your list of TLDs.)
The default pattern rejects the valid but obscure quoted IP-address form ([1.2.3.4]).
Messages
Emitted if the email address is not valid.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
A general URL validator.
Validates that a URL is well-formed and may optionally restrict the set of valid schemes and other URL components.
Attributes
Restrict URLs to just this sequence of named schemes, or allow all schemes with (‘*’,). Defaults to all schemes. Example:
allowed_schemes = ('http', 'https', 'ssh')
A sequence of 0 or more part names in urlparse‘s vocabulary:
'scheme', 'netloc', 'path', 'params', 'query', 'fragment'
Defaults to all parts allowed.
By default the urlparse module, but may be replaced by any object that implements urlparse.urlparse() and urlparse.urlunparse().
Messages
Emitted for an unparseable URL.
Emitted if the URL scheme: is not present in allowed_schemes.
Emitted if the URL has a component not present in allowed_parts.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
Validates http and https URLs.
Validates that an http-like URL is well-formed and may optionally require and restrict the permissible values of its components.
Attributes
A sequence of known URL parts. Defaults to the full 10-tuple of names in urlparse‘s vocabulary for HTTP-like URLs.
A mapping of part names. If value is True, the part is required. The value may also be a sequence of strings; the value of the part must be present in this collection to validate.
The default requires a scheme of 'http' or 'https'.
A mapping of part names. If value is True, the part is forbidden and validation fails. The value may also be a sequence of strings; the value of the part must not be present in this collection to validate.
The default forbids username and password parts.
By default the urlparse module, but may be replaced by any object that implements urlparse.urlparse() and urlparse.urlunparse().
Messages
Emitted for an unparseable URL.
Emitted if URL is missing a part present in required_parts.
Emitted if URL contains a part present in forbidden_parts.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|
Bases: flatland.validation.base.Validator
A URL canonicalizing validator.
Given a valid URL, re-writes it with unwanted parts removed. The default implementation drops the #fragment from the URL, if present.
Attributes
A sequence of 0 or more part names in urlparse‘s vocabulary:
'scheme', 'netloc', 'path', 'params', 'query', 'fragment'
By default the urlparse module, but may be replaced by any object that implements urlparse.urlparse() and urlparse.urlunparse().
Messages
Emitted for an unparseable URL. This is impossible to hit with the Python’s standard library implementation of urlparse.
Construct a validator.
Parameters: | **kw – override any extant class attribute on this instance. |
---|