Skip to content

Commit 593510c

Browse files
author
Thomas Preud'homme
committed
[LNT] Python 3 support: adapt XML parsing with extra entities
Summary: 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. Reviewers: cmatthews, hubert.reinterpretcast, kristof.beyls, leandron, PrzemekWirkus Reviewed By: cmatthews Subscribers: llvm-commits Differential Revision: https://reviews.llvm.org/D68986
1 parent 2c828b8 commit 593510c

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

tests/server/ui/V4Pages.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,10 +109,12 @@ def dump_html(html_string):
109109

110110
def get_xml_tree(html_string):
111111
try:
112-
parser = ET.XMLParser()
113-
parser.parser.UseForeignDTD(True)
114-
parser.entity.update((x, unichr(i)) for x, i in name2codepoint.items())
115-
tree = ET.fromstring(html_string, parser=parser)
112+
entities_defs = []
113+
for x, i in name2codepoint.items():
114+
entities_defs.append(' <!ENTITY {x} "&#{i};">'.format(**locals()))
115+
docstring = "<!DOCTYPE html [\n{}\n]>".format('\n'.join(entities_defs))
116+
html_string = html_string.replace("<!DOCTYPE html>", docstring, 1)
117+
tree = ET.fromstring(html_string)
116118
except: # noqa FIXME: figure out what we expect this to throw.
117119
dump_html(html_string)
118120
raise

0 commit comments

Comments
 (0)