def _validate(self, value): super(JSONField, self)._validate(value) try: jsonschema.validate(value, self.json_schema) except jsonschema.ValidationError as e: raise WrongContainedType(e.message, self.__name__)
def _validate(self, value): super(AbstractCollection, self)._validate(value) errors = _validate_sequence(self.value_type, value) if errors: raise WrongContainedType(errors, self.__name__) if self.unique: _validate_uniqueness(value)
def _validate(self, value): # XXX HACK: Can't call the super, since it'll check to # XXX see if we provide DictRow. # We're only a dict, so we can't. # super(DictRow, self)._validate(value) # Validate the dict against the schema # Pass 1 - ensure fields are present if value is NO_VALUE: return # Treat readonly fields for field_name in getFields(self.schema).keys(): field = self.schema[field_name] if field.readonly: value[field_name] = field.default errors = [] for field_name in getFields(self.schema).keys(): if field_name not in value: errors.append(AttributeNotFoundError(field_name, self.schema)) if errors: raise WrongContainedType(errors, self.__name__) # Pass 2 - Ensure fields are valid for field_name, field_type in getFields(self.schema).items(): if IChoice.providedBy(field_type): # Choice must be bound before validation otherwise # IContextSourceBinder is not iterable in validation bound = field_type.bind(value) bound.validate(value[field_name]) else: field_type.validate(value[field_name])
def validate(self, value): value = json.loads(value) for day in value: for section in value[day]: if section == 'comment': continue error = self._validate_format(value[day][section]) if error: raise WrongContainedType(error, self.__name__)
def _validate(self, value): super(Object, self)._validate(value) # schema has to be provided by value if not self.schema.providedBy(value): raise SchemaNotProvided # check the value against schema errors = _validate_fields(self.schema, value) if errors: raise WrongContainedType(errors, self.__name__)
def _validate(self, value): super(Collection, self)._validate(value) errors = _validate_sequence(self.value_type, value) if errors: try: raise WrongContainedType(errors, self.__name__).with_field_and_value(self, value) finally: # Break cycles del errors if self.unique: _validate_uniqueness(self, value)
def _validate(self, value): super(Dict, self)._validate(value) errors = [] try: if self.value_type: errors = _validate_sequence(self.value_type, value.values(), errors) errors = _validate_sequence(self.key_type, value, errors) if errors: raise WrongContainedType(errors, self.__name__) finally: errors = None
def _validate(self, value): super(Mapping, self)._validate(value) errors = [] if self.value_type: errors = _validate_sequence(self.value_type, value.values(), errors) errors = _validate_sequence(self.key_type, value, errors) if errors: try: raise WrongContainedType(errors, self.__name__).with_field_and_value(self, value) finally: # Break cycles del errors
def _validate(self, value): # XXX HACK: Can't call the super, since it'll check to # XXX see if we provide DictRow. # We're only a dict, so we can't. # super(DictRow, self)._validate(value) # Validate the dict against the schema # Pass 1 - ensure fields are present if value is NO_VALUE: return errors = [] for field_name in getFields(self.schema).keys(): if field_name not in value: errors.append(AttributeNotFoundError(field_name, self.schema)) if errors: raise WrongContainedType(errors, self.__name__) # Pass 2 - Ensure fields are valid for field_name, field_type in getFields(self.schema).items(): field_type.validate(value[field_name])
def validate(self, obj): raise WrongContainedType([])
""" implements(_IObject) # work around stupid ``Field`` constructor def __init__(self, *args, **kw): if 'check_declaration' in kw: self.check_declaration = kw['check_declaration'] del kw['check_declaration'] super(Object, self).__init__(*args, **kw) def _validate(self, value): super(ObjectBase, self)._validate(value) # schema has to be provided by value if self.check_declaration and not self.schema.providedBy(value): raise SchemaNotProvided # check the value against schema errors = [] for name, field in schemadict(self.schema).iteritems(): exc = None try: field.validate(getattr(value, name)) except ValidationError, error: exc = error except AttributeError, error: exc = SchemaNotFullyImplemented(error) if exc is not None: errors.append((name, exc)) if errors: raise WrongContainedType(errors)