From f6367091734ee62cd72f30e6b2125ec86956565d Mon Sep 17 00:00:00 2001 From: Mike Bayer <mike_mp@zzzcomputing.com> Date: Fri, 11 Jan 2008 22:11:24 +0000 Subject: [PATCH] - fixed bug in python generation when variable names are used with identifiers like "else", "finally", etc. inside them [ticket:68] --- CHANGES | 5 +++++ lib/mako/pygen.py | 2 +- setup.py | 2 +- test/pygen.py | 27 ++++++++++++++++++++++++++- 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CHANGES b/CHANGES index 63410aa..9db4722 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 01ed092..78310cf 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 53f2e50..f61a6ae 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 cfb8ae7..f7965de 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 = \ """ -- GitLab