test_callable_spec(self.callable, self.args, self.kwargs)
+# Taken from: http://kbyanc.blogspot.com/2007/07/python-more-generic-getargspec.html
+# License found at: http://kbyanc.blogspot.com/2007/08/license-for-code-posted-on-my-blog.html
+# Modified by Lakin Wecker (c) 2008:
+# - don't remove the implicit 'self' argument
+# - Be a bit more Pythonic and shorter
+# - Classes can't be handlers because their __init__ can't return anything, don't bother.
+# the getargspect function below is licensed under the following license:
+Copyright (c) 2007, Kelly Yancey
+Permission is hereby granted, free of charge, to any person obtaining a copy
+of this software and associated documentation files (the "Software"), to deal
+in the Software without restriction, including without limitation the rights
+to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+copies of the Software, and to permit persons to whom the Software is
+furnished to do so, subject to the following conditions:
+The above copyright notice and this permission notice shall be included in
+all copies or substantial portions of the Software.
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ """Get the names and default values of a callable's
+ A tuple of four things is returned: (args, varargs,
+ - args is a list of the argument names (it may
+ - varargs and varkw are the names of the * and
+ - defaults is a tuple of default argument values
+ or None if there are no default arguments; if
+ this tuple has n elements, they correspond to
+ the last n elements listed in args.
+ Unlike inspect.getargspec(), can return argument
+ specification for functions, methods, callable
+ objects, and classes. Does not support builtin
+ return inspect.getargspec(obj)
+ if hasattr(obj, 'im_func'):
+ # NB: We use im_func so we work with
+ # instancemethod objects also.
+ spec = list(inspect.getargspec(obj.im_func))
+ elif isinstance(obj, object) and hasattr(obj, '__call__'):
+ return getargspec(obj.__call__)
+ # If it wasn't one of our own types, re-raise
def test_callable_spec(callable, callable_args, callable_kwargs):
Inspect callable and test to see if the given args are suitable for it.
incorrect, then a 404 Not Found should be raised. Conversely the body
parameters are part of the request; if they are invalid a 400 Bad Request.
- (args, varargs, varkw, defaults) =
+ (args, varargs, varkw, defaults) = getargspec(callable)
if args and args == 'self':