Move RemoteNewsgroup to lib/nntp/tiny/remote.py
This commit is contained in:
parent
a145b34726
commit
1698eaafce
2 changed files with 36 additions and 1 deletions
|
@ -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')
|
||||
|
|
16
lib/nntp/tiny/remote.py
Normal file
16
lib/nntp/tiny/remote.py
Normal 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'
|
||||
)
|
Loading…
Add table
Reference in a new issue