def __call__(self, data, tree): """ Go through each item in data against the first schema in the arguments. If that fails try each subsequent schema until it passes. Even if schemas are failing to apply to that given item, consume all the available ones until at least one passes. If nothing passes, the last error is raised. :param data: Incoming data from the validator engine in normalized dict form. :param tree: The traversing tree up to this point, always passed in. :raises Invalid: If none of the schemas can validate the data. """ first_schema = expand_schema(self.schemas[0]) index = len(data) - 1 validator = IterableValidator(data, first_schema, tree, index=index, name='MultiIterable') for item_index in range(len(data)): try: validator.leaf(item_index) except (SchemaError, Invalid): self.itemized_validation(validator, item_index)
def __call__(self, data, tree): schema = expand_schema(self.schema) self.safe_type(data, tree) index = len(data) - 1 validator = IterableValidator(data, schema, [], index=index, name='AnyItem') for item_index in range(len(data)): try: return validator.leaf(item_index) except Invalid: pass tree.append('list[]') if is_callable(schema): msg = "did not contain any valid items against callable: %s" % schema.__name__ else: msg = "did not contain any valid items matching %s" % repr(schema) raise Invalid(schema, tree, pair='value', msg=msg)
def __call__(self, data, tree): schema = expand_schema(self.schema) self.safe_type(data, tree) validator = IterableValidator(data, schema, tree, name='AllItems') validator.validate()