def _validate_numeric(trait, obj, value,
minimum=undefined, maximum=undefined,
exclusiveMinimum=undefined, exclusiveMaximum=undefined,
multipleOf=undefined, **extra_kwds):
if value is None:
return value
if minimum is not undefined:
exclusive = exclusiveMinimum is not undefined and exclusiveMinimum
if value < minimum or (exclusive and value == minimum):
raise T.TraitError(
"The value of the '{name}' trait of {klass} instance should "
"not be less than {min_bound}, but a value of {value} was "
"specified".format(
name=trait.name, klass=class_of(obj),
value=value, min_bound=minimum))
if maximum is not undefined:
exclusive = exclusiveMaximum is not undefined and exclusiveMaximum
if value > maximum or (exclusive and value == maximum):
raise T.TraitError(
"The value of the '{name}' trait of {klass} instance should "
"not be greater than {max_bound}, but a value of {value} was "
"specified".format(
name=trait.name, klass=class_of(obj),
value=value, max_bound=maximum))
if multipleOf is not undefined:
if value % multipleOf != 0:
raise T.TraitError(
"The value of the '{name}' trait of {klass} instance should "
"be a multiple of {multiple}, but a value of {value} was "
"specified".format(
name=trait.name, klass=class_of(obj),
value=value, multiple=multipleOf))
return value
评论列表
文章目录