How to use the cerberus.utils.TypeDefinition function in Cerberus

To help you get started, we’ve selected a few Cerberus examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github pyeve / cerberus / cerberus / validator.py View on Github external
""" Rules that are evaluated on any field, regardless whether defined in
        the schema or not.
        Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """

    def __init__(self, *args, **kwargs):
        """ The arguments will be treated as with this signature:

        __init__(self, schema=None, ignore_none_values=False,
                 allow_unknown=False, purge_unknown=False,
                 error_handler=errors.BasicErrorHandler)
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
:class:`tuple`
    """  # noqa: E501

    mandatory_validations = ('nullable',)
    """ Rules that are evaluated on any field, regardless whether defined in
        the schema or not.
        Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """

    def __init__(self, *args, **kwargs):
        """ The arguments will be treated as with this signature:
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """

    def __init__(self, *args, **kwargs):
        """ The arguments will be treated as with this signature:

        __init__(self, schema=None, ignore_none_values=False,
                 allow_unknown=False, require_all=False,
                 purge_unknown=False, purge_readonly=False,
                 error_handler=errors.BasicErrorHandler)
        """
github pyeve / cerberus / cerberus / __init__.py View on Github external
"""

from __future__ import absolute_import

from cerberus.validator import DocumentError, Validator
from cerberus.schema import rules_set_registry, schema_registry, SchemaError
from cerberus.utils import TypeDefinition


__version__ = "1.2"

__all__ = [
    DocumentError.__name__,
    SchemaError.__name__,
    TypeDefinition.__name__,
    Validator.__name__,
    'schema_registry',
    'rules_set_registry',
]
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
initialization of the error handler.
                          Default: :class:`~cerberus.errors.BasicErrorHandler`.
    :type error_handler: class or instance based on
                         :class:`~cerberus.errors.BaseErrorHandler` or
                         :class:`tuple`
    """  # noqa: E501

    mandatory_validations = ('nullable',)
    """ Rules that are evaluated on any field, regardless whether defined in
        the schema or not.
        Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
github pyeve / cerberus / cerberus / validator.py View on Github external
Default: :class:`~cerberus.errors.BasicErrorHandler`.
    :type error_handler: class or instance based on
                         :class:`~cerberus.errors.BaseErrorHandler` or
                         :class:`tuple`
    """  # noqa: E501

    mandatory_validations = ('nullable',)
    """ Rules that are evaluated on any field, regardless whether defined in
        the schema or not.
        Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
mandatory_validations = ('nullable',)
    """ Rules that are evaluated on any field, regardless whether defined in
        the schema or not.
        Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """

    def __init__(self, *args, **kwargs):
        """ The arguments will be treated as with this signature:

        __init__(self, schema=None, ignore_none_values=False,
                 allow_unknown=False, require_all=False,
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """

    def __init__(self, *args, **kwargs):
        """ The arguments will be treated as with this signature:

        __init__(self, schema=None, ignore_none_values=False,
                 allow_unknown=False, require_all=False,
                 purge_unknown=False, purge_readonly=False,
                 error_handler=errors.BasicErrorHandler)
        """
github pyeve / cerberus / cerberus / validator.py View on Github external
:class:`~cerberus.errors.BaseErrorHandler` or
                         :class:`tuple`
    """  # noqa: E501

    mandatory_validations = ('nullable',)
    """ Rules that are evaluated on any field, regardless whether defined in
        the schema or not.
        Type: :class:`tuple` """
    priority_validations = ('nullable', 'readonly', 'type', 'empty')
    """ Rules that will be processed in that order before any other.
        Type: :class:`tuple` """
    types_mapping = {
        'binary': TypeDefinition('binary', (bytes, bytearray), ()),
        'boolean': TypeDefinition('boolean', (bool,), ()),
        'container': TypeDefinition('container', (Container,), (_str_type,)),
        'date': TypeDefinition('date', (date,), ()),
        'datetime': TypeDefinition('datetime', (datetime,), ()),
        'dict': TypeDefinition('dict', (Mapping,), ()),
        'float': TypeDefinition('float', (float, _int_types), ()),
        'integer': TypeDefinition('integer', (_int_types,), ()),
        'list': TypeDefinition('list', (Sequence,), (_str_type,)),
        'number': TypeDefinition('number', (_int_types, float), (bool,)),
        'set': TypeDefinition('set', (set,), ()),
        'string': TypeDefinition('string', (_str_type), ()),
    }
    """ This mapping holds all available constraints for the type rule and
        their assigned :class:`~cerberus.TypeDefinition`. """
    _valid_schemas = set()
    """ A :class:`set` of hashes derived from validation schemas that are
        legit for a particular ``Validator`` class. """

    def __init__(self, *args, **kwargs):