Skip to content

Commit

Permalink
- Fixed bug regarding <%call>/def calls w/ content
Browse files Browse the repository at this point in the history
  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]
  • Loading branch information
zzzeek committed Aug 5, 2011
1 parent 4f554cb commit 293531b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 2 deletions.
6 changes: 6 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
@@ -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]

Expand Down
4 changes: 2 additions & 2 deletions mako/codegen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
57 changes: 57 additions & 0 deletions test/test_call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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>
<%def name="B()">
B_def
${caller.body()}
</%def>
"""

template = Template(base + """
<%def name="C()">
C_def
<%self:B>
<%self:A>
A_body
</%self:A>
B_body
${caller.body()}
</%self:B>
</%def>
<%self:C>
C_body
</%self:C>
""")

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:A>
</%self:B>
</%def>
<%self:C>
C_body
</%self:C>
""")

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()">
Expand Down

0 comments on commit 293531b

Please sign in to comment.