Copy more attributes from controller callables to partial wrappers

master
Dustin C. Hatch 2011-04-15 21:04:24 -05:00
parent 92ba7c9387
commit 92ef80fd61
1 changed files with 11 additions and 4 deletions

View File

@ -94,10 +94,17 @@ class Router(object):
urlvars = match.groupdict()
urlvars.update(vars)
func = functools.partial(controller, **urlvars)
if hasattr(func, '__name__'):
func.__name__ = controller.__name__
if hasattr(func, '__doc__'):
func.__doc__ = controller.__doc__
# Work around for Python Issue 3445 for older versions
for attr in functools.WRAPPER_ASSIGNMENTS:
try:
value = getattr(controller, attr)
except AttributeError:
pass
else:
setattr(func, attr, value)
for attr in functools.WRAPPER_UPDATES:
getattr(func, attr).update(getattr(controller,
attr, {}))
self._cache[path_info] = func
return func