from abc import ABC, abstractmethod __all__ = ["DBConnector"] class DBConnector(ABC): def __init__(self): self._conn = None def __enter__(self): self.init() return self def __exit__(self, exc_type, exc_val, exc_tb): self.close() def init(self): self._conn = self._get_connection() @abstractmethod def close(self): pass @abstractmethod def _get_connection(self): pass @abstractmethod def check_db_connection(self) -> bool: pass