From 49e09a06c58c84b043634380525af45c4b31e60d Mon Sep 17 00:00:00 2001
From: Mike Bayer <mike_mp@zzzcomputing.com>
Date: Mon, 3 Dec 2007 22:56:49 +0000
Subject: [PATCH] - fixed another namespace bug where the namespace functions  
 did not have access to the correct context containing   their 'self' and
 'parent'

---
 CHANGES             |  5 ++++-
 lib/mako/runtime.py |  2 +-
 test/namespace.py   | 34 ++++++++++++++++++++++++++++++++++
 3 files changed, 39 insertions(+), 2 deletions(-)

diff --git a/CHANGES b/CHANGES
index 75c1543..63410aa 100644
--- a/CHANGES
+++ b/CHANGES
@@ -6,7 +6,10 @@
   existed anyway)
 - fixed bug where local.get_namespace() could put an 
   incorrect "self" in the current context
-
+- fixed another namespace bug where the namespace functions
+  did not have access to the correct context containing
+  their 'self' and 'parent'
+  
 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 d08a209..dd4aade 100644
--- a/lib/mako/runtime.py
+++ b/lib/mako/runtime.py
@@ -120,7 +120,7 @@ class Namespace(object):
         else:
             self.callables = None
         if populate_self and self.template is not None:
-            (lclcallable, self.context) = _populate_self_namespace(context, self.template, self_ns=self)
+            (lclcallable, lclcontext) = _populate_self_namespace(context, self.template, self_ns=self)
 
     module = property(lambda s:s._module or s.template.module)
     filename = property(lambda s:s._module and s._module.__file__ or s.template.filename)
diff --git a/test/namespace.py b/test/namespace.py
index 9be445c..36b811b 100644
--- a/test/namespace.py
+++ b/test/namespace.py
@@ -282,6 +282,40 @@ class NamespaceTest(unittest.TestCase):
             "this is index",
             "this is ns.html->bar"
         ]
+
+    def test_inheritance_two(self):
+        collection = lookup.TemplateLookup()
+        collection.put_string("base.html", """
+            <%def name="foo()">
+                base.foo
+            </%def>
+            
+            <%def name="bat()">
+                base.bat
+            </%def>
+""")
+        collection.put_string("lib.html", """
+            <%inherit file="base.html"/>
+            <%def name="bar()">
+                lib.bar
+                ${parent.foo()}
+                ${self.foo()}
+                ${parent.bat()}
+                ${self.bat()}
+            </%def>
+            
+            <%def name="foo()">
+                lib.foo
+            </%def>
+                
+        """)
+
+        collection.put_string("front.html", """
+            <%namespace name="lib" file="lib.html"/>
+            ${lib.bar()}
+        """)
+
+        assert result_lines(collection.get_template("front.html").render()) == ['lib.bar', 'base.foo', 'lib.foo', 'base.bat', 'base.bat']
         
     def test_ccall(self):
         collection = lookup.TemplateLookup()
-- 
GitLab