import enum from typing import Callable from nntp.tiny.newsgroup import Newsgroup class ServerCapability(enum.Flag): NONE = 0 AUTH = enum.auto() POST = enum.auto() class Server(): def __init__(self, connect_to_db: Callable): self.connect_to_db = connect_to_db self.capabilities = ServerCapability.NONE self.newsgroups = dict() self._init_newsgroups() def _init_newsgroups(self): db = self.connect_to_db() for newsgroup in db.query(Newsgroup).each(): self.newsgroups[newsgroup.name.casefold()] = newsgroup