xenu_nntp/lib/nntp/tiny/server.py

25 lines
596 B
Python
Raw Normal View History

2024-11-20 21:17:03 -05:00
import enum
2024-11-26 16:24:32 -05:00
from typing import Callable
2024-11-22 23:57:14 -05:00
from nntp.tiny.newsgroup import Newsgroup
2024-11-20 21:17:03 -05:00
class ServerCapability(enum.Flag):
NONE = 0
AUTH = enum.auto()
POST = enum.auto()
class Server():
2024-11-26 16:24:32 -05:00
def __init__(self, connect_to_db: Callable):
self.connect_to_db = connect_to_db
self.capabilities = ServerCapability.NONE
self.newsgroups = dict()
2024-11-22 23:57:14 -05:00
2024-11-25 00:16:15 -05:00
self._init_newsgroups()
2024-11-22 23:57:14 -05:00
def _init_newsgroups(self):
2024-11-26 16:24:32 -05:00
db = self.connect_to_db()
for newsgroup in db.query(Newsgroup).each():
2024-11-22 23:57:14 -05:00
self.newsgroups[newsgroup.name.casefold()] = newsgroup