You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
There are errors in an xsd file that raise an xml.etree.ElementTree.ParseError and do not cause an XMLSchemaException. The documentation of XMLSchemaException claims that it catches all exceptions.
"""Loads an xsd file"""importxmlschemadefmain():
"""Exception raised by invalid schema is expected to be caught"""try:
xmlschema.XMLSchema11("invalid_schema.xsd")
exceptxmlschema.XMLSchemaExceptionase:
print(e)
if__name__=='__main__':
main()
Run the python script with python validate_schema.py.
Expected behaviour: XMLSchema11 raises e.g. XMLSchemaValidatorError and the exception is caught.
Actual behaviour: the exception xml.etree.ElementTree.ParseError is raised and not caught.
The text was updated successfully, but these errors were encountered:
Hi,
the documentation says that the base exception "let you catch all the errors generated by the library". This case is on the boundary because this a ParseError of the ElementTree library.
Anyway it's better to reason on that because other errors are caught and re-raised.
In this case the error is in the syntax of the XML source, so it should raise an XMLResourceError or a derived exception from it. For v4.0 the XMLResource will be extended to support also parsing with lxml and custom url openers. All the XML data access in the library is delegated to this class so having its error type hierarchy could help to distinguish between XML data access/parsing and XML validation.
An hypothesis for this could be:
fromxml.etree.ElementTreeimportParseErrorfromxmlschemaimportXMLSchemaExceptionclassXMLResourceError(XMLSchemaException):
"""A generic error on an XML resource that let you catch all the errors generated by an XML resource."""classXMLResourceOSError(XMLResourceError, OSError):
"""Raised when an error is found accessing an XML resource."""classXMLResourceParseError(XMLResourceError, ParseError):
"""Raised when an error is found parsing an XML resource."""classXMLResourceBlocked(XMLResourceError):
"""Raised when an XML resource access is blocked by security settings."""classXMLResourceForbidden(XMLResourceError):
"""Raised when the parsing of an XML resource is forbidden for safety reasons."""
Deriving XMLResourceParseError from ParseError instead of SyntaxError preserves backward compatibility.
There are errors in an xsd file that raise an
xml.etree.ElementTree.ParseError
and do not cause anXMLSchemaException
. The documentation ofXMLSchemaException
claims that it catches all exceptions.Example
File:
invalid_schema.xsd
File:
validate_schema.py
Run the python script with
python validate_schema.py
.Expected behaviour:
XMLSchema11
raises e.g.XMLSchemaValidatorError
and the exception is caught.Actual behaviour: the exception
xml.etree.ElementTree.ParseError
is raised and not caught.The text was updated successfully, but these errors were encountered: