예제 #1
0
파일: jstraitlets.py 프로젝트: yibit/altair
    def _validate_string_length(self, obj, value):
        if self.minLength is not None and len(value) < self.minLength:
            raise T.TraitError(
                "The value of the '{name}' trait of {klass} instance should "
                "not be shorter than {minLength}, but a value of {value} was "
                "specified".format(
                    name=self.name, klass=class_of(obj),
                    value=value, minLength=self.minLength))

        if self.maxLength is not None and len(value) > self.maxLength:
            raise T.TraitError(
                "The value of the '{name}' trait of {klass} instance should "
                "not be longer than {maxLength}, but a value of {value} was "
                "specified".format(
                    name=self.name, klass=class_of(obj),
                    value=value, maxLength=self.maxLength))
        return value
예제 #2
0
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
예제 #3
0
 def validate(self, obj, value):
     if self.allow_undefined and value is undefined:
         return value
     value = super(JSONArray, self).validate(obj, value)
     if self.uniqueItems and not _has_unique_elements(value):
         raise T.TraitError(
             "The value of the '{name}' trait of {klass} instance should "
             "have unique elements".format(name=self.name,
                                           klass=class_of(obj)))
     return value