MCPcopy Index your code
hub / github.com/fluentpython/example-code-2e / add_hook

Method add_hook

21-async/mojifinder/bottle.py:622–636  ·  view source on GitHub ↗

Attach a callback to a hook. Three hooks are currently implemented: before_request Executed once before each request. The request context is available, but no routing has happened yet. after_request Executed once after each re

(self, name, func)

Source from the content-addressed store, hash-verified

620 return dict((name, []) for name in self.__hook_names)
621
622 def add_hook(self, name, func):
623 ''' Attach a callback to a hook. Three hooks are currently implemented:
624
625 before_request
626 Executed once before each request. The request context is
627 available, but no routing has happened yet.
628 after_request
629 Executed once after each request regardless of its outcome.
630 app_reset
631 Called whenever :meth:`Bottle.reset` is called.
632 '''
633 if name in self.__hook_reversed:
634 self._hooks[name].insert(0, func)
635 else:
636 self._hooks[name].append(func)
637
638 def remove_hook(self, name, func):
639 ''' Remove a callback from a hook. '''

Callers 1

decoratorMethod · 0.95

Calls 2

insertMethod · 0.80
appendMethod · 0.45

Tested by

no test coverage detected