schema.py 文件源码

python
阅读 19 收藏 0 点赞 0 评论 0

项目:QualquerMerdaAPI 作者: tiagovizoto 项目源码 文件源码
def error_handler(cls, func):
        """Decorator that registers an error handler function for the schema.
        The function receives the :class:`Schema` instance, a dictionary of errors,
        and the serialized object (if serializing data) or data dictionary (if
        deserializing data) as arguments.

        Example: ::

            class UserSchema(Schema):
                email = fields.Email()

            @UserSchema.error_handler
            def handle_errors(schema, errors, obj):
                raise ValueError('An error occurred while marshalling {}'.format(obj))

            user = User(email='invalid')
            UserSchema().dump(user)  # => raises ValueError
            UserSchema().load({'email': 'bademail'})  # raises ValueError

        .. versionadded:: 0.7.0
        .. deprecated:: 2.0.0
            Set the ``error_handler`` class Meta option instead.
        """
        warnings.warn(
            'Schema.error_handler is deprecated. Set the error_handler class Meta option '
            'instead.', category=DeprecationWarning
        )
        cls.__error_handler__ = func
        return func
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号