aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CHANGES5
-rw-r--r--lib/mako/runtime.py5
-rw-r--r--test/decorators.py44
3 files changed, 51 insertions, 3 deletions
diff --git a/CHANGES b/CHANGES
index a242785..b9de2ad 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,4 +1,9 @@
0.2.6
+
+- Fix mako function decorators to preserve the
+ original function's name in all cases. Patch
+ from Scott Torborg.
+
- Support the <%namespacename:defname> syntax in
the babel extractor. [ticket:118]
diff --git a/lib/mako/runtime.py b/lib/mako/runtime.py
index a75e6d8..ee6c5be 100644
--- a/lib/mako/runtime.py
+++ b/lib/mako/runtime.py
@@ -288,6 +288,11 @@ def _decorate_toplevel(fn):
def go(context, *args, **kw):
def y(*args, **kw):
return render_fn(context, *args, **kw)
+ try:
+ y.__name__ = render_fn.__name__[7:]
+ except TypeError:
+ # < Python 2.4
+ pass
return fn(y)(context, *args, **kw)
return go
return decorate_render
diff --git a/test/decorators.py b/test/decorators.py
index cf14fa6..2bd9e0d 100644
--- a/test/decorators.py
+++ b/test/decorators.py
@@ -68,8 +68,46 @@ class DecoratorTest(unittest.TestCase):
assert flatten_result(template.render()) == "BAT this is bar BAT"
-
-
+ def test_toplevel_decorated_name(self):
+ template = Template("""
+ <%!
+ def bar(fn):
+ def decorate(context, *args, **kw):
+ return "function " + fn.__name__ + " " + runtime.capture(context, fn, *args, **kw)
+ return decorate
+ %>
+
+ <%def name="foo(y, x)" decorator="bar">
+ this is foo ${y} ${x}
+ </%def>
+
+ ${foo(1, x=5)}
+ """)
+
+ assert flatten_result(template.render()) == "function foo this is foo 1 5"
+
+ def test_nested_decorated_name(self):
+ template = Template("""
+ <%!
+ def bat(fn):
+ def decorate(context):
+ return "function " + fn.__name__ + " " + runtime.capture(context, fn)
+ return decorate
+ %>
+
+ <%def name="foo()">
+
+ <%def name="bar()" decorator="bat">
+ this is bar
+ </%def>
+ ${bar()}
+ </%def>
+
+ ${foo()}
+ """)
+
+ assert flatten_result(template.render()) == "function bar this is bar"
+
+
if __name__ == '__main__':
unittest.main()
- \ No newline at end of file