def validate(self, value): original_value = value # So isinstance(True, int) -> True. # For a float parameter we should not allow a bool. if isinstance(value, bool): raise ValidationError(value=str(value), type_name='float', param=self) elif not isinstance(value, float): # If the value is a float, that's good enough for a float # param. Also you can't go directly from a float -> Decimal # in python2.6. # Otherwise the value has to look like a decimal, # so we just need to validate that it converts to a # decimal without issue and then run it through the min # max range validations. try: # We don't want to type convert here, but we need # to convert it to something we can use < and > against. value = decimal.Decimal(value) except (decimal.InvalidOperation, TypeError): raise ValidationError(value=str(value), type_name='float', param=self) if self.min: if value < self.min: raise RangeError(value=value, param=self, min_value=self.min, max_value=self.max) if self.max: if value > self.max: raise RangeError(value=value, param=self, min_value=self.min, max_value=self.max) return original_value
def validate(self, value): if not isinstance(value, float): raise ValidationError(value=str(value), type_name='double', param=self) if self.min: if value < self.min: raise RangeError(value=value, param=self, min_value=self.min, max_value=self.max) if self.max: if value > self.max: raise RangeError(value=value, param=self, min_value=self.min, max_value=self.max) return value
def validate(self, value): if not isinstance(value, six.integer_types): raise ValidationError(value=str(value), type_name='integer', param=self) if self.min: if value < self.min: raise RangeError(value=value, param=self, min_value=self.min, max_value=self.max) if self.max: if value > self.max: raise RangeError(value=value, param=self, min_value=self.min, max_value=self.max) return value
def validate(self, value): if not isinstance(value, six.string_types): raise ValidationError(value=str(value), type_name='string', param=self) if self.min: if len(value) < self.min: raise RangeError(value=len(value), param=self, min_value=self.min, max_value=self.max) if self.max: if len(value) > self.max: raise RangeError(value=len(value), param=self, min_value=self.min, max_value=self.max) return value