Interceptors

Interceptors can be thought of as hooks for your hooks.

from pytapable import Hook, HookInterceptor


class TapLogger(HookInterceptor):

    def register(self, tap):
        print(f"Hook being tapped by '${tap.name}'")
        return tap

tap_logger = TapLogger()

my_hook = Hook(interceptor=tap_logger)
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.

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

register(tap)[source]

Triggered for each added tap and allows you to modify the tap

Parameters

tap (Tap) – The Tap that is going to be installed on the hook

Returns

The Tap to install on the hook

Return type

modified_tap (Tap)

Tap

class pytapable.Tap(name, fn)[source]

A Tap is an object created when you tap into a hook. It holds a reference to the function you want to execute when the hook triggers