Here's the description. When identificators starting with else, elif, try, except,
finally, while, for, def and class are present inside template context, code generator
gets confused about indentions.
So the generated code looks like this:
Of course, prefixes and abbreviations can be used, but I think this is unmotivated
constrain. Especially when it is only about syntax test for variable name in Python.
Only few changes in regular expressions are needed inside '''mako.pygen.PythonPrinter.writeline''' and
'''mako.pygen.PythonPrinter._is_unindentor''', simply by writing this:
Maybe, I've missed something, but the code seems to work now.
Here's (if you can say it) the patch from version which I currently use.
< from StringIO import StringIO
> from cStringIO import StringIO
> except ImportError:
> from StringIO import StringIO
< match = re.match(r"^\s*(if|try|elif|while|for)", line)
> match = re.match(r"^\s*(if|try|elif|while|for)[^\da-zA-Z_]+", line)
< m2 = re.match(r"^\s*(def|class|else|elif|except|finally)", line)
> m2 = re.match(r"^\s*(def|class|else|elif|except|finally)[^\da-zA-Z_]", line)
< match = re.match(r"^\s*(else|elif|except|finally)", line)
> match = re.match(r"^\s*(else|elif|except|finally)[^\da-zA-Z_]+", line)
I have a short fix for this in f636709, which resolves the failing test case I was able to create. But I don't know what tests fail for you since you didn't post any, so feel free to post those if this fix doesn't resolve the issue.