How to use the cerberus.errors.COERCION_FAILED 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 / base.py View on Github external
def __normalize_coerce(self, processor, field, value, nullable, error):
        if isinstance(processor, str):
            processor = self.__get_rule_handler('normalize_coerce', processor)

        elif isinstance(processor, Iterable):
            result = value
            for p in processor:
                result = self.__normalize_coerce(p, field, result, nullable, error)
                if (
                    errors.COERCION_FAILED
                    in self.document_error_tree.fetch_errors_from(
                        self.document_path + (field,)
                    )
                ):
                    break
            return result

        try:
            return processor(value)
        except Exception as e:
            if not (nullable and value is None):
                self._error(field, error, str(e))
            return value
github pyeve / cerberus / cerberus / validator.py View on Github external
def __normalize_coerce(self, processor, field, value, nullable, error):
        if isinstance(processor, _str_type):
            processor = self.__get_rule_handler('normalize_coerce', processor)

        elif isinstance(processor, Iterable):
            result = value
            for p in processor:
                result = self.__normalize_coerce(p, field, result, nullable, error)
                if (
                    errors.COERCION_FAILED
                    in self.document_error_tree.fetch_errors_from(
                        self.document_path + (field,)
                    )
                ):
                    break
            return result

        try:
            return processor(value)
        except Exception as e:
            if not nullable and e is not TypeError:
                self._error(field, error, str(e))
            return value
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
def __normalize_coerce(self, processor, field, value, nullable, error):
        if isinstance(processor, _str_type):
            processor = self.__get_rule_handler('normalize_coerce', processor)

        elif isinstance(processor, Iterable):
            result = value
            for p in processor:
                result = self.__normalize_coerce(p, field, result, nullable, error)
                if (
                    errors.COERCION_FAILED
                    in self.document_error_tree.fetch_errors_from(
                        self.document_path + (field,)
                    )
                ):
                    break
            return result

        try:
            return processor(value)
        except Exception as e:
            if not (nullable and value is None):
                self._error(field, error, str(e))
            return value
github pypa / pipenv / pipenv / vendor / cerberus / validator.py View on Github external
def _normalize_coerce(self, mapping, schema):
        """ {'oneof': [
                {'type': 'callable'},
                {'type': 'list',
                 'schema': {'oneof': [{'type': 'callable'},
                                      {'type': 'string'}]}},
                {'type': 'string'}
                ]} """

        error = errors.COERCION_FAILED
        for field in mapping:
            if field in schema and 'coerce' in schema[field]:
                mapping[field] = self.__normalize_coerce(
                    schema[field]['coerce'],
                    field,
                    mapping[field],
                    schema[field].get('nullable', False),
                    error,
                )
            elif (
                isinstance(self.allow_unknown, Mapping)
                and 'coerce' in self.allow_unknown
            ):
                mapping[field] = self.__normalize_coerce(
                    self.allow_unknown['coerce'],
                    field,
github pyeve / cerberus / cerberus / validator.py View on Github external
def _normalize_coerce(self, mapping, schema):
        """ {'oneof': [
                {'type': 'callable'},
                {'type': 'list',
                 'schema': {'oneof': [{'type': 'callable'},
                                      {'type': 'string'}]}},
                {'type': 'string'}
                ]} """

        error = errors.COERCION_FAILED
        for field in mapping:
            if field in schema and 'coerce' in schema[field]:
                mapping[field] = self.__normalize_coerce(
                    schema[field]['coerce'],
                    field,
                    mapping[field],
                    schema[field].get('nullable', False),
                    error,
                )
            elif (
                isinstance(self.allow_unknown, Mapping)
                and 'coerce' in self.allow_unknown
            ):
                mapping[field] = self.__normalize_coerce(
                    self.allow_unknown['coerce'],
                    field,
github pyeve / cerberus / cerberus / base.py View on Github external
def _normalize_coerce(self, mapping, schema):
        """ {'oneof': [
                {'type': 'callable'},
                {'type': 'list',
                 'itemsrules': {'oneof': [{'type': 'callable'},
                                          {'type': 'string'}]}},
                {'type': 'string'}
                ]} """

        error = errors.COERCION_FAILED
        for field in mapping:
            if field in schema and 'coerce' in schema[field]:
                mapping[field] = self.__normalize_coerce(
                    schema[field]['coerce'],
                    field,
                    mapping[field],
                    schema[field].get('nullable', False),
                    error,
                )
            elif (
                isinstance(self.allow_unknown, Mapping)
                and 'coerce' in self.allow_unknown
            ):
                mapping[field] = self.__normalize_coerce(
                    self.allow_unknown['coerce'],
                    field,