diff options
-rw-r--r-- | cherrypy/_cpdispatch.py | 10 | ||||
-rw-r--r-- | cherrypy/test/test_objectmapping.py | 15 |
2 files changed, 23 insertions, 2 deletions
diff --git a/cherrypy/_cpdispatch.py b/cherrypy/_cpdispatch.py index 7289e494..1c2d7df8 100644 --- a/cherrypy/_cpdispatch.py +++ b/cherrypy/_cpdispatch.py @@ -93,11 +93,11 @@ def test_callable_spec(callable, callable_args, callable_kwargs): show_mismatched_params = getattr( cherrypy.serving.request, 'show_mismatched_params', False) try: - (args, varargs, varkw, defaults) = inspect.getargspec(callable) + (args, varargs, varkw, defaults) = getargspec(callable) except TypeError: if isinstance(callable, object) and hasattr(callable, '__call__'): (args, varargs, varkw, - defaults) = inspect.getargspec(callable.__call__) + defaults) = getargspec(callable.__call__) else: # If it wasn't one of our own types, re-raise # the original error @@ -205,6 +205,12 @@ try: import inspect except ImportError: test_callable_spec = lambda callable, args, kwargs: None +else: + getargspec = inspect.getargspec + # Python 3 requires using getfullargspec if keyword-only arguments are present + if hasattr(inspect, 'getfullargspec'): + def getargspec(callable): + return inspect.getfullargspec(callable)[:4] class LateParamPageHandler(PageHandler): diff --git a/cherrypy/test/test_objectmapping.py b/cherrypy/test/test_objectmapping.py index 28362b63..e80a7a71 100644 --- a/cherrypy/test/test_objectmapping.py +++ b/cherrypy/test/test_objectmapping.py @@ -1,3 +1,4 @@ +import sys import cherrypy from cherrypy._cpcompat import ntou from cherrypy._cptree import Application @@ -414,3 +415,17 @@ class ObjectMappingTest(helper.CPWebCase): a = Application(Root(), script_name=None) # However, this does not apply to tree.mount self.assertRaises(TypeError, cherrypy.tree.mount, a, None) + + def testKeywords(self): + if sys.version_info < (3,): + return self.skip("skipped (Python 3 only)") + exec("""class Root(object): + @cherrypy.expose + def hello(self, *, name='world'): + return 'Hello %s!' % name +cherrypy.tree.mount(Application(Root(), '/keywords'))""") + + self.getPage('/keywords/hello') + self.assertStatus(200) + self.getPage('/keywords/hello/extra') + self.assertStatus(404) |