Implement Client.each_response_line()

This commit is contained in:
XANTRONIX Development 2024-12-04 22:35:49 -05:00
parent 3067b812d5
commit a145b34726

View file

@ -9,6 +9,10 @@ from nntp.tiny.response import Response, ResponseCode
class ClientException(Exception):
pass
class ClientEOFException(ClientException):
def __str__(self):
return 'Unexpected client EOF'
class Client(Connection):
RE_SPLIT = re.compile(r'\s+')
@ -42,7 +46,6 @@ class Client(Connection):
self.host = host
self.port = port
self.tls = tls
super().__init__(sock)
@ -55,3 +58,17 @@ class Client(Connection):
self.print(' '.join(args))
return self._read_response()
def each_response_line(self):
while True:
line = self.readline()
if line == '':
raise ClientEOFException()
line = line.rstrip()
if line == '.':
break
yield line