deirokay.backend.MultiBackendMixin

class deirokay.backend.MultiBackendMixin[source]

Bases: object

Mixin class which all multi-backend resources in Deirokay derives from.

Together with the register_backend_method decorator, the methods of its subclasses can be marked to be active when a particular backend is active.

Methods

attach_backend

Generate a subclass that concretizes multibackend backend methods into their intended name.

get_backend

Get current active backend for this class.

register_backend_method

Proxy for register_backend_method to register an existing function as a backend-specific method.

Attributes

supported_backends

Backends supported by this resource.

classmethod __post_attach_backend__()[source]

This classmethod can be optionally overwritten to serve as a callback function for when the attach_backend() method is called.

classmethod attach_backend(backend: Backend) Type[_AnyMultiBackendClass][source]

Generate a subclass that concretizes multibackend backend methods into their intended name. The methods marked with the given backend will compose the returned class.

Parameters
  • cls (type) – Class to be subclassed with the given backend.

  • backend (Backend) – Backend to be selected.

Returns

Subclass of the current class with methods filtered for the given backend.

Return type

Type[MultiBackendMixin]

classmethod get_backend() Backend[source]

Get current active backend for this class.

Returns

The current active backend.

Return type

Backend

Raises

InvalidBackend – Backend not set or not a valid execution class.

classmethod register_backend_method(alias_for: str, func: Callable[[...], Any], backend: Backend) None[source]

Proxy for register_backend_method to register an existing function as a backend-specific method.

Parameters
  • alias_for (str) – The name of the method to be substituted with a backend-specific version.

  • func (AnyCallable) – Existing function to be registered as a method.

  • backend (Backend) – Backend for the method.

supported_backends: List[Backend] = []

Backends supported by this resource.

Type

List[Backend]