How to use the cerberus.errors.BaseErrorHandler 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
def __init_error_handler(kwargs):
        error_handler = kwargs.pop('error_handler', errors.BasicErrorHandler)
        if isinstance(error_handler, tuple):
            error_handler, eh_config = error_handler
        else:
            eh_config = {}
        if isinstance(error_handler, type) and issubclass(
            error_handler, errors.BaseErrorHandler
        ):
            return error_handler(**eh_config)
        elif isinstance(error_handler, errors.BaseErrorHandler):
            return error_handler
        else:
            raise RuntimeError('Invalid error_handler.')
github pyeve / cerberus / cerberus / validator.py View on Github external
def __init_error_handler(kwargs):
        error_handler = kwargs.pop('error_handler', errors.BasicErrorHandler)
        if isinstance(error_handler, tuple):
            error_handler, eh_config = error_handler
        else:
            eh_config = {}
        if isinstance(error_handler, type) and issubclass(
            error_handler, errors.BaseErrorHandler
        ):
            return error_handler(**eh_config)
        elif isinstance(error_handler, errors.BaseErrorHandler):
            return error_handler
        else:
            raise RuntimeError('Invalid error_handler.')
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
def __init_error_handler(kwargs):
        error_handler = kwargs.pop('error_handler', errors.BasicErrorHandler)
        if isinstance(error_handler, tuple):
            error_handler, eh_config = error_handler
        else:
            eh_config = {}
        if isinstance(error_handler, type) and issubclass(
            error_handler, errors.BaseErrorHandler
        ):
            return error_handler(**eh_config)
        elif isinstance(error_handler, errors.BaseErrorHandler):
            return error_handler
        else:
            raise RuntimeError('Invalid error_handler.')
github pyeve / cerberus / cerberus / errors.py View on Github external
pass

    def extend(self, errors: Iterable[ValidationError]) -> None:
        """ Adds all errors to the handler's container object. """
        for error in errors:
            self.add(error)

    def start(self, validator: "UnconcernedValidator") -> None:
        """ Gets called when a validation starts.

        :param validator: The calling validator.
        """
        pass


class ToyErrorHandler(BaseErrorHandler):
    def __call__(self, *args, **kwargs):
        raise RuntimeError('This is not supposed to happen.')

    add = __call__


class BasicErrorHandler(BaseErrorHandler):
    """ Models cerberus' legacy. Returns a :class:`dict`. When mangled
        through :class:`str` a pretty-formatted representation of that
        tree is returned.
    """

    messages = {
        0x00: "{0}",
        0x01: "document is missing",
        0x02: "required field",
github pyeve / cerberus / cerberus / errors.py View on Github external
def start(self, validator: "UnconcernedValidator") -> None:
        """ Gets called when a validation starts.

        :param validator: The calling validator.
        """
        pass


class ToyErrorHandler(BaseErrorHandler):
    def __call__(self, *args, **kwargs):
        raise RuntimeError('This is not supposed to happen.')

    add = __call__


class BasicErrorHandler(BaseErrorHandler):
    """ Models cerberus' legacy. Returns a :class:`dict`. When mangled
        through :class:`str` a pretty-formatted representation of that
        tree is returned.
    """

    messages = {
        0x00: "{0}",
        0x01: "document is missing",
        0x02: "required field",
        0x03: "unknown field",
        0x04: "field '{0}' is required",
        0x05: "depends on these values: {constraint}",
        0x06: "{0} must not be present with '{field}'",
        0x21: "'{0}' is not a document, must be a dict",
        0x22: "empty values not allowed",
        0x23: "null value not allowed",
github pyeve / cerberus / cerberus / base.py View on Github external
def __init_error_handler(config: ErrorHandlerConfig) -> errors.BaseErrorHandler:
        if isinstance(config, errors.BaseErrorHandler):
            return config

        if isinstance(config, tuple):
            error_handler, eh_config = config

        else:
            error_handler, eh_config = config, {}

        if isinstance(error_handler, type) and issubclass(
            error_handler, errors.BaseErrorHandler
        ):
            return error_handler(**eh_config)

        else:
            raise RuntimeError('Invalid error_handler configuration.')
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
def __init_error_handler(kwargs):
        error_handler = kwargs.pop('error_handler', errors.BasicErrorHandler)
        if isinstance(error_handler, tuple):
            error_handler, eh_config = error_handler
        else:
            eh_config = {}
        if isinstance(error_handler, type) and issubclass(
            error_handler, errors.BaseErrorHandler
        ):
            return error_handler(**eh_config)
        elif isinstance(error_handler, errors.BaseErrorHandler):
            return error_handler
        else:
            raise RuntimeError('Invalid error_handler.')