From 293531b5e4eac04c4e8364712137c24c4d1165f3 Mon Sep 17 00:00:00 2001 From: Mike Bayer Date: Fri, 5 Aug 2011 17:42:31 -0400 Subject: [PATCH] - Fixed bug regarding <%call>/def calls w/ content whereby the identity of the "caller" callable inside the <%def> would be corrupted by the presence of another <%call> in the same block. [ticket:170] --- CHANGES | 6 +++++ mako/codegen.py | 4 ++-- test/test_call.py | 57 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 65 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index 6dfc012..a6bae66 100644 --- a/CHANGES +++ b/CHANGES @@ -1,4 +1,10 @@ 0.4.2 +- Fixed bug regarding <%call>/def calls w/ content + whereby the identity of the "caller" callable + inside the <%def> would be corrupted by the + presence of another <%call> in the same block. + [ticket:170] + - Fixed the babel plugin to accommodate <%block> [ticket:169] diff --git a/mako/codegen.py b/mako/codegen.py index 5369180..b8c6382 100644 --- a/mako/codegen.py +++ b/mako/codegen.py @@ -847,10 +847,10 @@ def visitDefOrBase(s, node): self.printer.writelines( # get local reference to current caller, if any - "caller = context.caller_stack._get_caller()", + "__M_caller = context.caller_stack._get_caller()", # push on caller for nested call "context.caller_stack.nextcaller = " - "runtime.Namespace('caller', context, callables=ccall(caller))", + "runtime.Namespace('caller', context, callables=ccall(__M_caller))", "try:") self.write_source_comment(node) self.printer.writelines( diff --git a/test/test_call.py b/test/test_call.py index 6aadf62..5f13e95 100644 --- a/test/test_call.py +++ b/test/test_call.py @@ -279,6 +279,63 @@ def test_nested_call_3(self): ''') assert flatten_result(template.render()) == "foo" + def test_nested_call_4(self): + base = """ + <%def name="A()"> + A_def + ${caller.body()} + + + <%def name="B()"> + B_def + ${caller.body()} + + """ + + template = Template(base + """ + <%def name="C()"> + C_def + <%self:B> + <%self:A> + A_body + + B_body + ${caller.body()} + + + + <%self:C> + C_body + + """) + + eq_( + flatten_result(template.render()), + "C_def B_def A_def A_body B_body C_body" + ) + + template = Template(base + """ + <%def name="C()"> + C_def + <%self:B> + B_body + ${caller.body()} + <%self:A> + A_body + + + + + <%self:C> + C_body + + """) + + eq_( + flatten_result(template.render()), + "C_def B_def B_body C_body A_def A_body" + ) + def test_chained_call_in_nested(self): t = Template(""" <%def name="embedded()">