Skip to content

Commit 608d8bc

Browse files
committed
Merged revisions 72368 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ................ r72368 | benjamin.peterson | 2009-05-05 18:13:58 -0500 (Tue, 05 May 2009) | 53 lines Merged revisions 68503,68507,68694,69054,69673,69679-69681,70991,70999,71003,71695 via svnmerge from svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r68503 | benjamin.peterson | 2009-01-10 14:14:49 -0600 (Sat, 10 Jan 2009) | 1 line use variable ........ r68507 | benjamin.peterson | 2009-01-10 15:13:16 -0600 (Sat, 10 Jan 2009) | 1 line rewrap ........ r68694 | benjamin.peterson | 2009-01-17 17:55:59 -0600 (Sat, 17 Jan 2009) | 1 line test for specific node type ........ r69054 | guilherme.polo | 2009-01-28 10:01:54 -0600 (Wed, 28 Jan 2009) | 2 lines Added mapping for the ttk module. ........ r69673 | benjamin.peterson | 2009-02-16 09:38:22 -0600 (Mon, 16 Feb 2009) | 1 line fix handling of as imports python#5279 ........ r69679 | benjamin.peterson | 2009-02-16 11:36:06 -0600 (Mon, 16 Feb 2009) | 1 line make Base.get_next_sibling() and Base.get_prev_sibling() properties ........ r69680 | benjamin.peterson | 2009-02-16 11:41:48 -0600 (Mon, 16 Feb 2009) | 1 line normalize docstrings in pytree according to PEP 11 ........ r69681 | benjamin.peterson | 2009-02-16 11:43:09 -0600 (Mon, 16 Feb 2009) | 1 line use a set ........ r70991 | benjamin.peterson | 2009-04-01 15:54:50 -0500 (Wed, 01 Apr 2009) | 1 line map urllib.urlopen to urllib.request.open python#5637 ........ r70999 | benjamin.peterson | 2009-04-01 17:36:47 -0500 (Wed, 01 Apr 2009) | 1 line add very alpha support to 2to3 for running concurrently with multiprocessing ........ r71003 | benjamin.peterson | 2009-04-01 18:10:43 -0500 (Wed, 01 Apr 2009) | 1 line fix when multiprocessing is not available or used ........ r71695 | benjamin.peterson | 2009-04-17 22:21:29 -0500 (Fri, 17 Apr 2009) | 1 line refactor multiprocessing support, so it's less hacky to employ and only loads mp when needed ........ ................
1 parent b43d325 commit 608d8bc

12 files changed

Lines changed: 246 additions & 116 deletions

Lib/lib2to3/fixer_util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def is_probably_builtin(node):
226226
"""
227227
Check that something isn't an attribute or function name etc.
228228
"""
229-
prev = node.get_prev_sibling()
229+
prev = node.prev_sibling
230230
if prev is not None and prev.type == token.DOT:
231231
# Attribute lookup.
232232
return False

Lib/lib2to3/fixes/fix_except.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,11 @@
2525
from .. import pytree
2626
from ..pgen2 import token
2727
from .. import fixer_base
28-
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list
28+
from ..fixer_util import Assign, Attr, Name, is_tuple, is_list, syms
2929

3030
def find_excepts(nodes):
3131
for i, n in enumerate(nodes):
32-
if isinstance(n, pytree.Node):
32+
if n.type == syms.except_clause:
3333
if n.children[0].value == 'except':
3434
yield (n, nodes[i+2])
3535

Lib/lib2to3/fixes/fix_imports.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
'ScrolledText': 'tkinter.scrolledtext',
2828
'Tkconstants': 'tkinter.constants',
2929
'Tix': 'tkinter.tix',
30+
'ttk': 'tkinter.ttk',
3031
'Tkinter': 'tkinter',
3132
'markupbase': '_markupbase',
3233
'_winreg': 'winreg',
@@ -121,17 +122,18 @@ def start_tree(self, tree, filename):
121122
def transform(self, node, results):
122123
import_mod = results.get("module_name")
123124
if import_mod:
124-
new_name = self.mapping[import_mod.value]
125+
mod_name = import_mod.value
126+
new_name = self.mapping[mod_name]
125127
import_mod.replace(Name(new_name, prefix=import_mod.get_prefix()))
126128
if "name_import" in results:
127129
# If it's not a "from x import x, y" or "import x as y" import,
128130
# marked its usage to be replaced.
129-
self.replace[import_mod.value] = new_name
131+
self.replace[mod_name] = new_name
130132
if "multiple_imports" in results:
131-
# This is a nasty hack to fix multiple imports on a
132-
# line (e.g., "import StringIO, urlparse"). The problem is that I
133-
# can't figure out an easy way to make a pattern recognize the
134-
# keys of MAPPING randomly sprinkled in an import statement.
133+
# This is a nasty hack to fix multiple imports on a line (e.g.,
134+
# "import StringIO, urlparse"). The problem is that I can't
135+
# figure out an easy way to make a pattern recognize the keys of
136+
# MAPPING randomly sprinkled in an import statement.
135137
results = self.match(node)
136138
if results:
137139
self.transform(node, results)

Lib/lib2to3/fixes/fix_itertools_imports.py

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
""" Fixer for imports of itertools.(imap|ifilter|izip|ifilterfalse) """
22

