コード例 #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)
コード例 #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))
コード例 #3
0
ファイル: test_validators.py プロジェクト: makkus/booby
 def validate(self):
     raise errors.ValidationError()
コード例 #4
0
ファイル: test_field.py プロジェクト: makkus/booby
 def validator2(value):
     if value == 'foo':
         raise errors.ValidationError()
コード例 #5
0
 def validate(self, value):
     if not isinstance(value, bool):
         raise errors.ValidationError('should be a boolean')
コード例 #6
0
 def validate(self, value):
     if not isinstance(value, float):
         raise errors.ValidationError('should be a float')
コード例 #7
0
 def validate(self, value):
     if not isinstance(value, int):
         raise errors.ValidationError('should be an integer')
コード例 #8
0
 def validate(self, value):
     if not isinstance(value, str):
         raise errors.ValidationError('should be a string')
コード例 #9
0
 def validate(self, value):
     if value not in self.choices:
         raise errors.ValidationError('should be in {}'.format(self.choices))
コード例 #10
0
 def validate(self, value):
     if value is None:
         raise errors.ValidationError('is required')
コード例 #11
0
 def validate(self, value):
     if not isinstance(value, datetime.datetime):
         raise errors.ValidationError('should be a datetime')
コード例 #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')
コード例 #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()
コード例 #14
0
ファイル: test_list.py プロジェクト: jvrsantacruz/booby
 def inner_validator(value):
     if value == 'bar':
         raise errors.ValidationError('invalid')
コード例 #15
0
ファイル: validators.py プロジェクト: jgissend10/booby
    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')
コード例 #16
0
ファイル: validators.py プロジェクト: jgissend10/booby
    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')