aboutsummaryrefslogtreecommitdiffstats
path: root/mako/runtime.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2010-03-11 22:04:28 +0000
committerMike Bayer <mike_mp@zzzcomputing.com>2010-03-11 22:04:28 +0000
commit2bf553ee966e55975df32558588afe31308ad75b (patch)
tree7fad8df321b995d65d3be6770d0fc953423adf01 /mako/runtime.py
parent838a8d6330a21f63e23425563782c93c920a8f97 (diff)
downloadexternal_python_mako-2bf553ee966e55975df32558588afe31308ad75b.tar.gz
external_python_mako-2bf553ee966e55975df32558588afe31308ad75b.tar.bz2
external_python_mako-2bf553ee966e55975df32558588afe31308ad75b.zip
- Calling a def from the top, viarel_0_3_2
template.get_def(...).render() now checks the argument signature the same way as it did in 0.2.5, so that TypeError is not raised. reopen of [ticket:116]
Diffstat (limited to 'mako/runtime.py')
-rw-r--r--mako/runtime.py21
1 files changed, 18 insertions, 3 deletions
diff --git a/mako/runtime.py b/mako/runtime.py
index 8811fd6..863b4e7 100644
--- a/mako/runtime.py
+++ b/mako/runtime.py
@@ -338,7 +338,7 @@ def _include_file(context, uri, calling_uri, **kwargs):
template = _lookup_template(context, uri, calling_uri)
(callable_, ctx) = _populate_self_namespace(context._clean_inheritance_tokens(), template)
- callable_(ctx, **_kwargs_for_callable(callable_, context._orig, **kwargs))
+ callable_(ctx, **_kwargs_for_include(callable_, context._orig, **kwargs))
def _inherit_from(context, uri, calling_uri):
"""called by the _inherit method in template modules to set up the inheritance chain at the start
@@ -399,10 +399,25 @@ def _render(template, callable_, args, data, as_unicode=False):
context = Context(buf, **data)
context._outputting_as_unicode = as_unicode
context._with_template = template
- _render_context(template, callable_, context, *args, **data)
+
+ _render_context(template, callable_, context, *args, **_kwargs_for_callable(callable_, data))
return context._pop_buffer().getvalue()
-def _kwargs_for_callable(callable_, data, **kwargs):
+def _kwargs_for_callable(callable_, data):
+ argspec = inspect.getargspec(callable_)
+ # for normal pages, **pageargs is usually present
+ if argspec[2]:
+ return data
+
+ # for rendering defs from the top level, figure out the args
+ namedargs = argspec[0] + [v for v in argspec[1:3] if v is not None]
+ kwargs = {}
+ for arg in namedargs:
+ if arg != 'context' and arg in data and arg not in kwargs:
+ kwargs[arg] = data[arg]
+ return kwargs
+
+def _kwargs_for_include(callable_, data, **kwargs):
argspec = inspect.getargspec(callable_)
namedargs = argspec[0] + [v for v in argspec[1:3] if v is not None]
for arg in namedargs: