GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-57092: Add the validate option to xml.sax.saxutils.XMLGenerator by serhiy-storchaka · Pull Request #156800 · python/cpython Conversation
|
Documentation build overview
294 files changed ·
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
The overall change LGTM.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
||
| def startElement(self, name, attrs): | ||
| if self._validate: | ||
| _check_name(name, 'element name') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Would it be possible to validate attributes here? With the current code, you start writing before raising an error on invalid attribute. So on error, incomplete XML is written.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I do not see how can this help? We already wrote something.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| def startElementNS(self, name, qname, attrs): | ||
| name = self._qname(name) | ||
| if self._validate: | ||
| _check_name(name, 'element name') |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Same remark: can you check attributes here?
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
I wrote a short program to understand how errors are handled and what is written. from xml.sax.saxutils import XMLGenerator from io import StringIO stream = StringIO() gen = XMLGenerator(stream, validate=True) gen.startElement('hello', {}) gen.endElement('hello') try: gen.startElement('hello2', {'': 'value'}) except ValueError: pass gen.startElement('hello3', {}) gen.endElement('hello3') print(stream.getvalue()) With this change, the output is: Ah yes, My concern is that an unfinished With my suggestion, it would be possible to write: I'm fine with not supporting this case and declare game over at the first validation error: the output should be discard in this case. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
Moving all checks at the function entry would avoid writing unfinished XML markup, but I'm fine with not supporting this case and expect the caller to discard the whole output at the first validation error.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Valid XML should have the root element. If serialization fails, the close tag for the root element and other open elements is no written -- this is an invalid XML. If serialization fails before writing the root element -- this is an invalid XML. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…en-validate # Conflicts: # Doc/whatsnew/3.16.rst
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.