Beispiel #1
0
    def validate(self, document, location=None):
        if location is None:
            location = YAMLLocation()
            document = copy.deepcopy(document)
        return_snippet = {}

        if type(location.get(document)) != CommentedMap:
            raise_exception(
                "when expecting a mapping",
                "found non-mapping",
                document, location=location,
            )
        else:
            for key, value in location.get(document).items():
                if key not in self._validator_dict.keys():
                    raise_exception(
                        "while parsing a mapping",
                        "unexpected key not in schema '{0}'".format(key),
                        document, location=location.key(key)
                    )

                return_snippet[key] = self._validator_dict[key](
                    document, location=location.val(key)
                )

        return return_snippet
Beispiel #2
0
    def validate(self, document, location=None):
        if location is None:
            location = YAMLLocation()
            document = copy.deepcopy(document)
        return_snippet = {}

        if type(location.get(document)) != CommentedMap:
            raise_exception(
                "when expecting a mapping",
                "found non-mapping",
                document, location=location,
            )
        else:
            for key, value in location.get(document).items():
                if key not in self._validator_dict.keys():
                    raise_exception(
                        "while parsing a mapping",
                        "unexpected key not in schema '{0}'".format(key),
                        document, location=location.key(key)
                    )

                return_snippet[key] = self._validator_dict[key](
                    document, location.val(key)
                )

        return return_snippet
Beispiel #3
0
    def validate(self, document, location=None):
        if location is None:
            location = YAMLLocation()
            document = copy.deepcopy(document)
        return_snippet = {}

        if type(location.get(document)) != CommentedMap:
            raise_exception(
                "when expecting a mapping",
                "found non-mapping",
                document, location=location,
            )
        else:
            for key, value in location.get(document).items():
                valid_key = self._key_validator(document, location.key(key))
                valid_val = self._value_validator(document, location.val(key))
                return_snippet[valid_key] = valid_val

        return return_snippet
Beispiel #4
0
    def validate(self, document, location=None):
        if location is None:
            location = YAMLLocation()
            document = copy.deepcopy(document)
        return_snippet = {}

        if type(location.get(document)) != CommentedMap:
            raise_exception(
                "when expecting a mapping",
                "found non-mapping",
                document, location=location,
            )
        else:
            for key, value in location.get(document).items():
                valid_key = self._key_validator(document, location.key(key))
                valid_val = self._value_validator(document, location.val(key))
                return_snippet[valid_key] = valid_val

        return return_snippet