aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES8
-rw-r--r--mako/__init__.py2
-rw-r--r--mako/runtime.py21
-rw-r--r--test/test_def.py3
4 files changed, 30 insertions, 4 deletions
diff --git a/CHANGES b/CHANGES
index 02c1539..3af9dc1 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+0.3.2
+- Calling a def from the top, via
+ 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]
+
+
0.3.1
- Fixed incorrect dir name in setup.py
[ticket:129]
diff --git a/mako/__init__.py b/mako/__init__.py
index 73a2f33..7a2f176 100644
--- a/mako/__init__.py
+++ b/mako/__init__.py
@@ -5,5 +5,5 @@
# the MIT License: http://www.opensource.org/licenses/mit-license.php
-__version__ = '0.3.1'
+__version__ = '0.3.2'
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:
diff --git a/test/test_def.py b/test/test_def.py
index 1f7a39a..fa5908e 100644
--- a/test/test_def.py
+++ b/test/test_def.py
@@ -82,6 +82,9 @@ class DefTest(TemplateTest):
filters=flatten_result)
self._do_test(template.get_def("body"), "this is the body", filters=flatten_result)
+ # test that args outside of the dict can be used
+ self._do_test(template.get_def("a"), "this is a",
+ filters=flatten_result, template_args={'q':5,'zq':'test'})
class ScopeTest(TemplateTest):
"""test scoping rules. The key is, enclosing scope always takes precedence over contextual scope."""