Skip to content

Handlers

diffusion.handlers

Base module for various event handlers.

Handler

Bases: Protocol

Protocol for event handlers implementation.

handle async

handle(event: str, **kwargs: typing.Any) -> typing.Any

Implements handling of the given event.

Parameters:

Name Type Description Default
event str

The event identifier.

required
**kwargs typing.Any

Additional arguments.

{}

UnknownHandlerError

Bases: exceptions.DiffusionError

Raised when a requested handler key has not been registered in the session.

SimpleHandler

Bases: Handler

Wraps a callable into a Handler protocol instance.

handle async

handle(event: str = '', **kwargs: typing.Any)

Implements handling of the given event.

Parameters:

Name Type Description Default
event str

The event identifier.

''
**kwargs typing.Any

Additional arguments.

{}

AbstractHandlerSet

Bases: Handler, typing.Iterable[Handler]

handle async

handle(event: str = '', **kwargs: typing.Any) -> typing.Any

Implements handling of the given event.

Parameters:

Name Type Description Default
event str

The event identifier.

''
**kwargs typing.Any

Additional arguments.

{}

Returns:

Type Description
typing.Any

Aggregated list of returned values.

HandlerSet

Bases: set, AbstractHandlerSet

A collection of handlers to be invoked together.

EventStreamHandler

Bases: Handler

Generic handler of event streams.

Each keyword argument is a callable which will be converted to coroutine and awaited to handle the event matching the argument keyword.

handle async

handle(event: str, **kwargs: typing.Any)

Implements handling of the given event.

Parameters:

Name Type Description Default
event str

The event identifier.

required
**kwargs typing.Any

Additional arguments.

{}