|
19 | 19 | __all__ = ['XmlValidator'] |
20 | 20 |
|
21 | 21 | from abc import ABC |
| 22 | +from collections.abc import Iterable |
22 | 23 | from typing import TYPE_CHECKING, Any, Literal, Optional |
23 | 24 |
|
24 | 25 | from ..exception import MissingOptionalDependencyException |
@@ -53,12 +54,24 @@ def __init__(self, schema_version: 'SchemaVersion') -> None: |
53 | 54 | # this is the def that is used for generating the documentation |
54 | 55 | super().__init__(schema_version) |
55 | 56 |
|
56 | | - if _missing_deps_error: |
| 57 | + if _missing_deps_error: # noqa:C901 |
57 | 58 | __MDERROR = _missing_deps_error |
58 | 59 |
|
59 | 60 | def validate_str(self, data: str) -> Optional[ValidationError]: |
60 | 61 | raise self.__MDERROR[0] from self.__MDERROR[1] |
| 62 | + |
| 63 | + def iterate_errors(self, data: str) -> Iterable[ValidationError]: |
| 64 | + raise self.__MDERROR[0] from self.__MDERROR[1] |
61 | 65 | else: |
| 66 | + def iterate_errors(self, data: str) -> Iterable[ValidationError]: |
| 67 | + xml_data = xml_fromstring( # nosec B320 |
| 68 | + bytes(data, encoding='utf8'), |
| 69 | + parser=self.__xml_parser) |
| 70 | + validator = self._validator # may throw on error that MUST NOT be caught |
| 71 | + validator.validate(xml_data) |
| 72 | + for error in validator.error_log: |
| 73 | + yield ValidationError(error) |
| 74 | + |
62 | 75 | def validate_str(self, data: str) -> Optional[ValidationError]: |
63 | 76 | return self._validate_data( |
64 | 77 | xml_fromstring( # nosec B320 |
|
0 commit comments