Beispiel #1
0
    def validate(self, value):
        if not isinstance(value, collections.MutableSequence):
            raise errors.ValidationError('should be a list')

        for i in value:
            for validator in self.validators:
                validator(i)
Beispiel #2
0
    def validate(self):
        """This method validates the entire `model`. That is, validates
        all the :mod:`fields` within this model.

        If some `field` validation fails, then this method raises the same
        exception that the :func:`field.validate` method had raised, but
        with the field name prepended.

        """

        for name, field in self._fields.items():
            try:
                field.validate(getattr(self, name))
            except errors.ValidationError as err:
                raise errors.ValidationError('%s %s' % (name, err))
Beispiel #3
0
 def validate(self):
     raise errors.ValidationError()
Beispiel #4
0
 def validator2(value):
     if value == 'foo':
         raise errors.ValidationError()
Beispiel #5
0
 def validate(self, value):
     if not isinstance(value, bool):
         raise errors.ValidationError('should be a boolean')
Beispiel #6
0
 def validate(self, value):
     if not isinstance(value, float):
         raise errors.ValidationError('should be a float')
Beispiel #7
0
 def validate(self, value):
     if not isinstance(value, int):
         raise errors.ValidationError('should be an integer')
Beispiel #8
0
 def validate(self, value):
     if not isinstance(value, str):
         raise errors.ValidationError('should be a string')
Beispiel #9
0
 def validate(self, value):
     if value not in self.choices:
         raise errors.ValidationError('should be in {}'.format(self.choices))
Beispiel #10
0
 def validate(self, value):
     if value is None:
         raise errors.ValidationError('is required')
Beispiel #11
0
 def validate(self, value):
     if not isinstance(value, datetime.datetime):
         raise errors.ValidationError('should be a datetime')
Beispiel #12
0
    def validate(self, value):
        super(Email, self).validate(value)

        if self.pattern.match(value) is None:
            raise errors.ValidationError('should be a valid email')
Beispiel #13
0
    def validate(self, value):
        if not isinstance(value, self.model):
            raise errors.ValidationError(
                "should be an instance of '{}'".format(self.model.__name__))

        value.validate()
Beispiel #14
0
 def inner_validator(value):
     if value == 'bar':
         raise errors.ValidationError('invalid')
Beispiel #15
0
    def validate(self, value):
        super(URI, self).validate(value)

        if self.uri_regex.match(value) is None:
            raise errors.ValidationError('should be a valid URI')
Beispiel #16
0
    def validate(self, value):
        super(IP, self).validate(value)

        if self.ipv4.match(value) is None and self.ipv6 is None:
            raise errors.ValidationError(
                'should be a valid IPv4 or IPv6 address')