From 1698eaafceee0800eb675f1d9a1ea5f5610c61fe Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Wed, 4 Dec 2024 23:07:30 -0500 Subject: [PATCH] Move RemoteNewsgroup to lib/nntp/tiny/remote.py --- lib/nntp/tiny/client.py | 21 ++++++++++++++++++++- lib/nntp/tiny/remote.py | 16 ++++++++++++++++ 2 files changed, 36 insertions(+), 1 deletion(-) create mode 100644 lib/nntp/tiny/remote.py diff --git a/lib/nntp/tiny/client.py b/lib/nntp/tiny/client.py index 3ef53e8..6ab015b 100644 --- a/lib/nntp/tiny/client.py +++ b/lib/nntp/tiny/client.py @@ -1,10 +1,12 @@ import re import socket import ssl +import datetime from nntp.tiny.socket import Connection from nntp.tiny.host import Host from nntp.tiny.response import Response, ResponseCode +from nntp.tiny.remote import RemoteNewsgroup class ClientException(Exception): pass @@ -20,7 +22,7 @@ class Client(Connection): line = self.readline() if line == '': - return + raise ClientEOFException() parts = self.RE_SPLIT.split(line.rstrip(), 1) @@ -72,3 +74,20 @@ class Client(Connection): break yield line + + def each_newsgroup(self, wildmat: str, timestamp: datetime.datetime): + date = timestamp.strftime('%Y%m%d') + time = timestamp.strftime('%H%M%S') + + response = self.request('NEWGROUPS', wildmat, date, time) + + for line in self.each_response_line(): + parts = self.RE_SPLIT.split(line) + + if len(parts) != 4: + raise ClientException('Unexpected result from NEWGROUPS') + + yield RemoteNewsgroup(parts[0], + int(parts[1]), + int(parts[2]), + parts[3] == 'y') diff --git a/lib/nntp/tiny/remote.py b/lib/nntp/tiny/remote.py new file mode 100644 index 0000000..6d16cde --- /dev/null +++ b/lib/nntp/tiny/remote.py @@ -0,0 +1,16 @@ +class RemoteNewsgroup(): + __slots__ = 'name', 'low', 'high', 'post', + + def __init__(self, name: str, low: int, high: int, post: bool): + self.name = name + self.low = low + self.high = high + self.post = post + + def __str__(self): + return "%s %d %d %s" % ( + self.name, + self.low, + self.high, + 'y' if self.post else 'n' + )