def validate(self, value): if value is None and self._does_allow_none(): return None if type(value) is datetime.date: return value if type(value) is datetime.datetime: return datetime.date(value.year, value.month, value.day) if isinstance(value, datetime.date) or isinstance(value, datetime.datetime): return datetime.date(value.year, value.month, value.day) try: dt = parse_datetime(value) if dt: return datetime.date(dt.year, dt.month, dt.day) except (ValueError, TypeError): dt = None if not dt: try: dt = parse_date(value) except (ValueError, TypeError): raise FieldValidationError(FieldError(self, 'invalid')) if dt: return dt raise FieldValidationError(FieldError(self, 'invalid'))
def validate(self, value): if value is None and self._does_allow_none(): return None if type(value) is not str or str(value) != value: raise FieldValidationError(FieldError(self, 'invalid')) if self.trim: value = value.strip() if not value and not self.allow_empty: raise FieldValidationError(FieldError(self, 'empty')) return value
def validate(self, value): if value is None and self._does_allow_none(): return None schema = self.cached or self._get_schema() if not hasattr(value, '__dict__') and (type(value) is not dict or not isinstance(value, dict)): raise FieldValidationError(FieldError(self, 'invalid_mapping')) try: return schema.validate(value, exclude=self.exclude, whitelist=self.whitelist, tags=self.tags, halt_on_error=self._schema.halt_on_error) except ValidationError: raise FieldValidationError(FieldError(self, 'invalid', errors=schema._raw_errors))
def validate(self, value): if value is None and self._does_allow_none(): return None if isinstance(value, datetime.date): return value try: dt = parse_datetime(value) if dt: return dt raise FieldValidationError(FieldError(self, 'invalid')) except (ValueError, TypeError): raise FieldValidationError(FieldError(self, 'invalid'))
def validate(self, value): if value is None and self._does_allow_none(): return None if type(value) is int: return value try: if not float(value).is_integer(): raise FieldValidationError(FieldError(self, 'invalid')) except (TypeError, ValueError): raise FieldValidationError(FieldError(self, 'invalid')) try: if int(value) != value or type(value) is bool: raise FieldValidationError(FieldError(self, 'invalid')) except ValueError: raise FieldValidationError(FieldError(self, 'invalid')) return value
def validate(self, value): if value is None and self._does_allow_none(): return None if type(value) is float: return value if type(value) in (bool, str): raise FieldValidationError(FieldError(self, 'invalid')) try: float(value) is value except TypeError: raise FieldValidationError(FieldError(self, 'invalid')) if self.strict: try: value.is_integer() except AttributeError: raise FieldValidationError(FieldError(self, 'invalid')) return value
def validate(self, value): self.field._schema = self._schema if value is None and self._does_allow_none(): return None valid = [] errors = {} if not isinstance(value, list): raise FieldValidationError(FieldError(self, 'invalid')) for k, v in enumerate(value): try: valid.append(self.field.validate(v)) except FieldValidationError as field_exc: errors[str(k)] = field_exc.error if self._schema.halt_on_error: break if errors: raise FieldValidationError(FieldError(self, 'invalid_item', errors=errors)) return valid
def validate(self, value): if value is None and self._does_allow_none(): return None try: return uuid.UUID(value) except (ValueError, AttributeError, TypeError): pass if isinstance(value, uuid.UUID): return value raise FieldValidationError(FieldError(self, 'invalid'))
def validate(self, value): if value is None and self._does_allow_none(): return None valid = False for field in self.fieldset: field._schema = self._schema try: value = field.validate(value) valid = True break except Exception: continue if not valid: raise FieldValidationError(FieldError(self, 'invalid')) return value
def validate(self, value): if value is None and self._does_allow_none(): return None if not isinstance(value, dict): raise FieldValidationError(FieldError(self, 'invalid')) return value
def validate(self, value): if value is None and self._does_allow_none(): return None if type(value) is not bool: raise FieldValidationError(FieldError(self, 'invalid')) return value
def not_bella(self, value, field=None, **kwargs): if value == 'bella': raise FieldValidationError(FieldError(field, 'invalid')) return value
def not_fiona(value, schema=None, field=None): if value == 'fiona': raise FieldValidationError(FieldError(field, 'invalid')) return value
def not_fiona(value, **kwargs): if value == 'fiona': raise FieldValidationError(FieldError(self, 'invalid')) return value
def validate_mark(value, schema=None, field=None): if value == 'mark': return value raise FieldValidationError(FieldError(field, 'invalid'))