summaryrefslogtreecommitdiffstats
path: root/Lib/lib2to3/fixes/fix_metaclass.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-05-09 01:01:14 (GMT)
committerBenjamin Peterson <benjamin@python.org>2009-05-09 01:01:14 (GMT)
commit84ad84e0bb15e7c64109e88060afdcb60ae7b740 (patch)
tree5469c776c1f0fd812ae194e39544fca7dd3130b9 /Lib/lib2to3/fixes/fix_metaclass.py
parent5edb1a1b0add465bae25121ee4278a9ec6009005 (diff)
downloadcpython-84ad84e0bb15e7c64109e88060afdcb60ae7b740.zip
cpython-84ad84e0bb15e7c64109e88060afdcb60ae7b740.tar.gz
cpython-84ad84e0bb15e7c64109e88060afdcb60ae7b740.tar.bz2
Merged revisions 72491-72493 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r72491 | benjamin.peterson | 2009-05-08 19:33:27 -0500 (Fri, 08 May 2009) | 7 lines make 2to3 use unicode internally on 2.x This started out as a fix for #2660, but became this large refactoring when I realized the dire state this was in. 2to3 now uses tokenize.detect_encoding to decode the files correctly into unicode. ........ r72492 | benjamin.peterson | 2009-05-08 19:35:38 -0500 (Fri, 08 May 2009) | 1 line remove compat code ........ r72493 | benjamin.peterson | 2009-05-08 19:54:15 -0500 (Fri, 08 May 2009) | 1 line add a test for \r\n newlines ........
Diffstat (limited to 'Lib/lib2to3/fixes/fix_metaclass.py')
-rw-r--r--Lib/lib2to3/fixes/fix_metaclass.py24
1 files changed, 12 insertions, 12 deletions
diff --git a/Lib/lib2to3/fixes/fix_metaclass.py b/Lib/lib2to3/fixes/fix_metaclass.py
index b508f5f..3b1b3ea 100644
--- a/Lib/lib2to3/fixes/fix_metaclass.py
+++ b/Lib/lib2to3/fixes/fix_metaclass.py
@@ -113,7 +113,7 @@ def find_metas(cls_node):
# Check if the expr_node is a simple assignment.
left_node = expr_node.children[0]
if isinstance(left_node, Leaf) and \
- left_node.value == '__metaclass__':
+ left_node.value == u'__metaclass__':
# We found a assignment to __metaclass__.
fixup_simple_stmt(node, i, simple_node)
remove_trailing_newline(simple_node)
@@ -182,9 +182,9 @@ class FixMetaclass(fixer_base.BaseFix):
# Node(classdef, ['class', 'name', ':', suite])
# 0 1 2 3
arglist = Node(syms.arglist, [])
- node.insert_child(2, Leaf(token.RPAR, ')'))
+ node.insert_child(2, Leaf(token.RPAR, u')'))
node.insert_child(2, arglist)
- node.insert_child(2, Leaf(token.LPAR, '('))
+ node.insert_child(2, Leaf(token.LPAR, u'('))
else:
raise ValueError("Unexpected class definition")
@@ -194,16 +194,16 @@ class FixMetaclass(fixer_base.BaseFix):
orig_meta_prefix = meta_txt.get_prefix()
if arglist.children:
- arglist.append_child(Leaf(token.COMMA, ','))
- meta_txt.set_prefix(' ')
+ arglist.append_child(Leaf(token.COMMA, u','))
+ meta_txt.set_prefix(u' ')
else:
- meta_txt.set_prefix('')
+ meta_txt.set_prefix(u'')
# compact the expression "metaclass = Meta" -> "metaclass=Meta"
expr_stmt = last_metaclass.children[0]
assert expr_stmt.type == syms.expr_stmt
- expr_stmt.children[1].set_prefix('')
- expr_stmt.children[2].set_prefix('')
+ expr_stmt.children[1].set_prefix(u'')
+ expr_stmt.children[2].set_prefix(u'')
arglist.append_child(last_metaclass)
@@ -213,15 +213,15 @@ class FixMetaclass(fixer_base.BaseFix):
if not suite.children:
# one-liner that was just __metaclass_
suite.remove()
- pass_leaf = Leaf(text_type, 'pass')
+ pass_leaf = Leaf(text_type, u'pass')
pass_leaf.set_prefix(orig_meta_prefix)
node.append_child(pass_leaf)
- node.append_child(Leaf(token.NEWLINE, '\n'))
+ node.append_child(Leaf(token.NEWLINE, u'\n'))
elif len(suite.children) > 1 and \
(suite.children[-2].type == token.INDENT and
suite.children[-1].type == token.DEDENT):
# there was only one line in the class body and it was __metaclass__
- pass_leaf = Leaf(text_type, 'pass')
+ pass_leaf = Leaf(text_type, u'pass')
suite.insert_child(-1, pass_leaf)
- suite.insert_child(-1, Leaf(token.NEWLINE, '\n'))
+ suite.insert_child(-1, Leaf(token.NEWLINE, u'\n'))