xenu_nntp/lib/nntp/tiny/server.py
2024-11-26 16:24:32 -05:00

24 lines
596 B
Python

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