From 71386ea95373d6cad6acb5bae54027c4c8cf35ba Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Fri, 12 Oct 2007 19:26:06 +0000
Subject: [PATCH] - fixed propagation of 'caller' such that nested %def calls  
 within a <%call> tag's argument list propigates 'caller'   to the %call
 function itself (propigates to the inner   calls too, this is a slight side
 effect which previously   existed anyway)

---
 CHANGES             |  7 +++++++
 lib/mako/runtime.py |  6 +++---
 setup.py            |  2 +-
 test/call.py        | 25 +++++++++++++++++++++++++
 4 files changed, 36 insertions(+), 4 deletions(-)

diff --git a/CHANGES b/CHANGES
index 7132504..9f1efe9 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,10 @@
+0.1.10
+- fixed propagation of 'caller' such that nested %def calls
+  within a <%call> tag's argument list propigates 'caller'
+  to the %call function itself (propigates to the inner
+  calls too, this is a slight side effect which previously
+  existed anyway)
+
 0.1.9
 - filters.Decode filter can also accept a non-basestring
 object and will call str() + unicode() on it [ticket:47]
diff --git a/lib/mako/runtime.py b/lib/mako/runtime.py
index c44b633..628496e 100644
--- a/lib/mako/runtime.py
+++ b/lib/mako/runtime.py
@@ -73,16 +73,16 @@ class CallerStack(list):
     def __init__(self):
         self.nextcaller = None
     def __nonzero__(self):
-          return self._get_caller() and True or False
+        return self._get_caller() and True or False
     def _get_caller(self):
-        return self.nextcaller or self[-1]
+        return self[-1]
     def __getattr__(self, key):
         return getattr(self._get_caller(), key)
     def push_frame(self):
         self.append(self.nextcaller or None)
         self.nextcaller = None
     def pop_frame(self):
-        self.pop()
+        self.nextcaller = self.pop()
         
         
 class Undefined(object):
diff --git a/setup.py b/setup.py
index 4281cf7..53f2e50 100644
--- a/setup.py
+++ b/setup.py
@@ -1,6 +1,6 @@
 from setuptools import setup, find_packages
 
-version = '0.1.9'
+version = '0.1.10'
 
 setup(name='Mako',
       version=version,
diff --git a/test/call.py b/test/call.py
index 8de429c..52ebeb0 100644
--- a/test/call.py
+++ b/test/call.py
@@ -87,6 +87,31 @@ class CallTest(unittest.TestCase):
             "OUTER END",
         ]
     
+    def test_stack_pop(self):
+        t = Template("""
+        <%def name="links()" buffered="True">
+           Some links
+        </%def>
+
+        <%def name="wrapper(links)">
+           <h1>${caller.body()}</h1>
+           ${links}
+        </%def>
+
+        ## links() pushes a stack frame on.  when complete,
+        ## 'nextcaller' must be restored
+        <%call expr="wrapper(links())">
+           Some title
+        </%call>
+
+        """)
+        assert result_lines(t.render()) == [
+        "<h1>",
+        "Some title",
+        "</h1>",
+        "Some links"
+        ]
+        
     def test_conditional_call(self):
         """test that 'caller' is non-None only if the immediate <%def> was called via <%call>"""
 
-- 
GitLab