# Path: pypeman/conf.py
# NOT_FOUND = object()  # sentinel object
# class ConfigError(ImportError):
# class Settings():
#     def __init__(self, module_name=None):
#     def init_settings(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):


import asyncio
import importlib
from concurrent.futures import ThreadPoolExecutor
from collections import defaultdict
from sqlitedict import SqliteDict
from pypeman.conf import settings
"""
This module contains all persistence related things.
"""




SENTINEL = object()

_backend = None


async def get_backend(loop):
    """
    Return the configured backend instance.

    :param loop: Asyncio loop to use. Passed backend instance.
    """
    global _backend
    if not _backend:
        # Load backend on first use
        if not settings.PERSISTENCE_BACKEND:
            raise Exception("Persistence backend not configured.")

        module, _, class_ = settings.PERSISTENCE_BACKEND.rpartition('.')
        loaded_module = importlib.import_module(module)

# Path: pypeman/conf.py
# NOT_FOUND = object()  # sentinel object
# class ConfigError(ImportError):
# class Settings():
#     def __init__(self, module_name=None):
#     def init_settings(self):
#     def __getattr__(self, name):
#     def __setattr__(self, name, value):


# Path: pypeman/persistence.py
import asyncio
import importlib
from concurrent.futures import ThreadPoolExecutor
from collections import defaultdict
from sqlitedict import SqliteDict
from pypeman.conf import settings

"""
This module contains all persistence related things.
"""




SENTINEL = object()

_backend = None


async def get_backend(loop):
    """
    Return the configured backend instance.

    :param loop: Asyncio loop to use. Passed backend instance.
    """
    global _backend
    if not _backend:
        # Load backend on first use
        if not settings.PERSISTENCE_BACKEND:
            raise Exception("Persistence backend not configured.")

        module, _, class_ = settings.PERSISTENCE_BACKEND.rpartition('.')
        loaded_module = importlib.import_module(module)

        _backend = getattr(loaded_module, class_)(loop=loop, **settings.PERSISTENCE_CONFIG)