Move RemoteNewsgroup to lib/nntp/tiny/remote.py

This commit is contained in:
XANTRONIX Development 2024-12-04 23:07:30 -05:00
parent a145b34726
commit 1698eaafce
2 changed files with 36 additions and 1 deletions

View file

@ -1,10 +1,12 @@
import re import re
import socket import socket
import ssl import ssl
import datetime
from nntp.tiny.socket import Connection from nntp.tiny.socket import Connection
from nntp.tiny.host import Host from nntp.tiny.host import Host
from nntp.tiny.response import Response, ResponseCode from nntp.tiny.response import Response, ResponseCode
from nntp.tiny.remote import RemoteNewsgroup
class ClientException(Exception): class ClientException(Exception):
pass pass
@ -20,7 +22,7 @@ class Client(Connection):
line = self.readline() line = self.readline()
if line == '': if line == '':
return raise ClientEOFException()
parts = self.RE_SPLIT.split(line.rstrip(), 1) parts = self.RE_SPLIT.split(line.rstrip(), 1)
@ -72,3 +74,20 @@ class Client(Connection):
break break
yield line 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')

16
lib/nntp/tiny/remote.py Normal file
View file

@ -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'
)