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-139489: Add xml.is_valid_text() by serhiy-storchaka · Pull Request #149412 · python/cpython Conversation
|
Documentation build overview
10 files changed ·
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
What do you think of adding also a sanitize function which takes a callback? Example: import re ILLEGAL_XML_CHARS_RE = re.compile( '[' # Control characters; newline (\x0A and \x0D) and TAB (\x09) are legal '\x00-\x08\x0B\x0C\x0E-\x1F' # Surrogate characters '\uD800-\uDFFF' # Special Unicode characters '\uFFFE' '\uFFFF' # Match multiple sequential invalid characters for better efficiency ']+') def sanitize(text, replace_func): def callback(regs): return replace_func(regs[0]) return ILLEGAL_XML_CHARS_RE.sub(callback, text) def escape(text): return ''.join(f'\\x{ord(char):02x}' for char in text) invalid = '\x00' test = f'a{invalid}b' print(sanitize(test, lambda text: '#' * len(text))) print(sanitize(test, escape)) It would be useful for |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Stan Ulbrych <[email protected]> Co-authored-by: Serhiy Storchaka <[email protected]>
I left it for a separate PR. I have similar function in a different branch. But it accepts also the name of the registered error handler ('strict', 'ignore', 'replace, 'backslashreplace', etc) and the callback has different interface. It needs a separate discussion. |
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
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Ok, that makes sense. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…8qqIM.rst Co-authored-by: Victor Stinner <[email protected]>
There was an error while loading. Please reload this page.
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.