diff options
author | Marcel Hellkamp <marc@gsites.de> | 2011-11-22 19:27:58 +0100 |
---|---|---|
committer | Marcel Hellkamp <marc@gsites.de> | 2011-11-22 19:27:58 +0100 |
commit | 5e57ead62ee563fdd2f3e2a9d0e8ae060a093bce (patch) | |
tree | 881cc335cc33d27ed374ee67868964643af79504 | |
parent | f382779cec246e14dbcde3bb4a394acdbfc1dfca (diff) | |
download | bottle-5e57ead62ee563fdd2f3e2a9d0e8ae060a093bce.tar.gz |
fix: Workaround for bug in functools.update_wrapper() (fixes #223 #224)
Thanks to Brian Wickman
-rwxr-xr-x | bottle.py | 7 | ||||
-rw-r--r-- | test/test_plugins.py | 9 |
2 files changed, 15 insertions, 1 deletions
@@ -123,6 +123,10 @@ def tob(data, enc='utf8'): tonat = touni if py3k else tob tonat.__doc__ = """ Convert anything to native strings """ +def try_update_wrapper(wrapper, wrapped, *a, **ka): + try: # Bug: functools breaks if wrapper is an instane method + functools.update_wrapper(wrapper, wrapped, *a, **ka) + except AttributeError: pass # Backward compatibility def depr(message): @@ -508,7 +512,8 @@ class Route(object): callback = plugin(callback) except RouteReset: # Try again with changed configuration. return self._make_callback() - functools.update_wrapper(callback, self.callback) + if not callback is self.callback: + try_update_wrapper(callback, self.callback) return callback diff --git a/test/test_plugins.py b/test/test_plugins.py index b16ae43..c6d190d 100644 --- a/test/test_plugins.py +++ b/test/test_plugins.py @@ -182,6 +182,15 @@ class TestPluginAPI(tools.ServerTestBase): self.app.install(Plugin()) self.assertBody('test:plugin.cfg; tail', '/') + def test_instance_method_wrapper(self): + class Plugin(object): + api=2 + def apply(self, callback, route): + return self.b + def b(self): return "Hello" + self.app.install(Plugin()) + self.assertBody('Hello', '/') + def test_setup(self): class Plugin(object): def __call__(self, func): return func |