Implement usage of OutputBuffer
This commit is contained in:
parent
8d5267c039
commit
22f417e68e
1 changed files with 13 additions and 8 deletions
|
@ -7,7 +7,7 @@ import traceback
|
||||||
|
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
|
|
||||||
from nntp.tiny.buffer import LineBuffer, BufferOverflow
|
from nntp.tiny.buffer import LineBuffer, OutputBuffer, BufferOverflow
|
||||||
from nntp.tiny.db import Database
|
from nntp.tiny.db import Database
|
||||||
from nntp.tiny.response import Response, ResponseCode
|
from nntp.tiny.response import Response, ResponseCode
|
||||||
from nntp.tiny.newsgroup import Newsgroup
|
from nntp.tiny.newsgroup import Newsgroup
|
||||||
|
@ -104,12 +104,13 @@ class Session():
|
||||||
RE_SPLIT = re.compile(r'\s+')
|
RE_SPLIT = re.compile(r'\s+')
|
||||||
|
|
||||||
def __init__(self, server, sock: socket.socket):
|
def __init__(self, server, sock: socket.socket):
|
||||||
self.server = server
|
self.server = server
|
||||||
self.db: Database = server.connect_to_db()
|
self.db: Database = server.connect_to_db()
|
||||||
self.sock: socket.socket = sock
|
self.sock: socket.socket = sock
|
||||||
self.buf: LineBuffer = LineBuffer()
|
self.buf: LineBuffer = LineBuffer()
|
||||||
self.state: SessionState = SessionState.ACTIVE
|
self.output: OutputBuffer = OutputBuffer(sock)
|
||||||
self.mode: SessionMode = SessionMode.READER
|
self.state: SessionState = SessionState.ACTIVE
|
||||||
|
self.mode: SessionMode = SessionMode.READER
|
||||||
|
|
||||||
self.newsgroup: Optional[Newsgroup] = None
|
self.newsgroup: Optional[Newsgroup] = None
|
||||||
self.article_id: Optional[int] = None
|
self.article_id: Optional[int] = None
|
||||||
|
@ -118,7 +119,10 @@ class Session():
|
||||||
return self.buf.readline(self.sock)
|
return self.buf.readline(self.sock)
|
||||||
|
|
||||||
def print(self, text: str, end: str="\r\n"):
|
def print(self, text: str, end: str="\r\n"):
|
||||||
return self.sock.send(bytes(text + end, 'utf-8'))
|
return self.output.print(text, end)
|
||||||
|
|
||||||
|
def flush(self):
|
||||||
|
return self.output.flush()
|
||||||
|
|
||||||
def end(self):
|
def end(self):
|
||||||
return self.print('.')
|
return self.print('.')
|
||||||
|
@ -768,5 +772,6 @@ class Session():
|
||||||
|
|
||||||
while self.state & SessionState.ACTIVE:
|
while self.state & SessionState.ACTIVE:
|
||||||
self.handle_command()
|
self.handle_command()
|
||||||
|
self.flush()
|
||||||
|
|
||||||
self.sock.close()
|
self.sock.close()
|
||||||
|
|
Loading…
Add table
Reference in a new issue