diff options
author | Balazs Scheidler <bazsi@balabit.hu> | 2014-03-12 08:49:14 +0100 |
---|---|---|
committer | Balazs Scheidler <bazsi@balabit.hu> | 2014-03-12 08:49:14 +0100 |
commit | 893f3099b96c2be2b8fe53516352baba37a87746 (patch) | |
tree | 2746ad0340eb7204e76a5d1995c93c4d0a626c42 | |
parent | 6d3befa380713f8e1afa9c282a1eaadef09d753c (diff) | |
download | cherrypy-893f3099b96c2be2b8fe53516352baba37a87746.tar.gz |
HandlerWrapperTool: handle config arguments properly
It is possible to pass configuration variables to tools created using
HandlerWrapperTool, either via the config file, _cp_config or explicit
decorator arguments.
As HandlerWrapperTool passes these configuration variables as arguments to
the HandlerWrapperTool.callable() method, the callable method must have a
signature that actually accepts any arguments. These are not passed on to
the actual handler function, that might work with those using explicit
config.get() calls.
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
-rw-r--r-- | cherrypy/_cptools.py | 2 | ||||
-rw-r--r-- | cherrypy/test/test_tools.py | 4 |
2 files changed, 4 insertions, 2 deletions
diff --git a/cherrypy/_cptools.py b/cherrypy/_cptools.py index 2f24e65f..97ea53fe 100644 --- a/cherrypy/_cptools.py +++ b/cherrypy/_cptools.py @@ -215,7 +215,7 @@ class HandlerWrapperTool(Tool): self._name = name self._priority = priority - def callable(self, debug=False): + def callable(self, *args, **kwargs): innerfunc = cherrypy.serving.request.handler def wrap(*args, **kwargs): return self.newhandler(innerfunc, *args, **kwargs) diff --git a/cherrypy/test/test_tools.py b/cherrypy/test/test_tools.py index 21ada1f7..41e19a00 100644 --- a/cherrypy/test/test_tools.py +++ b/cherrypy/test/test_tools.py @@ -103,6 +103,7 @@ class ToolTests(helper.CPWebCase): cherrypy.tools.rotator = cherrypy.Tool('before_finalize', Rotator()) def stream_handler(next_handler, *args, **kwargs): + assert cherrypy.request.config.get('tools.streamer.arg') == 'arg value' cherrypy.response.output = o = BytesIO() try: response = next_handler(*args, **kwargs) @@ -118,10 +119,11 @@ class ToolTests(helper.CPWebCase): index.exposed = True def tarfile(self): + assert cherrypy.request.config.get('tools.streamer.arg') == 'arg value' cherrypy.response.output.write(ntob('I am ')) cherrypy.response.output.write(ntob('a tarfile')) tarfile.exposed = True - tarfile._cp_config = {'tools.streamer.on': True} + tarfile._cp_config = {'tools.streamer.on': True, 'tools.streamer.arg': 'arg value'} def euro(self): hooks = list(cherrypy.request.hooks['before_finalize']) |