Skip to content

Commit

Permalink
Python2.5 support.
Browse files Browse the repository at this point in the history
  • Loading branch information
ralphbean committed May 21, 2012
1 parent 8324359 commit 66e93b6
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 3 deletions.
12 changes: 12 additions & 0 deletions tests/test_template.py
Expand Up @@ -9,9 +9,21 @@
engines = ['genshi', 'mako', 'jinja', 'kajiki', 'chameleon'] 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): class TestWD(twc.Widget):
test = twc.Param(default='bob') test = twc.Param(default='bob')



class TestTemplate(object): class TestTemplate(object):
def setUp(self): def setUp(self):
testapi.setup() testapi.setup()
Expand Down
11 changes: 9 additions & 2 deletions tw2/core/templating.py
Expand Up @@ -90,8 +90,15 @@ def get_source(engine_name, template, inline=False):
else: else:
filename = _get_dotted_filename(engine_name, template) filename = _get_dotted_filename(engine_name, template)


with open(filename, 'r') as f: # TODO -- use a context manager here once we drop support for py2.5.
return f.read() f = open(filename, 'r')

try:
source = f.read()
finally:
f.close()

return source




@memoize @memoize
Expand Down
2 changes: 1 addition & 1 deletion tw2/core/testbase/base.py
Expand Up @@ -207,7 +207,7 @@ def _check_rendering_vs_expected(self, engine, attrs, params, expected):
self.request(1, mw) self.request(1, mw)
try: try:
r = self.widget(_no_autoid=True, **attrs).display(**params) 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"): if str(e).startswith("Could not find engine name"):
raise SkipTest("No template for engine %r" % engine) raise SkipTest("No template for engine %r" % engine)
else: else:
Expand Down

0 comments on commit 66e93b6

Please sign in to comment.