def handler_context(self, type_, from_, cb, *, wildcard_resource=True):
        """
        Context manager which temporarily registers a callback.

        The arguments are the same as for :meth:`register_callback`.

        When the context is entered, the callback `cb` is registered. When the
        context is exited, no matter if an exception is raised or not, the
        callback is unregistered.
        """
        self.register_callback(
            type_, from_, cb,
            wildcard_resource=wildcard_resource
        )
        try:
            yield
        finally:
            self.unregister_callback(
                type_, from_,
                wildcard_resource=wildcard_resource
            )
Context manager which temporarily registers a callback.

        The arguments are the same as for :meth:`register_callback`.

        When the context is entered, the callback `cb` is registered. When the
        context is exited, no matter if an exception is raised or not, the
        callback is unregistered.