Log message for revision 74715: To aid debugging, generate the facade with the same name as the original callable
Changed: U Zope/trunk/lib/python/AccessControl/requestmethod.py U Zope/trunk/lib/python/AccessControl/requestmethod.txt -=- Modified: Zope/trunk/lib/python/AccessControl/requestmethod.py =================================================================== --- Zope/trunk/lib/python/AccessControl/requestmethod.py 2007-04-24 18:21:57 UTC (rev 74714) +++ Zope/trunk/lib/python/AccessControl/requestmethod.py 2007-04-24 18:44:50 UTC (rev 74715) @@ -17,7 +17,7 @@ _default = [] -def _buildFacade(spec, docstring): +def _buildFacade(name, spec, docstring): """Build a facade function, matching the decorated method in signature. Note that defaults are replaced by _default, and _curried will reconstruct @@ -26,8 +26,8 @@ """ args = inspect.formatargspec(formatvalue=lambda v: '=_default', *spec) callargs = inspect.formatargspec(formatvalue=lambda v: '', *spec) - return 'def _facade%s:\n """%s"""\n return _curried%s' % ( - args, docstring, callargs) + return 'def %s%s:\n """%s"""\n return _curried%s' % ( + name, args, docstring, callargs) def requestmethod(*methods): """Create a request method specific decorator""" @@ -70,9 +70,10 @@ return callable(*args, **kw) # Build a facade, with a reference to our locally-scoped _curried + name = callable.__name__ facade_globs = dict(_curried=_curried, _default=_default) - exec _buildFacade(spec, callable.__doc__) in facade_globs - return facade_globs['_facade'] + exec _buildFacade(name, spec, callable.__doc__) in facade_globs + return facade_globs[name] return _methodtest Modified: Zope/trunk/lib/python/AccessControl/requestmethod.txt =================================================================== --- Zope/trunk/lib/python/AccessControl/requestmethod.txt 2007-04-24 18:21:57 UTC (rev 74714) +++ Zope/trunk/lib/python/AccessControl/requestmethod.txt 2007-04-24 18:44:50 UTC (rev 74715) @@ -57,12 +57,16 @@ >>> import inspect >>> mutabledefault = dict() >>> @requestmethod('POST') - ... def foo(bar, baz=mutabledefault, egg=mutabledefault, REQUEST=None, **kw): + ... def foo(bar, baz=mutabledefault, egg=mutabledefault, REQUEST=None, *args): ... return bar, baz is mutabledefault, egg is None, REQUEST >>> inspect.getargspec(foo)[:3] - (['bar', 'baz', 'egg', 'REQUEST'], None, 'kw') + (['bar', 'baz', 'egg', 'REQUEST'], 'args', None) >>> foo('spam', egg=None) ('spam', True, True, None) + >>> foo(monty='python') + Traceback (most recent call last): + ... + TypeError: foo() got an unexpected keyword argument 'monty' The requestmethod decorator factory can be used for any request method, simply pass in the desired request method:: _______________________________________________ Zope-Checkins maillist - Zope-Checkins@zope.org http://mail.zope.org/mailman/listinfo/zope-checkins