示例#1
0
    def _check_with_rulesset(self, field, value):
        # resolve schema registry reference
        if isinstance(value, str):
            if value in self.known_rules_set_refs:
                return
            else:
                self.known_rules_set_refs.add(value)
            definition = self.target_validator.rules_set_registry.get(value)
            if definition is None:
                self._error(
                    field,
                    "Rules set definition '{}' not found.".format(value))
                return
            else:
                value = definition

        _hash = (
            schema_hash({'turing': value}),
            schema_hash(self.target_validator.types_mapping),
        )
        if _hash in self.target_validator._valid_schemas:
            return

        validator = self._get_child_validator(
            document_crumb=field,
            allow_unknown=False,
            schema=self.target_validator.rules,
        )
        validator(value, normalize=False)
        if validator._errors:
            self._error(validator._errors)
        else:
            self.target_validator._valid_schemas.add(_hash)
示例#2
0
    def _check_with_schema(self, field, value):
        if isinstance(value, str):
            if value in self.known_schema_refs:
                return

            self.known_schema_refs.add(value)
            definition = self.target_validator.schema_registry.get(value)
            if definition is None:
                path = self.document_path + (field, )
                self._error(path,
                            "Schema definition '{}' not found.".format(value))
        else:
            definition = value

        _hash = (
            schema_hash(definition),
            schema_hash(self.target_validator.types_mapping),
        )
        if _hash in self.target_validator._valid_schemas:
            return

        validator = self._get_child_validator(
            document_crumb=field,
            schema=None,
            allow_unknown=self.root_allow_unknown)
        validator(self._expand_rules_set_refs(definition), normalize=False)
        if validator._errors:
            self._error(validator._errors)
        else:
            self.target_validator._valid_schemas.add(_hash)
示例#3
0
    def _validate_logical(self, rule, field, value):
        """{'allowed': ('allof', 'anyof', 'noneof', 'oneof')}"""
        if not isinstance(value, Sequence):
            self._error(field, errors.TYPE)
            return

        validator = self._get_child_validator(
            document_crumb=rule,
            allow_unknown=False,
            schema=self.target_validator.validation_rules,
        )

        for constraints in value:
            _hash = (
                schema_hash({'turing': constraints}),
                schema_hash(self.target_validator.types_mapping),
            )
            if _hash in self.target_validator._valid_schemas:
                continue

            validator(constraints, normalize=False)
            if validator._errors:
                self._error(validator._errors)
            else:
                self.target_validator._valid_schemas.add(_hash)
示例#4
0
 def validate(self, schema=None):
     if schema is None:
         schema = self.schema
     _hash = (schema_hash(schema), schema_hash(self.validator.types_mapping))
     if _hash not in self.validator._valid_schemas:
         self._validate(schema)
         self.validator._valid_schemas.add(_hash)