OpenQuizz
Une application de gestion des contenus pédagogiques
|
Data Structures | |
class | _DeepIterable |
class | _DeepMapping |
class | _InstanceOfValidator |
class | _InValidator |
class | _IsCallableValidator |
class | _MatchesReValidator |
class | _OptionalValidator |
class | _ProvidesValidator |
Functions | |
def | instance_of (type) |
def | matches_re (regex, flags=0, func=None) |
def | provides (interface) |
def | optional (validator) |
def | in_ (options) |
def | is_callable () |
def | deep_iterable (member_validator, iterable_validator=None) |
def | deep_mapping (key_validator, value_validator, mapping_validator=None) |
Variables | |
repr | |
False | |
slots | |
True | |
hash | |
Commonly useful validators.
def attr.validators.deep_iterable | ( | member_validator, | |
iterable_validator = None |
|||
) |
A validator that performs deep validation of an iterable. :param member_validator: Validator to apply to iterable members :param iterable_validator: Validator to apply to iterable itself (optional) .. versionadded:: 19.1.0 :raises TypeError: if any sub-validators fail
def attr.validators.deep_mapping | ( | key_validator, | |
value_validator, | |||
mapping_validator = None |
|||
) |
A validator that performs deep validation of a dictionary. :param key_validator: Validator to apply to dictionary keys :param value_validator: Validator to apply to dictionary values :param mapping_validator: Validator to apply to top-level mapping attribute (optional) .. versionadded:: 19.1.0 :raises TypeError: if any sub-validators fail
def attr.validators.in_ | ( | options | ) |
A validator that raises a `ValueError` if the initializer is called with a value that does not belong in the options provided. The check is performed using ``value in options``. :param options: Allowed options. :type options: list, tuple, `enum.Enum`, ... :raises ValueError: With a human readable error message, the attribute (of type `attr.Attribute`), the expected options, and the value it got. .. versionadded:: 17.1.0
def attr.validators.instance_of | ( | type | ) |
A validator that raises a `TypeError` if the initializer is called with a wrong type for this particular attribute (checks are performed using `isinstance` therefore it's also valid to pass a tuple of types). :param type: The type to check for. :type type: type or tuple of types :raises TypeError: With a human readable error message, the attribute (of type `attr.Attribute`), the expected type, and the value it got.
def attr.validators.is_callable | ( | ) |
A validator that raises a `attr.exceptions.NotCallableError` if the initializer is called with a value for this particular attribute that is not callable. .. versionadded:: 19.1.0 :raises `attr.exceptions.NotCallableError`: With a human readable error message containing the attribute (`attr.Attribute`) name, and the value it got.
def attr.validators.matches_re | ( | regex, | |
flags = 0 , |
|||
func = None |
|||
) |
A validator that raises `ValueError` if the initializer is called with a string that doesn't match *regex*. :param str regex: a regex string to match against :param int flags: flags that will be passed to the underlying re function (default 0) :param callable func: which underlying `re` function to call (options are `re.fullmatch`, `re.search`, `re.match`, default is ``None`` which means either `re.fullmatch` or an emulation of it on Python 2). For performance reasons, they won't be used directly but on a pre-`re.compile`\ ed pattern. .. versionadded:: 19.2.0
def attr.validators.optional | ( | validator | ) |
A validator that makes an attribute optional. An optional attribute is one which can be set to ``None`` in addition to satisfying the requirements of the sub-validator. :param validator: A validator (or a list of validators) that is used for non-``None`` values. :type validator: callable or `list` of callables. .. versionadded:: 15.1.0 .. versionchanged:: 17.1.0 *validator* can be a list of validators.
def attr.validators.provides | ( | interface | ) |
A validator that raises a `TypeError` if the initializer is called with an object that does not provide the requested *interface* (checks are performed using ``interface.providedBy(value)`` (see `zope.interface <https://zopeinterface.readthedocs.io/en/latest/>`_). :param interface: The interface to check for. :type interface: ``zope.interface.Interface`` :raises TypeError: With a human readable error message, the attribute (of type `attr.Attribute`), the expected interface, and the value it got.
False |
hash |
repr |
slots |
True |