diff options
| author | Russell Keith-Magee <russell@keith-magee.com> | 2010-03-12 13:06:13 +0000 |
|---|---|---|
| committer | Russell Keith-Magee <russell@keith-magee.com> | 2010-03-12 13:06:13 +0000 |
| commit | 615eab6b0255608e2094f0ecf02c5351a1e887cc (patch) | |
| tree | 9e8a0cd86d10b58cadbcaf783bedaff917e7fd2b /django/utils | |
| parent | 5c256ddeecc2963121bce93db235c57a8380030c (diff) | |
Fixed #13093 -- Updated some decorators and the decorator_from_middleware function to allow callable classes to be decorated. Thanks to Brian Neal for the report.
git-svn-id: http://code.djangoproject.com/svn/django/trunk@12762 bcc190cf-cafb-0310-a4f2-bffc1f526a37
Diffstat (limited to 'django/utils')
| -rw-r--r-- | django/utils/decorators.py | 12 |
1 files changed, 9 insertions, 3 deletions
diff --git a/django/utils/decorators.py b/django/utils/decorators.py index 810d863849..84ec1bac00 100644 --- a/django/utils/decorators.py +++ b/django/utils/decorators.py @@ -2,9 +2,9 @@ import types try: - from functools import wraps, update_wrapper + from functools import wraps, update_wrapper, WRAPPER_ASSIGNMENTS except ImportError: - from django.utils.functional import wraps, update_wrapper # Python 2.3, 2.4 fallback. + from django.utils.functional import wraps, update_wrapper, WRAPPER_ASSIGNMENTS # Python 2.3, 2.4 fallback. def method_decorator(decorator): @@ -50,6 +50,12 @@ def decorator_from_middleware(middleware_class): """ return make_middleware_decorator(middleware_class)() +def available_attrs(fn): + """ + Return the list of functools-wrappable attributes on a callable. + This is required as a workaround for http://bugs.python.org/issue3445. + """ + return tuple(a for a in WRAPPER_ASSIGNMENTS if hasattr(fn, a)) def make_middleware_decorator(middleware_class): def _make_decorator(*m_args, **m_kwargs): @@ -77,6 +83,6 @@ def make_middleware_decorator(middleware_class): if result is not None: return result return response - return wraps(view_func)(_wrapped_view) + return wraps(view_func, assigned=available_attrs(view_func))(_wrapped_view) return _decorator return _make_decorator |
