[PATCH] D68986: [LNT] Python 3 support: adapt XML parsing with extra entities
Thomas Preud'homme via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Oct 15 07:20:24 PDT 2019
thopre created this revision.
thopre added reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls.
thopre added a parent revision: D68985: [LNT] Python 3 support: requests.response as text.
thopre added a child revision: D68987: [LNT] Python 3 support: store color value as int.
Test server/ui/V4Pages.py parses XML with non standard entities using
the ElementTree's XML parser. However the method it uses to declare the
non standard entities are no longer available in Python 3's ElementTree.
This commit instead modifies the DOCTYPE element in the XML directly
before passing it to ElementTree's XML parser.
https://reviews.llvm.org/D68986
Files:
tests/server/ui/V4Pages.py
Index: tests/server/ui/V4Pages.py
===================================================================
--- tests/server/ui/V4Pages.py
+++ tests/server/ui/V4Pages.py
@@ -19,7 +19,6 @@
from future import standard_library
standard_library.install_aliases()
-from builtins import chr
import logging
import re
import sys
@@ -112,10 +111,12 @@
def get_xml_tree(html_string):
try:
- parser = ET.XMLParser()
- parser.parser.UseForeignDTD(True)
- parser.entity.update((x, chr(i)) for x, i in name2codepoint.items())
- tree = ET.fromstring(html_string, parser=parser)
+ entities_defs = []
+ for x, i in name2codepoint.items():
+ entities_defs.append(' <!ENTITY {x} "&#{i};">'.format(**locals()))
+ docstring = "<!DOCTYPE html [\n{}\n]>".format('\n'.join(entities_defs))
+ html_string = html_string.replace("<!DOCTYPE html>", docstring, 1)
+ tree = ET.fromstring(html_string)
except: # noqa FIXME: figure out what we expect this to throw.
dump_html(html_string)
raise
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D68986.225029.patch
Type: text/x-patch
Size: 1070 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20191015/14013dd6/attachment.bin>
More information about the llvm-commits
mailing list