Skip to content

Adapter

blackline.factories.adapter

ADAPTER_SUBMODULE = 'adapters' module-attribute

AdapterFactory

Source code in BAR /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/blackline/factories/adapter.py
class AdapterFactory:
    def __init__(self) -> None:
        self.adapters: Dict[str, AdapterBase] = {}

    def adapter(self, name: str) -> AdapterBase:
        return self.adapters.setdefault(name, self.load_adapter(name))

    @staticmethod
    def load_adapter(name: str) -> AdapterBase:
        mod = AdapterFactory._import_module(submodule=ADAPTER_SUBMODULE, name=name)
        return AdapterFactory._filter_class_from_module(mod)

    @staticmethod
    def _import_module(
        submodule: str, name: str, suffix: Optional[str] = None
    ) -> ModuleType:
        _name = f"blackline.{submodule}.{name}.{name}"
        if suffix is not None:
            _name += f"_{suffix}"
        try:
            return import_module(_name)
        except ModuleNotFoundError as e:
            if e.name and "blackline" in e.name:
                raise ModuleNotFoundError(
                    f"Could not import plugin: {_name}. Have you install the blackline-{name} package?"  # noqa: E501
                )
            raise e

    @staticmethod
    def _filter_class_from_module(mod):
        return inspect.getmembers(
            mod,
            lambda member: inspect.isclass(member)
            and member.__module__ == mod.__name__,
        )[0][1]

adapters: Dict[str, AdapterBase] = {} instance-attribute

__init__()

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/blackline/factories/adapter.py
def __init__(self) -> None:
    self.adapters: Dict[str, AdapterBase] = {}

adapter(name)

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/blackline/factories/adapter.py
def adapter(self, name: str) -> AdapterBase:
    return self.adapters.setdefault(name, self.load_adapter(name))

load_adapter(name) staticmethod

Source code in /opt/hostedtoolcache/Python/3.10.12/x64/lib/python3.10/site-packages/blackline/factories/adapter.py
@staticmethod
def load_adapter(name: str) -> AdapterBase:
    mod = AdapterFactory._import_module(submodule=ADAPTER_SUBMODULE, name=name)
    return AdapterFactory._filter_class_from_module(mod)