Commits

Ralph Bean committed f30beb3

Python2.5 support.

Comments (0)

Files changed (3)

tests/test_template.py

 engines = ['genshi', 'mako', 'jinja', 'kajiki', 'chameleon']
 
 
+# Python 2.5 support shim.  TODO -- remove this in the future.
+if not hasattr(itertools, 'product'):
+    def product(*args):
+        if not args:
+            return iter(((),))  # yield tuple()
+        return (items + (item,)
+                for items in product(*args[:-1]) for item in args[-1])
+
+    itertools.product = product
+
+
 class TestWD(twc.Widget):
     test = twc.Param(default='bob')
 
+
 class TestTemplate(object):
     def setUp(self):
         testapi.setup()

tw2/core/templating.py

     else:
         filename = _get_dotted_filename(engine_name, template)
 
-    with open(filename, 'r') as f:
-        return f.read()
+    # TODO -- use a context manager here once we drop support for py2.5.
+    f = open(filename, 'r')
+
+    try:
+        source = f.read()
+    finally:
+        f.close()
+
+    return source
 
 
 @memoize

tw2/core/testbase/base.py

         self.request(1, mw)
         try:
             r = self.widget(_no_autoid=True, **attrs).display(**params)
-        except ValueError as e:
+        except ValueError, e:
             if str(e).startswith("Could not find engine name"):
                 raise SkipTest("No template for engine %r" % engine)
             else: