validations.py 文件源码

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

项目:drf-url-filters 作者: manjitkumar 项目源码 文件源码
def __call__(self, value):
        '''
        Checks whether a value is list of given validation_function.
        Returns list of validated values or just one valid value in
        list if there is only one element in given CSV string.
        '''
        try:
            if isinstance(value, basestring):
                if self.separator in value:
                    seperated_string_values =[item.strip() for item
                        in value.split(self.separator)]
                    values = [self.validation_function(item) for item
                        in seperated_string_values]
                else:
                    values = [self.validation_function(value)]
                return values
            else:
                raise ValueError
        except (Invalid, ValueError) as e:
            raise Invalid(self.msg or
                ('<{0}> is not valid set of <{1}>, {2}'.format(
                    value,
                    self.value_type,
                        e)))
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号