Skip to content

Commit

Permalink
- fix #190 for py2.4
Browse files Browse the repository at this point in the history
- other 2.4 ism
  • Loading branch information
zzzeek committed Aug 4, 2013
1 parent 82d4954 commit 10ca8d3
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 6 deletions.
3 changes: 2 additions & 1 deletion CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
[ticket:207]

- [bug] Fixed Py3K bug where a "lambda" expression was not
interpreted correctly within a template tag. [ticket:190]
interpreted correctly within a template tag; also
fixed in Py2.4. [ticket:190]

0.8.1
- [bug] Changed setup.py to skip installing markupsafe
Expand Down
21 changes: 21 additions & 0 deletions mako/pyparser.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,27 @@ def visitCallFunc(self, node, *args):
self.visit(a)
self.buf.write(')')

def visitLambda(self, node, *args):
self.buf.write('lambda ')

argnames = list(node.argnames)

kw = arg = None
if node.kwargs > 0:
kw = argnames.pop(-1)
if node.varargs > 0:
arg = argnames.pop(-1)

if arg:
argnames.append("*%s" % arg)
if kw:
argnames.append("**%s" % kw)

self.buf.write(", ".join(argnames))

self.buf.write(': ')
self.visit(node.code)


class walker(visitor.ASTVisitor):

Expand Down
12 changes: 8 additions & 4 deletions test/test_ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -316,7 +316,8 @@ def lala(arg):
"repr({'x':-1})", "repr(((1,2,3), (4,5,6)))",
"repr(1 and 2 and 3 and 4)",
"repr(True and False or 55)",
"repr(lambda x, y: x+y)",
"repr(lambda x, y: (x + y))",
"repr(lambda *arg, **kw: arg, kw)",
"repr(1 & 2 | 3)",
"repr(3//5)",
"repr(3^5)",
Expand All @@ -327,9 +328,12 @@ def lala(arg):
local_dict = {}
astnode = pyparser.parse(code)
newcode = pyparser.ExpressionGenerator(astnode).value()
eq_(eval(code, local_dict),
eval(newcode, local_dict)
)
if "lambda" in code:
eq_(code, newcode)
else:
eq_(eval(code, local_dict),
eval(newcode, local_dict)
)



2 changes: 1 addition & 1 deletion test/test_runtime.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"""
from mako import runtime
import unittest
from . import eq_
from test import eq_

class ContextTest(unittest.TestCase):
def test_locals_kwargs(self):
Expand Down

0 comments on commit 10ca8d3

Please sign in to comment.