schema.py 文件源码

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

项目:storjnet 作者: StorjRND 项目源码 文件源码
def _validate_subscription_number(key, value, description):
    if not isinstance(value, list):
        raise jsonschema.exceptions.ValidationError(
            "{0} value not a list.".format(key)
        )
    if len(value) != 2:
        raise jsonschema.exceptions.ValidationError(
            "{0} value {1} does not have two entries.".format(key, value)
        )
    try:
        lower = Decimal(value[0])
        upper = Decimal(value[1])
    except InvalidOperation:
        raise jsonschema.exceptions.ValidationError(
            "{0} values {1} not numbers.".format(key, value)
        )
    minimum = Decimal(description["minimum"])
    maximum = Decimal(description["maximum"])
    if not (minimum <= lower <= upper < maximum):  # maximum is exclusive
        raise jsonschema.exceptions.ValidationError(
            "{0} values {1} not in limits: {2} <= {4} <= {5} < {3}.".format(
                key, value, minimum, maximum, lower, upper
            )
        )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号