summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/pytree.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/lib2to3/pytree.py')
-rw-r--r--Lib/lib2to3/pytree.py14
1 files changed, 12 insertions, 2 deletions
diff --git a/Lib/lib2to3/pytree.py b/Lib/lib2to3/pytree.py
index 9de810e..c60f107 100644
--- a/Lib/lib2to3/pytree.py
+++ b/Lib/lib2to3/pytree.py
@@ -216,6 +216,10 @@ class Base(object):
return ""
return next_sib.get_prefix()
+ if sys.version_info < (3, 0):
+ def __str__(self):
+ return str(self).encode("ascii")
+
class Node(Base):
@@ -245,7 +249,7 @@ class Node(Base):
type_repr(self.type),
self.children)
- def __str__(self):
+ def __unicode__(self):
"""
Return a pretty string representation.
@@ -253,6 +257,9 @@ class Node(Base):
"""
return "".join(map(str, self.children))
+ if sys.version_info > (3, 0):
+ __str__ = __unicode__
+
def _eq(self, other):
"""Compare two nodes for equality."""
return (self.type, self.children) == (other.type, other.children)
@@ -353,7 +360,7 @@ class Leaf(Base):
self.type,
self.value)
- def __str__(self):
+ def __unicode__(self):
"""
Return a pretty string representation.
@@ -361,6 +368,9 @@ class Leaf(Base):
"""
return self.prefix + str(self.value)
+ if sys.version_info > (3, 0):
+ __str__ = __unicode__
+
def _eq(self, other):
"""Compare two nodes for equality."""
return (self.type, self.value) == (other.type, other.value)