Use bool for tracking active session
This commit is contained in:
parent
4133d72eb4
commit
9b27899446
1 changed files with 4 additions and 13 deletions
|
@ -15,11 +15,6 @@ from nntp.tiny.response import Response, ResponseCode
|
||||||
from nntp.tiny.newsgroup import Newsgroup
|
from nntp.tiny.newsgroup import Newsgroup
|
||||||
from nntp.tiny.message import Message, MessageRange, MessagePart
|
from nntp.tiny.message import Message, MessageRange, MessagePart
|
||||||
|
|
||||||
class SessionState(enum.Flag):
|
|
||||||
ACTIVE = 1
|
|
||||||
AUTH_OK = enum.auto()
|
|
||||||
AUTH_POST = enum.auto()
|
|
||||||
|
|
||||||
class SessionMode(enum.Enum):
|
class SessionMode(enum.Enum):
|
||||||
READER = 1
|
READER = 1
|
||||||
|
|
||||||
|
@ -42,8 +37,8 @@ class Session():
|
||||||
self.sock: socket.socket = sock
|
self.sock: socket.socket = sock
|
||||||
self.buf: LineBuffer = LineBuffer()
|
self.buf: LineBuffer = LineBuffer()
|
||||||
self.output: OutputBuffer = OutputBuffer(sock)
|
self.output: OutputBuffer = OutputBuffer(sock)
|
||||||
self.state: SessionState = SessionState.ACTIVE
|
|
||||||
self.mode: SessionMode = SessionMode.READER
|
self.mode: SessionMode = SessionMode.READER
|
||||||
|
self.active: bool = True
|
||||||
|
|
||||||
self.newsgroup: Optional[Newsgroup] = None
|
self.newsgroup: Optional[Newsgroup] = None
|
||||||
self.article_id: Optional[int] = None
|
self.article_id: Optional[int] = None
|
||||||
|
@ -68,10 +63,6 @@ class Session():
|
||||||
def _cmd_capabilities(self, *args):
|
def _cmd_capabilities(self, *args):
|
||||||
self.respond(ResponseCode.NNTP_CAPABILITIES_FOLLOW)
|
self.respond(ResponseCode.NNTP_CAPABILITIES_FOLLOW)
|
||||||
|
|
||||||
if self.state & SessionState.AUTH_POST:
|
|
||||||
self.print('POST')
|
|
||||||
|
|
||||||
if self.state & SessionState.AUTH_OK:
|
|
||||||
self.print('AUTHUSER INFO')
|
self.print('AUTHUSER INFO')
|
||||||
|
|
||||||
for item in self.NNTP_CAPABILITIES:
|
for item in self.NNTP_CAPABILITIES:
|
||||||
|
@ -657,7 +648,7 @@ class Session():
|
||||||
timestamp.strftime("%Y%m%d%H%M%S"))
|
timestamp.strftime("%Y%m%d%H%M%S"))
|
||||||
|
|
||||||
def _cmd_quit(self):
|
def _cmd_quit(self):
|
||||||
self.state &= ~SessionState.ACTIVE
|
self.active = False
|
||||||
|
|
||||||
return self.respond(ResponseCode.NNTP_CONNECTION_CLOSING)
|
return self.respond(ResponseCode.NNTP_CONNECTION_CLOSING)
|
||||||
|
|
||||||
|
@ -691,7 +682,7 @@ class Session():
|
||||||
line = self.readline()
|
line = self.readline()
|
||||||
|
|
||||||
if line == '':
|
if line == '':
|
||||||
self.state &= ~SessionState.ACTIVE
|
self.active = False
|
||||||
return
|
return
|
||||||
|
|
||||||
tokens = self.RE_SPLIT.split(line.rstrip())
|
tokens = self.RE_SPLIT.split(line.rstrip())
|
||||||
|
@ -715,7 +706,7 @@ class Session():
|
||||||
self.greet()
|
self.greet()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
while self.state & SessionState.ACTIVE:
|
while self.active:
|
||||||
self.handle_command()
|
self.handle_command()
|
||||||
self.flush()
|
self.flush()
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue