summaryrefslogtreecommitdiff
path: root/Lib/lib2to3/refactor.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2009-11-25 18:16:46 +0000
committerBenjamin Peterson <benjamin@python.org>2009-11-25 18:16:46 +0000
commit42d26d94cc5fe633613c853c1e1b4b51f0855df4 (patch)
treebef533daf1fbecdc6f9d7818123ad8b7f16897e7 /Lib/lib2to3/refactor.py
parent2ed8813f227756a8a698b03f1eb0b98af0b2b8b6 (diff)
downloadcpython-git-42d26d94cc5fe633613c853c1e1b4b51f0855df4.tar.gz
Merged revisions 76160-76161,76250,76252,76447,76506 via svnmerge from
svn+ssh://pythondev@svn.python.org/sandbox/trunk/2to3/lib2to3 ........ r76160 | benjamin.peterson | 2009-11-08 18:53:48 -0600 (Sun, 08 Nov 2009) | 1 line undeprecate the -p option; it's useful for converting python3 sources ........ r76161 | benjamin.peterson | 2009-11-08 19:05:37 -0600 (Sun, 08 Nov 2009) | 1 line simplify condition ........ r76250 | benjamin.peterson | 2009-11-13 16:56:48 -0600 (Fri, 13 Nov 2009) | 1 line fix handling of a utf-8 bom #7313 ........ r76252 | benjamin.peterson | 2009-11-13 16:58:36 -0600 (Fri, 13 Nov 2009) | 1 line remove pdb turd ........ r76447 | benjamin.peterson | 2009-11-22 18:17:40 -0600 (Sun, 22 Nov 2009) | 1 line #7375 fix nested transformations in fix_urllib ........ r76506 | benjamin.peterson | 2009-11-24 18:34:31 -0600 (Tue, 24 Nov 2009) | 1 line use generator expressions in any() ........
Diffstat (limited to 'Lib/lib2to3/refactor.py')
-rw-r--r--Lib/lib2to3/refactor.py43
1 files changed, 20 insertions, 23 deletions
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 97a540d7c6..df5456e6f5 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -18,7 +18,6 @@ import logging
import operator
import collections
import StringIO
-import warnings
from itertools import chain
# Local imports
@@ -139,26 +138,23 @@ def _detect_future_print(source):
if have_docstring:
break
have_docstring = True
- elif tp == token.NAME:
- if value == u"from":
+ elif tp == token.NAME and value == u"from":
+ tp, value = advance()
+ if tp != token.NAME and value != u"__future__":
+ break
+ tp, value = advance()
+ if tp != token.NAME and value != u"import":
+ break
+ tp, value = advance()
+ if tp == token.OP and value == u"(":
tp, value = advance()
- if tp != token.NAME and value != u"__future__":
- break
+ while tp == token.NAME:
+ if value == u"print_function":
+ return True
tp, value = advance()
- if tp != token.NAME and value != u"import":
+ if tp != token.OP and value != u",":
break
tp, value = advance()
- if tp == token.OP and value == u"(":
- tp, value = advance()
- while tp == token.NAME:
- if value == u"print_function":
- return True
- tp, value = advance()
- if tp != token.OP and value != u",":
- break
- tp, value = advance()
- else:
- break
else:
break
except StopIteration:
@@ -172,7 +168,7 @@ class FixerError(Exception):
class RefactoringTool(object):
- _default_options = {}
+ _default_options = {"print_function" : False}
CLASS_PREFIX = "Fix" # The prefix for fixer classes
FILE_PREFIX = "fix_" # The prefix for modules with a fixer within
@@ -189,15 +185,16 @@ class RefactoringTool(object):
self.explicit = explicit or []
self.options = self._default_options.copy()
if options is not None:
- if "print_function" in options:
- warnings.warn("the 'print_function' option is deprecated",
- DeprecationWarning)
self.options.update(options)
+ if self.options["print_function"]:
+ self.grammar = pygram.python_grammar_no_print_statement
+ else:
+ self.grammar = pygram.python_grammar
self.errors = []
self.logger = logging.getLogger("RefactoringTool")
self.fixer_log = []
self.wrote = False
- self.driver = driver.Driver(pygram.python_grammar,
+ self.driver = driver.Driver(self.grammar,
convert=pytree.convert,
logger=self.logger)
self.pre_order, self.post_order = self.get_fixers()
@@ -353,7 +350,7 @@ class RefactoringTool(object):
name, err.__class__.__name__, err)
return
finally:
- self.driver.grammar = pygram.python_grammar
+ self.driver.grammar = self.grammar
self.log_debug("Refactoring %s", name)
self.refactor_tree(tree, name)
return tree