Ejemplo n.º 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)
Ejemplo n.º 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))
Ejemplo n.º 3
0
 def validate(self):
     raise errors.ValidationError()
Ejemplo n.º 4
0
 def validator2(value):
     if value == 'foo':
         raise errors.ValidationError()
Ejemplo n.º 5
0
 def validate(self, value):
     if not isinstance(value, bool):
         raise errors.ValidationError('should be a boolean')
Ejemplo n.º 6
0
 def validate(self, value):
     if not isinstance(value, float):
         raise errors.ValidationError('should be a float')
Ejemplo n.º 7
0
 def validate(self, value):
     if not isinstance(value, int):
         raise errors.ValidationError('should be an integer')
Ejemplo n.º 8
0
 def validate(self, value):
     if not isinstance(value, str):
         raise errors.ValidationError('should be a string')
Ejemplo n.º 9
0
 def validate(self, value):
     if value not in self.choices:
         raise errors.ValidationError('should be in {}'.format(self.choices))
Ejemplo n.º 10
0
 def validate(self, value):
     if value is None:
         raise errors.ValidationError('is required')
Ejemplo n.º 11
0
 def validate(self, value):
     if not isinstance(value, datetime.datetime):
         raise errors.ValidationError('should be a datetime')
Ejemplo n.º 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')
Ejemplo n.º 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()
Ejemplo n.º 14
0
 def inner_validator(value):
     if value == 'bar':
         raise errors.ValidationError('invalid')
Ejemplo n.º 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')
Ejemplo n.º 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')