Raised when the XML data is not validated with the XSD component or schema. It's used by decoding and encoding methods. Encoding validation errors do not include XML data element and source, so the error is limited to a message containing object representation and a reason. :pa
| 286 | |
| 287 | |
| 288 | class XMLSchemaValidationError(XMLSchemaValidatorError, ValueError): |
| 289 | """ |
| 290 | Raised when the XML data is not validated with the XSD component or schema. |
| 291 | It's used by decoding and encoding methods. Encoding validation errors do |
| 292 | not include XML data element and source, so the error is limited to a message |
| 293 | containing object representation and a reason. |
| 294 | |
| 295 | :param validator: the XSD validator. |
| 296 | :param obj: the not validated XML data. |
| 297 | :param reason: the detailed reason of failed validation. |
| 298 | :param source: the XML resource that contains the error. |
| 299 | :param namespaces: is an optional mapping from namespace prefix to URI. |
| 300 | """ |
| 301 | _message = 'failed validating {} with' |
| 302 | |
| 303 | @property |
| 304 | def message(self) -> str: |
| 305 | return f'{self._message} {self.validator!r}.' |
| 306 | |
| 307 | # For compatibility with XMLSchemaChildrenValidationError |
| 308 | invalid_tag: Optional[str] = None |
| 309 | |
| 310 | @property |
| 311 | def expected_tags(self) -> list[str]: return [] |
| 312 | |
| 313 | @property |
| 314 | def invalid_child(self) -> Optional[ElementType]: return None |
| 315 | |
| 316 | def __init__(self, |
| 317 | validator: ValidatorType, |
| 318 | obj: Any, |
| 319 | reason: Optional[str] = None, |
| 320 | source: Optional[Any] = None, |
| 321 | namespaces: Optional[NsmapType] = None) -> None: |
| 322 | |
| 323 | if isinstance(obj, str): |
| 324 | obj_repr = repr(obj.encode('ascii', 'xmlcharrefreplace').decode('utf-8')) |
| 325 | else: |
| 326 | obj_repr = repr(obj) |
| 327 | |
| 328 | if len(obj_repr) > 200: |
| 329 | obj_repr = f"{type(obj)} instance" |
| 330 | |
| 331 | super().__init__( |
| 332 | validator=validator, |
| 333 | message=_(self._message).format(obj_repr), |
| 334 | elem=obj if is_etree_element(obj) else None, |
| 335 | source=source, |
| 336 | namespaces=namespaces, |
| 337 | ) |
| 338 | self.obj = obj |
| 339 | self.reason = reason |
| 340 | |
| 341 | def __repr__(self) -> str: |
| 342 | return '%s(reason=%r)' % (self.__class__.__name__, self.reason) |
| 343 | |
| 344 | def __str__(self) -> str: |
| 345 | chunks: list[str] = ['%s:\n' % self.message.rstrip('.:')] |
no outgoing calls
searching dependent graphs…