Interceptors¶
Interceptors can be thought of as hooks for your hooks.
from pytapable import Hook, HookInterceptor
class TapLogger(HookInterceptor):
def create(self, hook):
print(f"Hook {hook.name} initialized")
def register(self, context, tap):
print(f"Hook being tapping is '${context['hook']}'")
print(f"Hook being tapped by '${tap.name}'")
return tap
tap_logger = TapLogger()
my_hook = Hook(interceptor=tap_logger)
>>> Hook XYZ initialized
my_hook.tap('My Tap', my_callback)
>>> Hook being tapped by 'My Tap'
They are a mechanism for you to intercept whenever one of your hooks are tapped into or when a hook was created
The return value of the register
method must be a tap. If you need to modify the behavior of the callback in the
tap, this is the place to do it.
API Documentation¶
HookInterceptor¶
-
class
pytapable.
HookInterceptor
[source]¶ Interceptors allow you to intercept actions that are being performed on hooks and optionally modify it
-
create
(hook)[source]¶ Triggered when a hook has been initialized
- Parameters
hook (BaseHook) – The hook that was created
-