Download Install Tutorial Docs FAQ Tools WikiLicense Team IRC Planet Involvement Shop Book

Ticket #565 (enhancement)

Opened 2 years ago

Last modified 2 years ago

Allow hooks to be programmatically attached

Status: closed (fixed)

Reported by: michele Assigned to: rdelon
Priority: normal Milestone: 3.0
Component: CherryPy code Keywords:
Cc:

At the moment you can't programmatically attach hooks so that they are *always* executed without enabling them in configuration.

The problem is that the respond method of the Request class overwrites the hooks attribute with a new HookMap? object without keeping hooks defined at the class level.

The patch is just one line:

Index: _cprequest.py
===================================================================
--- _cprequest.py       (revision 1367)
+++ _cprequest.py       (working copy)
@@ -525,6 +525,7 @@
                         self.process_headers()

                     self.hooks = HookMap(self.hookpoints)
+                    self.hooks.update(self.__class__.hooks)
                     self.get_resource(path_info)
                     self.configure()

with it you can do things like:

cherrypy.engine.request_class.hooks.attach("before_handler", my_func)

Change History

09/16/06 17:40:38: Modified by fumanchu

  • status changed from new to closed.
  • resolution set to fixed.
  • summary changed from [PATCH] Allow hooks to be programmatically attached to Allow hooks to be programmatically attached.

Fixed in [1371] (with a custom copy method for HookMap?).

Hosted by WebFaction

Log in as guest/cpguest to create tickets