33
# Local imports
4-
from .. import fixer_base
5-
from ..fixer_util import BlankLine
4+
from lib2to3 import fixer_base
5+
from lib2to3.fixer_util import BlankLine, syms, token
6+
67

78
class FixItertoolsImports(fixer_base.BaseFix):
89
PATTERN = """
@@ -11,34 +12,40 @@ class FixItertoolsImports(fixer_base.BaseFix):
1112

1213
def transform(self, node, results):
1314
imports = results['imports']
14-
children = imports.children[:] or [imports]
15-
for child in children:
16-
if not hasattr(child, 'value'):
17-
# Handle 'import ... as ...'
18-
continue
19-
if child.value in ('imap', 'izip', 'ifilter'):
20-
# The value must be set to none in case child == import,
21-
# so that the test for empty imports will work out
15+
if imports.type == syms.import_as_name or not imports.children:
16+
children = [imports]
17+
else:
18+
children = imports.children
19+
for child in children[::2]:
20+
if child.type == token.NAME:
21+
member = child.value
22+
name_node = child
23+
else:
24+
assert child.type == syms.import_as_name
25+
name_node = child.children[0]
26+
member_name = name_node.value
27+
if member_name in ('imap', 'izip', 'ifilter'):
2228
child.value = None
2329
child.remove()
24-
elif child.value == 'ifilterfalse':
30+
elif member_name == 'ifilterfalse':
2531
node.changed()
26-
child.value = 'filterfalse'
32+
name_node.value = 'filterfalse'
2733

2834
# Make sure the import statement is still sane
2935
children = imports.children[:] or [imports]
3036
remove_comma = True
3137
for child in children:
32-
if remove_comma and getattr(child, 'value', None) == ',':
38+
if remove_comma and child.type == token.COMMA:
3339
child.remove()
3440
else:
3541
remove_comma ^= True
3642

37-
if str(children[-1]) == ',':
43+
if children[-1].type == token.COMMA:
3844
children[-1].remove()
3945

4046
# If there are no imports left, just get rid of the entire statement
41-
if not (imports.children or getattr(imports, 'value', None)):
47+
if not (imports.children or getattr(imports, 'value', None)) or \
48+
imports.parent is None:
4249
p = node.get_prefix()
4350
node = BlankLine()
4451
node.prefix = p

Lib/lib2to3/fixes/fix_set_literal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def transform(self, node, results):
3838
literal.extend(n.clone() for n in items.children)
3939
literal.append(pytree.Leaf(token.RBRACE, "}"))
4040
# Set the prefix of the right brace to that of the ')' or ']'
41-
literal[-1].set_prefix(items.get_next_sibling().get_prefix())
41+
literal[-1].set_prefix(items.next_sibling.get_prefix())
4242
maker = pytree.Node(syms.dictsetmaker, literal)
4343
maker.set_prefix(node.get_prefix())
4444

Lib/lib2to3/fixes/fix_urllib.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
MAPPING = {'urllib': [
1313
('urllib.request',
1414
['URLOpener', 'FancyURLOpener', 'urlretrieve',
15-
'_urlopener', 'urlcleanup']),
15+
'_urlopener', 'urlopen', 'urlcleanup']),
1616
('urllib.parse',
1717
['quote', 'quote_plus', 'unquote', 'unquote_plus',
1818
'urlencode', 'pathname2url', 'url2pathname', 'splitattr',

Lib/lib2to3/main.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
from . import refactor
1212

13-
14-
class StdoutRefactoringTool(refactor.RefactoringTool):
13+
class StdoutRefactoringTool(refactor.MultiprocessRefactoringTool):
1514
"""
1615
Prints output to stdout.
1716
"""
@@ -64,6 +63,8 @@ def main(fixer_pkg, args=None):
6463
help="Fix up doctests only")
6564
parser.add_option("-f", "--fix", action="append", default=[],
6665
help="Each FIX specifies a transformation; default: all")
66+
parser.add_option("-j", "--processes", action="store", default=1,
67+
type="int", help="Run 2to3 concurrently")
6768
parser.add_option("-x", "--nofix", action="append", default=[],
6869
help="Prevent a fixer from being run.")
6970
parser.add_option("-l", "--list-fixes", action="store_true",
@@ -126,7 +127,14 @@ def main(fixer_pkg, args=None):
126127
if refactor_stdin:
127128
rt.refactor_stdin()
128129
else:
129-
rt.refactor(args, options.write, options.doctests_only)
130+
try:
131+
rt.refactor(args, options.write, options.doctests_only,
132+
options.processes)
133+
except refactor.MultiprocessingUnsupported:
134+
assert options.processes > 1
135+
print >> sys.stderr, "Sorry, -j isn't " \
136+
"supported on this platform."
137+
return 1
130138
rt.summarize()
131139

132140
# Return error status (0 if rt.errors is zero)

Lib/lib2to3/patcomp.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030

3131
def tokenize_wrapper(input):
3232
"""Tokenizes a string suppressing significant whitespace."""
33-
skip = (token.NEWLINE, token.INDENT, token.DEDENT)
33+
skip = set((token.NEWLINE, token.INDENT, token.DEDENT))
3434
tokens = tokenize.generate_tokens(driver.generate_lines(input).__next__)
3535
for quintuple in tokens:
3636
type, value, start, end, line_text = quintuple

0 commit comments

Comments
 (0)