Skip to content

Commit 31053fa

Browse files
committed
Make Document and DocumentFragment stringify better
Having both __str__ and __unicode__ appears to be necessary to handle both explicit print and when a value is echoed in an interactive python shell. http://code.google.com/p/html5lib/issues/detail?id=169
1 parent 31c6b2d commit 31053fa

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

html5lib/treebuilders/simpletree.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,9 +83,12 @@ class Document(Node):
8383
def __init__(self):
8484
Node.__init__(self, None)
8585

86-
def __unicode__(self):
86+
def __str__(self):
8787
return "#document"
8888

89+
def __unicode__(self):
90+
return str(self)
91+
8992
def appendChild(self, child):
9093
Node.appendChild(self, child)
9194

@@ -112,9 +115,12 @@ def cloneNode(self):
112115

113116
class DocumentFragment(Document):
114117
type = 2
115-
def __unicode__(self):
118+
def __str__(self):
116119
return "#document-fragment"
117120

121+
def __unicode__(self):
122+
return str(self)
123+
118124
def cloneNode(self):
119125
return DocumentFragment()
120126

0 commit comments

Comments
 (0)