[Patches] Subject: nntplib.py patch for 'mode reader' command

Thomas Wouters thomas@xs4all.net
Mon, 7 Feb 2000 18:31:18 +0100


--pAwQNkOnpTn9IO2O
Content-Type: text/plain; charset=us-ascii



Attached you'll find a patch to nntplib.py, the NNTP class, to allow for a
'readermode' argument during construction. Some newsservers require a
command, 'mode reader', to be sent before certain commands can be executed
(inn uses it to spawn nnrpd and pass the connection to it. i am not sure if
other, non-inn-based readers use it too.)

The patch is based on a posting by Jim Tittsler <jwt@dskk.co.jp>, to the
mailman-users list, in October last year:
http://www.python.org/pipermail/mailman-users/1999-October/002371.html

As he points out, this can be solved by wrapping the first group command
around a try/except, and send the 'mode reader' command if it fails with an
error 500, as long as authentication is not used. Mailman does not use
authentication, and I've already posted a patch to the mailman-developpers
list to fix it like that, but I think the obvious fix is the one attached.

The patch also expands NNTP.__init__'s docstring some.

I confirm that, to the best of my knowledge and belief, this contribution is
free of any claims of third parties under copyright, patent or other rights
or interests ("claims").  To the extent that I have any such claims, I
hereby grant to CNRI a nonexclusive, irrevocable, royalty-free, worldwide
license to reproduce, distribute, perform and/or display publicly, prepare
derivative versions, and otherwise use this contribution as part of the
Python software and its related documentation, or any derivative versions
thereof, at no cost to CNRI or its licensed users, and to authorize others
to do so.

I acknowledge that CNRI may, at its sole discretion, decide whether or not
to incorporate this contribution in the Python software and its related
documentation.  I further grant CNRI permission to use my name and other
identifying information provided to CNRI by me for use in connection with
the Python software and its related documentation.

(The patch is unified diff. I prefer unified, sue me and i'll send a context
one ;)

-- 
Thomas Wouters <thomas@xs4all.net>

Hi! I'm a .signature virus! copy me into your .signature file to help me spread!

--pAwQNkOnpTn9IO2O
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="nntplib.diff"

Index: dist/src/Lib/nntplib.py
===================================================================
RCS file: /projects/cvsroot/python/dist/src/Lib/nntplib.py,v
retrieving revision 1.17
diff -u -r1.17 nntplib.py
--- nntplib.py	2000/02/04 15:10:33	1.17
+++ nntplib.py	2000/02/07 16:02:44
@@ -58,10 +58,13 @@
 
 class NNTP:
 
-	def __init__(self, host, port = NNTP_PORT, user=None, password=None):
+	def __init__(self, host, port = NNTP_PORT, user=None, password=None, readermode=0):
 		"""Initialize an instance.  Arguments:
 		- host: hostname to connect to
-		- port: port to connect to (default the standard NNTP port)"""
+		- port: port to connect to (default the standard NNTP port)
+		- user: username to authenticate with
+		- password: password to use with username
+		- readermode: send 'mode reader' command after connecting"""
 
 		self.host = host
 		self.port = port
@@ -70,6 +73,11 @@
 		self.file = self.sock.makefile('rb')
 		self.debugging = 0
 		self.welcome = self.getresp()
+		if readermode:
+			try:
+				self.welcome = self.shortcmd('mode reader')
+			except error_perm: # error 500, probably 'not implemented'
+				pass
 		if user:
 			resp = self.shortcmd('authinfo user '+user)
 			if resp[:3] == '381':

--pAwQNkOnpTn9IO2O--