[Python-checkins] r54312 - in sandbox/trunk/2to3: fixes/basefix.py fixes/fix_intern.py pgen2/parse.py pytree.py refactor.py tests/pytree_idempotency.py tests/support.py tests/test_pytree.py
collin.winter
python-checkins at python.org
Mon Mar 12 23:02:48 CET 2007
Author: collin.winter
Date: Mon Mar 12 23:02:45 2007
New Revision: 54312
Modified:
sandbox/trunk/2to3/fixes/basefix.py
sandbox/trunk/2to3/fixes/fix_intern.py
sandbox/trunk/2to3/pgen2/parse.py
sandbox/trunk/2to3/pytree.py
sandbox/trunk/2to3/refactor.py
sandbox/trunk/2to3/tests/pytree_idempotency.py
sandbox/trunk/2to3/tests/support.py
sandbox/trunk/2to3/tests/test_pytree.py
Log:
Make 2to3 run on Python 2.3.
Modified: sandbox/trunk/2to3/fixes/basefix.py
==============================================================================
--- sandbox/trunk/2to3/fixes/basefix.py (original)
+++ sandbox/trunk/2to3/fixes/basefix.py Mon Mar 12 23:02:45 2007
@@ -7,12 +7,16 @@
import logging
import itertools
+# Get a usable 'set' constructor
+try:
+ set()
+except:
+ from sets import Set as set
+
# Local imports
import patcomp
import pygram
-# For new_name()
-
class BaseFix(object):
"""Optional base class for fixers.
Modified: sandbox/trunk/2to3/fixes/fix_intern.py
==============================================================================
--- sandbox/trunk/2to3/fixes/fix_intern.py (original)
+++ sandbox/trunk/2to3/fixes/fix_intern.py Mon Mar 12 23:02:45 2007
@@ -35,7 +35,7 @@
newarglist = pytree.Node(syms.arglist, [obj.clone()])
after = results["after"]
if after:
- after = tuple(n.clone() for n in after)
+ after = tuple([n.clone() for n in after])
new = pytree.Node(syms.power,
Attr(Name("sys"), Name("intern")) +
(pytree.Node(syms.trailer,
Modified: sandbox/trunk/2to3/pgen2/parse.py
==============================================================================
--- sandbox/trunk/2to3/pgen2/parse.py (original)
+++ sandbox/trunk/2to3/pgen2/parse.py Mon Mar 12 23:02:45 2007
@@ -10,6 +10,12 @@
"""
+# Get a usable 'set' constructor
+try:
+ set()
+except:
+ from sets import Set as set
+
# Local imports
from pgen2 import token
Modified: sandbox/trunk/2to3/pytree.py
==============================================================================
--- sandbox/trunk/2to3/pytree.py (original)
+++ sandbox/trunk/2to3/pytree.py Mon Mar 12 23:02:45 2007
@@ -164,7 +164,7 @@
def clone(self):
"""Returns a cloned (deep) copy of self."""
- return Node(self.type, (ch.clone() for ch in self.children))
+ return Node(self.type, [ch.clone() for ch in self.children])
def post_order(self):
"""Returns a post-order iterator for the tree."""
Modified: sandbox/trunk/2to3/refactor.py
==============================================================================
--- sandbox/trunk/2to3/refactor.py (original)
+++ sandbox/trunk/2to3/refactor.py Mon Mar 12 23:02:45 2007
@@ -28,7 +28,13 @@
import fixes.macros
import pygram
-logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
+if sys.version_info < (2, 4):
+ hdlr = logging.StreamHandler()
+ fmt = logging.Formatter('%(name)s: %(message)s')
+ hdlr.setFormatter(fmt)
+ logging.root.addHandler(hdlr)
+else:
+ logging.basicConfig(format='%(name)s: %(message)s', level=logging.INFO)
def main(args=None):
@@ -122,7 +128,7 @@
self.log_error("Can't find transformation %s", fix_name)
continue
parts = fix_name.split("_")
- class_name = "Fix" + "".join(p.title() for p in parts)
+ class_name = "Fix" + "".join([p.title() for p in parts])
try:
fix_class = getattr(mod, class_name)
except AttributeError:
Modified: sandbox/trunk/2to3/tests/pytree_idempotency.py
==============================================================================
--- sandbox/trunk/2to3/tests/pytree_idempotency.py (original)
+++ sandbox/trunk/2to3/tests/pytree_idempotency.py Mon Mar 12 23:02:45 2007
@@ -16,7 +16,7 @@
import pytree
-logging.basicConfig(level=logging.WARN)
+logging.basicConfig()
def main():
gr = driver.load_grammar("Grammar.txt")
Modified: sandbox/trunk/2to3/tests/support.py
==============================================================================
--- sandbox/trunk/2to3/tests/support.py (original)
+++ sandbox/trunk/2to3/tests/support.py Mon Mar 12 23:02:45 2007
@@ -8,6 +8,12 @@
TestCase = unittest.TestCase
+# Python 2.3's TestSuite is not iter()-able
+if sys.version_info < (2, 4):
+ def TestSuite_iter(self):
+ return iter(self._tests)
+ unittest.TestSuite.__iter__ = TestSuite_iter
+
def run_all_tests(test_mod=None, tests=None):
if tests is None:
tests = unittest.TestLoader().loadTestsFromModule(test_mod)
@@ -25,5 +31,5 @@
if indent == 0:
code = string
else:
- code = "\n".join(line[indent-1:] for line in string.split("\n")[1:])
+ code = "\n".join([line[indent-1:] for line in string.split("\n")[1:]])
return code + "\n\n"
Modified: sandbox/trunk/2to3/tests/test_pytree.py
==============================================================================
--- sandbox/trunk/2to3/tests/test_pytree.py (original)
+++ sandbox/trunk/2to3/tests/test_pytree.py Mon Mar 12 23:02:45 2007
@@ -18,6 +18,13 @@
# Local imports (XXX should become a package)
import pytree
+try:
+ sorted
+except:
+ def sorted(lst):
+ l = list(lst)
+ l.sort()
+ return l
class TestNodes(support.TestCase):
More information about the Python-checkins
mailing list