diff --git a/CHANGES b/CHANGES index 63410aa2165ccc70d6bbb221849d19ed329c4d90..9db47224595a04572110ce34f8af2e406343d821 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,8 @@ +0.2.0 +- fixed bug in python generation when variable names are used + with identifiers like "else", "finally", etc. inside them + [ticket:68] + 0.1.10 - fixed propagation of 'caller' such that nested %def calls within a <%call> tag's argument list propigates 'caller' diff --git a/lib/mako/pygen.py b/lib/mako/pygen.py index 01ed09283b9324dc42eaa1586c6d74776cff69f3..78310cf4d806c07148c849ef0a2d8ed38bb61677 100644 --- a/lib/mako/pygen.py +++ b/lib/mako/pygen.py @@ -138,7 +138,7 @@ class PythonPrinter(object): # if the current line doesnt have one of the "unindentor" keywords, # return False - match = re.match(r"^\s*(else|elif|except|finally)", line) + match = re.match(r"^\s*(else|elif|except|finally).*\:", line) if not match: return False diff --git a/setup.py b/setup.py index 53f2e502bd0c3aa6f4b34d1bea662fdf842c0324..f61a6aefb0af933b112bc9e139ec82351c0fcad7 100644 --- a/setup.py +++ b/setup.py @@ -1,6 +1,6 @@ from setuptools import setup, find_packages -version = '0.1.10' +version = '0.2.0' setup(name='Mako', version=version, diff --git a/test/pygen.py b/test/pygen.py index cfb8ae701a590ef905684feebdaa92c2425d24f8..f7965de912f168ab716ffa5adfec3453c70fc7d3 100644 --- a/test/pygen.py +++ b/test/pygen.py @@ -99,7 +99,32 @@ and more block. do_more_stuff(g) """ - + + def test_false_unindendor(self): + stream = StringIO() + printer = PythonPrinter(stream) + for line in [ + "try:", + "elsemyvar = 12", + "if True:", + "print 'hi'", + None, + "finally:", + "dosomething", + None + ]: + printer.writeline(line) + + assert stream.getvalue() == \ +"""try: + elsemyvar = 12 + if True: + print 'hi' +finally: + dosomething +""" , stream.getvalue() + + def test_backslash_line(self): block = \ """