Permalink
Browse files

Python2.5 support.

  • Loading branch information...
ralphbean committed May 21, 2012
1 parent 8324359 commit 66e93b66d89a8670d4763560eb34ade94e15195c
Showing with 22 additions and 3 deletions.
  1. +12 −0 tests/test_template.py
  2. +9 −2 tw2/core/templating.py
  3. +1 −1 tw2/core/testbase/base.py
@@ -9,9 +9,21 @@
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()
@@ -90,8 +90,15 @@ def get_source(engine_name, template, inline=False):
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
@@ -207,7 +207,7 @@ def _check_rendering_vs_expected(self, engine, attrs, params, expected):
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:

0 comments on commit 66e93b6

Please sign in to comment.