From 9763ea0cdff96464fc73ca1cabfca89082fad305 Mon Sep 17 00:00:00 2001 From: XANTRONIX Development Date: Mon, 25 Nov 2024 00:49:53 -0500 Subject: [PATCH] Implement first working commands --- lib/nntp/tiny/session.py | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/lib/nntp/tiny/session.py b/lib/nntp/tiny/session.py index 159aed3..65e8929 100644 --- a/lib/nntp/tiny/session.py +++ b/lib/nntp/tiny/session.py @@ -291,10 +291,40 @@ class Session(): return self.end() + def _cmd_newgroups(self, wildmat, datestr, timestr, *args): + gmt = False + + if len(args) == 1: + if args[0] == "GMT": + gmt = True + else: + return self.send_response(ResponseCode.NNTP_SYNTAX_ERROR, "Only optional 'GMT' allowed") + elif len(args) > 1: + return self.send_response(ResponseCode.NNTP_SYNTAX_ERROR, "Too many arguments") + + pass + + COMMANDS = { + 'CAPABILITIES': _cmd_capabilities, + 'GROUP': _cmd_group, + 'LISTGROUP': _cmd_listgroup, + 'LIST': _cmd_list, + 'NEWNEWS': _cmd_newnews, + 'NEWSGROUPS': _cmd_newgroups, + } + def handle(self): line = self.readline() if line == '': return - command, args = self.RE_SPLIT.split(line.rstrip()) + tokens = self.RE_SPLIT.split(line.rstrip()) + command, *args = tokens + + fn = self.COMMANDS.get(command.upper()) + + if fn is None: + return self.respond(ResponseCode.NNTP_COMMAND_UNKNOWN) + + return fn(self, *args)