summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-03-21 00:42:39 +0000
committerwiemann <wiemann@929543f6-e4f2-0310-98a6-ba3bd3dd1d04>2007-03-21 00:42:39 +0000
commit04df8925bce94e67f84a0ea937a9dd5ce3794b0c (patch)
tree33a1fade3ac8aea42f20558592b764ff284094e4
parent861f2c54c572218763130c9ce72819c78f0309dd (diff)
downloaddocutils-04df8925bce94e67f84a0ea937a9dd5ce3794b0c.tar.gz
moved Element.__str__ to Node.__str__ so Text has it too;
made all Element and Text node convertible to unicode git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk/docutils/docutils@5030 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
-rw-r--r--nodes.py17
1 files changed, 12 insertions, 5 deletions
diff --git a/nodes.py b/nodes.py
index 8c30e203e..ffb679b17 100644
--- a/nodes.py
+++ b/nodes.py
@@ -61,6 +61,13 @@ class Node:
"""
return 1
+ def __str__(self):
+ return self.__unicode__().encode('raw_unicode_escape')
+
+ def __unicode__(self):
+ # Override in subclass.
+ raise NotImplementedError
+
def asdom(self, dom=None):
"""Return a DOM **fragment** representation of this Node."""
if dom is None:
@@ -306,6 +313,9 @@ class Text(Node, UserString):
def astext(self):
return self.data
+ def __unicode__(self):
+ return self.data
+
def copy(self):
return self.__class__(self.data)
@@ -425,14 +435,11 @@ class Element(Node):
else:
return '<%s...>' % self.tagname
- def __str__(self):
- return self.__unicode__().encode('raw_unicode_escape')
-
def __unicode__(self):
if self.children:
return u'%s%s%s' % (self.starttag(),
- ''.join([str(c) for c in self.children]),
- self.endtag())
+ ''.join([unicode(c) for c in self.children]),
+ self.endtag())
else:
return self.emptytag()