validators.py 文件源码

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

项目:wypok 作者: arturtamborski 项目源码 文件源码
def __call__(self, data):
        if self.max_size is not None and data.size > self.max_size:
            params = {
                'max_size': filesizeformat(self.max_size),
                'size': filesizeformat(data.size),
            }
            raise ValidationError(self.error_messages['max_size'], 'max_size', params)

        if self.min_size is not None and data.size < self.min_size:
            params = {
                'min_size': filesizeformat(self.mix_size),
                'size': filesizeformat(data.size)
            }
            raise ValidationError(self.error_messages['min_size'], 'min_size', params)

        if self.content_types is not None and len(self.content_types):
            content_type = magic.from_buffer(data.read(), mime=True)
            data.seek(0) # seek to start for future mime checks by django

            if content_type not in self.content_types:
                params = {
                    'content_type': content_type
                }
                raise ValidationError(self.error_messages['content_type'], 'content_type', params)
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号