Skip to content

Commit 6f2cf48

Browse files
committed
move toxml to a consistent place (after __unicode__) in every class
--HG-- extra : convert_revision : svn%3Aacbfec75-9323-0410-a652-858a13e371e0/trunk%40468
1 parent fac0a99 commit 6f2cf48

File tree

1 file changed

+22
-20
lines changed

1 file changed

+22
-20
lines changed

src/treebuilders/simpletree.py

Lines changed: 22 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def __init__(self, name):
1313
def __unicode__(self):
1414
return self.name
1515

16+
def toxml(self):
17+
raise NotImplementedError
18+
1619
def __repr__(self):
1720
return "<%s %s>" % (self.__class__, self.name)
1821

@@ -71,27 +74,26 @@ def __init__(self):
7174
def __unicode__(self):
7275
return "#document"
7376

74-
def printTree(self):
75-
tree = unicode(self)
76-
for child in self.childNodes:
77-
tree += child.printTree(2)
78-
return tree
79-
8077
def toxml(self, encoding="utf=8"):
8178
result = ''
8279
for child in self.childNodes:
8380
result += child.toxml()
8481
return result.encode(encoding)
8582

83+
def printTree(self):
84+
tree = unicode(self)
85+
for child in self.childNodes:
86+
tree += child.printTree(2)
87+
return tree
88+
8689
class DocumentType(Node):
8790
def __init__(self, name):
8891
Node.__init__(self, name)
8992

9093
def __unicode__(self):
9194
return "<!DOCTYPE %s>" % self.name
9295

93-
def toxml(self):
94-
return "";
96+
toxml = __unicode__
9597

9698
class TextNode(Node):
9799
def __init__(self, value):
@@ -112,16 +114,6 @@ def __init__(self, name):
112114
def __unicode__(self):
113115
return "<%s>" % self.name
114116

115-
def printTree(self, indent):
116-
tree = '\n|%s%s' % (' '*indent, unicode(self))
117-
indent += 2
118-
if self.attributes:
119-
for name, value in self.attributes.iteritems():
120-
tree += '\n|%s%s="%s"' % (' ' * indent, name, value)
121-
for child in self.childNodes:
122-
tree += child.printTree(indent)
123-
return tree
124-
125117
def toxml(self):
126118
result = '<' + self.name
127119
if self.attributes:
@@ -136,15 +128,25 @@ def toxml(self):
136128
result += '/>'
137129
return result
138130

131+
def printTree(self, indent):
132+
tree = '\n|%s%s' % (' '*indent, unicode(self))
133+
indent += 2
134+
if self.attributes:
135+
for name, value in self.attributes.iteritems():
136+
tree += '\n|%s%s="%s"' % (' ' * indent, name, value)
137+
for child in self.childNodes:
138+
tree += child.printTree(indent)
139+
return tree
140+
139141
class CommentNode(Node):
140142
def __init__(self, data):
141143
Node.__init__(self, None)
142144
self.data = data
143145

144146
def __unicode__(self):
145147
return "<!-- %s -->" % self.data
146-
147-
toxml = __unicode__
148+
149+
toxml = __unicode__
148150

149151
class TreeBuilder(_base.TreeBuilder):
150152
documentClass = Document

0 commit comments

Comments
 (0)