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()
........
diff --git a/Lib/lib2to3/refactor.py b/Lib/lib2to3/refactor.py
index 97a540d..df5456e 100644
--- a/Lib/lib2to3/refactor.py
+++ b/Lib/lib2to3/refactor.py
@@ -18,7 +18,6 @@
import operator
import collections
import StringIO
-import warnings
from itertools import chain
# Local imports
@@ -139,26 +138,23 @@
if have_docstring:
break
have_docstring = True
- elif tp == token.NAME:
- if 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()
- 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:
+ 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()
+ 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
except StopIteration:
@@ -172,7 +168,7 @@
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 @@
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 @@
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