aboutsummaryrefslogtreecommitdiffstats
path: root/lib/mako
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2007-02-19 03:55:12 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2007-02-19 03:55:12 +0000
commit23dd29f0c9b4c27e82648cc02fe834052ef05f1c (patch)
tree20441f1815dfdc4e34f9c63e9d7a554ebab0ec5a /lib/mako
parent22194b40ce386a99d3439482d2c7ec7f3a7236e6 (diff)
downloadexternal_python_mako-23dd29f0c9b4c27e82648cc02fe834052ef05f1c.tar.gz
external_python_mako-23dd29f0c9b4c27e82648cc02fe834052ef05f1c.tar.bz2
external_python_mako-23dd29f0c9b4c27e82648cc02fe834052ef05f1c.zip
- improvement to scoping of "caller" variable when using <%call> tag
Diffstat (limited to 'lib/mako')
-rw-r--r--lib/mako/codegen.py5
-rw-r--r--lib/mako/runtime.py28
2 files changed, 27 insertions, 6 deletions
diff --git a/lib/mako/codegen.py b/lib/mako/codegen.py
index 477ccad..285e392 100644
--- a/lib/mako/codegen.py
+++ b/lib/mako/codegen.py
@@ -523,14 +523,15 @@ class _GenerateRenderMethod(object):
self.printer.writelines(
# push on global "caller" to be picked up by the next ccall
- "context.caller_stack.append(runtime.Namespace('caller', context, callables=ccall(context.caller_stack[-1])))",
+ "caller = context['caller']._get_actual_caller()",
+ "context.push_caller(runtime.Namespace('caller', context, callables=ccall(runtime._StackFacade(context, caller))))",
"try:")
self.write_source_comment(node)
self.printer.writelines(
"context.write(unicode(%s))" % node.attributes['expr'],
"finally:",
# pop it off
- "context.caller_stack.pop()",
+ "context.pop_caller()",
None
)
diff --git a/lib/mako/runtime.py b/lib/mako/runtime.py
index 20748b9..e6e640b 100644
--- a/lib/mako/runtime.py
+++ b/lib/mako/runtime.py
@@ -23,9 +23,13 @@ class Context(object):
# "caller" stack used by def calls with content
self.caller_stack = [Undefined]
- data['caller'] = _StackFacade(self.caller_stack)
+ data['caller'] = _StackFacade(self, None)
lookup = property(lambda self:self._with_template.lookup)
kwargs = property(lambda self:self._kwargs.copy())
+ def push_caller(self, caller):
+ self.caller_stack.append(caller)
+ def pop_caller(self):
+ del self.caller_stack[-1]
def keys(self):
return self._data.keys()
def __getitem__(self, key):
@@ -67,10 +71,26 @@ class Context(object):
return c
class _StackFacade(object):
- def __init__(self, stack):
- self.target = stack
+ def __init__(self, context, local):
+ self.__stack = context.caller_stack
+ self.__local = local
+ def _get_actual_caller(self):
+ caller = self.__stack[-1]
+ if caller is None:
+ return self.__local
+ else:
+ return caller
def __getattr__(self, key):
- return getattr(self.target[-1], key)
+ caller = self._get_actual_caller()
+ callable_ = getattr(caller, key)
+ def call_wno_caller(*args, **kwargs):
+ try:
+ self.__stack.append(None)
+ return callable_(*args, **kwargs)
+ finally:
+ self.__stack.pop()
+ return call_wno_caller
+
class Undefined(object):
"""represents an undefined value in a template."""