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)) != CommentedSeq:
            raise_exception(
                "when expecting a unique sequence",
                "found non-sequence",
                document, location=location,
            )
        else:
            existing_items = set()

            for i, item in enumerate(location.get(document)):
                if item in existing_items:
                    raise_exception(
                        "while parsing a sequence",
                        "duplicate found",
                        document, location=location
                    )
                else:
                    existing_items.add(item)
                    return_snippet.append(self._validator(document, location=location.index(i)))

        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)) != CommentedSeq:
            raise_exception(
                "when expecting a unique sequence",
                "found non-sequence",
                document, location=location,
            )
        else:
            existing_items = set()

            for i, item in enumerate(location.get(document)):
                if item in existing_items:
                    raise_exception(
                        "while parsing a sequence",
                        "duplicate found",
                        document, location=location
                    )
                else:
                    existing_items.add(item)
                    return_snippet.append(self._validator(document, location=location.index(i)))

        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():
                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 #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)) != CommentedSeq:
            raise_exception(
                "when expecting a sequence",
                "found non-sequence",
                document, location=location,
            )
        else:
            for i, item in enumerate(location.get(document)):
                return_snippet.append(self._validator(document, location=location.index(i)))

        return return_snippet
Beispiel #5
0
    def validate(self, document, location=None):
        if location is None:
            location = YAMLLocation()
            document = copy.deepcopy(document)
        return_snippet = []

        if type(location.get(document)) != CommentedSeq:
            raise_exception(
                "when expecting a sequence",
                "found non-sequence",
                document, location=location,
            )
        else:
            for i, item in enumerate(location.get(document)):
                return_snippet.append(self._validator(document, location=location.index(i)))

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

        try:
            return self._validator_a(document, location=location)
        except YAMLValidationError:
            return self._validator_b(document, location=location)
Beispiel #7
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 #8
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 #9
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 #10
0
 def __call__(self, document, location=None):
     if location is None:
         location = YAMLLocation()
     return self.validate(document, location)