Skip to content

Commit 3e50aad

Browse files
committed
Don't rely on the ElementTree Comment factory being the tag attribute on Comments.
This is needed for xml.etree.cElementTree under 2.6 (and likely hence custom installs of cElementTree 1.2), where the tag property is equal to xml.etree.ElementTree.Comment (i.e., the pure Python version). Similarly, don't rely on type(comment.tag), as this is just function!
1 parent 4e06f37 commit 3e50aad

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

html5lib/treebuilders/etree.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
def getETreeBuilder(ElementTreeImplementation, fullTree=False):
1515
ElementTree = ElementTreeImplementation
16+
ElementTreeCommentType = ElementTree.Comment("asd").tag
1617
class Element(_base.Node):
1718
def __init__(self, name, namespace=None):
1819
self._name = name
@@ -207,7 +208,7 @@ def serializeElement(element, indent=0):
207208
rv.append("|%s\"%s\""%(' '*(indent+2), element.text))
208209
if element.tail:
209210
finalText = element.tail
210-
elif element.tag == ElementTree.Comment:
211+
elif element.tag == ElementTreeCommentType:
211212
rv.append("|%s<!-- %s -->"%(' '*indent, element.text))
212213
else:
213214
assert isinstance(element.tag, text_type), "Expected unicode, got %s, %s"%(type(element.tag), element.tag)
@@ -275,7 +276,7 @@ def serializeElement(element):
275276
for child in element:
276277
serializeElement(child)
277278

278-
elif type(element.tag) == type(ElementTree.Comment):
279+
elif element.tag == ElementTreeCommentType:
279280
rv.append("<!--%s-->"%(element.text,))
280281
else:
281282
#This is assumed to be an ordinary element

0 commit comments

Comments
 (0)