Bug#57223: mailman: gate_news problems (fwd)
Hello,
Any ideas what might cause this ?
---------- Forwarded message ---------- Date: Mon, 07 Feb 2000 03:01:23 +0000 (UTC) From: Lazarus Long <lazarus@overdue.dhis.net> To: submit@bugs.debian.org Subject: Bug#57223: mailman: gate_news problems Resent-Date: Mon, 07 Feb 2000 03:03:28 +0000 (GMT) Resent-From: Lazarus Long <lazarus@overdue.dhis.net> Resent-To: debian-bugs-dist@lists.debian.org Resent-cc: Gergely Madarasz <gorgo@sztaki.hu>
Package: mailman Version: 1.1-2 Severity: important
Subject: Cron <list@phoenix> [ -x /usr/bin/python -a -f /usr/lib/mailman/cron/gate_news ] && /usr/bin/python +/usr/lib/mailman/cron/gate_news X-Cron-Env: <SHELL=/bin/sh> X-Cron-Env: <HOME=/var/list> X-Cron-Env: <PATH=/usr/bin:/bin> X-Cron-Env: <LOGNAME=list> Date: Mon, 7 Feb 2000 02:55:06 +0000 (UTC)
Traceback (innermost last): File "/usr/lib/mailman/cron/gate_news", line 119, in ? main() File "/usr/lib/mailman/cron/gate_news", line 79, in main r,c,first,last,n = conn.group(mlist.linked_newsgroup) File "/usr/lib/python1.5/nntplib.py", line 208, in group resp = self.shortcmd('GROUP ' + name) File "/usr/lib/python1.5/nntplib.py", line 158, in shortcmd return self.getresp() File "/usr/lib/python1.5/nntplib.py", line 134, in getresp raise error_perm, resp nntplib.error_perm: 500 "GROUP" not implemented; try "help".
-- System Information Debian Release: 2.2 Kernel Version: Linux phoenix 2.2.14 #1 Thu Jan 6 01:44:28 UTC 2000 i586 unknown
Versions of the packages mailman depends on: ii apache 1.3.9-10 Versatile, high-performance HTTP server ii cron 3.0pl1-55 management of regular background processing ii libc6 2.1.2-13 GNU C Library: Shared libraries and Timezone data ii logrotate 3.2-11 Log rotation utility ii python-base 1.5.2-6 An interactive object-oriented scripting language. sendmail Not installed or no info ii postfix-tls 0.0.19991231pl02+0.51-1 A mail transport agent with RFC2487 encryption ^^^ (Provides virtual package mail-transport-agent) ii apache-ssl 1.3.9.10+1.37-1 Versatile, high-performance HTTP server with SSL support ^^^ (Provides virtual package httpd)
On Mon, Feb 07, 2000 at 01:13:56PM +0100, Gergely Madarasz wrote:
Any ideas what might cause this ?
nntplib.error_perm: 500 "GROUP" not implemented; try "help".
You're connecting to a newsserver that does not have or perhaps does not allow the 'GROUP' command. I personally wasn't aware that there were such newsservers... But perhaps you are connected to a newsfeeder box, instead of a newsreader box ? Some ISPs split their newsservers in feeders, who only have enough of a newsserver to share news with other newsservers, serve as a gateway of sorts, and actual readers, which get their feed off the feeders, and who _do_ allow clients to connect, and offer most, if not all, NNTP commands.
If you're fairly sure you are connected to the right newsserver, try connecting to that newsserver, from the machine running mailman, on the news port (119) and try the GROUP command yourself. Also see if you can check the newsservers' logfile, to see if it mentions anything else. If all else fails, you need to find a different newsserver, or shut off the news gateway.
---------- Forwarded message ---------- Package: mailman Version: 1.1-2 Severity: important
Traceback (innermost last): File "/usr/lib/mailman/cron/gate_news", line 119, in ? main() File "/usr/lib/mailman/cron/gate_news", line 79, in main r,c,first,last,n = conn.group(mlist.linked_newsgroup) File "/usr/lib/python1.5/nntplib.py", line 208, in group resp = self.shortcmd('GROUP ' + name) File "/usr/lib/python1.5/nntplib.py", line 158, in shortcmd return self.getresp() File "/usr/lib/python1.5/nntplib.py", line 134, in getresp raise error_perm, resp
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
On Mon, 7 Feb 2000, Thomas Wouters wrote:
On Mon, Feb 07, 2000 at 01:13:56PM +0100, Gergely Madarasz wrote:
Any ideas what might cause this ?
nntplib.error_perm: 500 "GROUP" not implemented; try "help".
You're connecting to a newsserver that does not have or perhaps does not allow the 'GROUP' command. I personally wasn't aware that there were such newsservers... But perhaps you are connected to a newsfeeder box, instead of a newsreader box ? Some ISPs split their newsservers in feeders, who only have enough of a newsserver to share news with other newsservers, serve as a gateway of sorts, and actual readers, which get their feed off the feeders, and who _do_ allow clients to connect, and offer most, if not all, NNTP commands.
If you're fairly sure you are connected to the right newsserver, try connecting to that newsserver, from the machine running mailman, on the news port (119) and try the GROUP command yourself. Also see if you can check the newsservers' logfile, to see if it mentions anything else. If all else fails, you need to find a different newsserver, or shut off the news gateway.
Hmm... I found what might cause this... this if from the mailman list archives: http://www.python.org/pipermail/mailman-users/1999-October/002371.html
so does this mean that there was no workaround made for this in mailman 1.1 ? Is there a patch somewhere perhaps ?
-- Madarasz Gergely gorgo@sztaki.hu gorgo@linux.rulez.org It's practically impossible to look at a penguin and feel angry. Egy pingvinre gyakorlatilag lehetetlen haragosan nezni. HuLUG: http://mlf.linux.rulez.org/
On Mon, Feb 07, 2000 at 03:41:55PM +0100, Gergely Madarasz wrote:
nntplib.error_perm: 500 "GROUP" not implemented; try "help".
You're connecting to a newsserver that does not have or perhaps does not allow the 'GROUP' command. I personally wasn't aware that there were such
Hmm... I found what might cause this... this if from the mailman list archives: http://www.python.org/pipermail/mailman-users/1999-October/002371.html
so does this mean that there was no workaround made for this in mailman 1.1 ? Is there a patch somewhere perhaps ?
The problem is that the problem code isn't Mailman code ;) nntplib.py is in the standard python library, it's just included in the 'pythonlib' directory for older python distributions, that dont have nntplib.py. Apparently the patch (which isn't real clean, by the way, because a general except: clause can be very nasty) hasn't been sent to the python-list, or hasn't been accepted. But the problem does look like it needs fixing, i'll see if i can send a patch to the python-patches list. In the mean time you can apply the patch mentioned in that posting, to your own copy of nntplib, as long as you dont use nntplib in server mode anywhere (Not very likely, that last part)
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
On Mon, 7 Feb 2000, Thomas Wouters wrote:
send a patch to the python-patches list. In the mean time you can apply the patch mentioned in that posting, to your own copy of nntplib, as long as you dont use nntplib in server mode anywhere (Not very likely, that last part)
That is for the reporter of the problem... But I need to make a fix in the mailman .deb package for debian potato before potato is released... :)
-- Madarasz Gergely gorgo@sztaki.hu gorgo@linux.rulez.org It's practically impossible to look at a penguin and feel angry. Egy pingvinre gyakorlatilag lehetetlen haragosan nezni. HuLUG: http://mlf.linux.rulez.org/
On Mon, Feb 07, 2000 at 04:57:37PM +0100, Gergely Madarasz wrote:
On Mon, 7 Feb 2000, Thomas Wouters wrote:
send a patch to the python-patches list. In the mean time you can apply the patch mentioned in that posting, to your own copy of nntplib, as long as you dont use nntplib in server mode anywhere (Not very likely, that last part)
That is for the reporter of the problem... But I need to make a fix in the mailman .deb package for debian potato before potato is released... :)
Ok, well, because the reader attempting the 'group' command, in cron/gate_news, isn't using authorization, we can just send the 'mode reader' command when we get the error 500. The attached patch should work, I think. It fixes the first call to 'group' instead of the constructor of nntplib.NNTP, so it should be usable with all nntplib version.
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
On Mon, 7 Feb 2000, Thomas Wouters wrote:
On Mon, Feb 07, 2000 at 04:57:37PM +0100, Gergely Madarasz wrote:
On Mon, 7 Feb 2000, Thomas Wouters wrote:
send a patch to the python-patches list. In the mean time you can apply the patch mentioned in that posting, to your own copy of nntplib, as long as you dont use nntplib in server mode anywhere (Not very likely, that last part)
That is for the reporter of the problem... But I need to make a fix in the mailman .deb package for debian potato before potato is released... :)
Ok, well, because the reader attempting the 'group' command, in cron/gate_news, isn't using authorization, we can just send the 'mode reader' command when we get the error 500. The attached patch should work, I think. It fixes the first call to 'group' instead of the constructor of nntplib.NNTP, so it should be usable with all nntplib version.
Thanks. Lazarus, please test this patch, and notify me if it worked for you :)
-- Madarasz Gergely gorgo@sztaki.hu gorgo@linux.rulez.org It's practically impossible to look at a penguin and feel angry. Egy pingvinre gyakorlatilag lehetetlen haragosan nezni. HuLUG: http://mlf.linux.rulez.org/
On Mon, Feb 07, 2000 at 06:16:06PM +0100, Gergely Madarasz wrote:
Thanks. Lazarus, please test this patch, and notify me if it worked for you :)
phoenix:/usr/lib/mailman/cron# patch --verbose --dry-run < mailman.cvs.diff Hmm... Looks like a unified diff to me... The text leading up to this was:
|Index: cron/gate_news |=================================================================== |RCS file: /projects/cvsroot/mailman/cron/gate_news,v |retrieving revision 1.22 |diff -u -r1.22 gate_news |--- gate_news 1999/12/25 14:35:31 1.22 |+++ gate_news 2000/02/07 16:12:40
Patching file `gate_news' using Plan A... Hunk #1 FAILED at 125. 1 out of 1 hunk FAILED -- saving rejects to gate_news.rej done phoenix:/usr/lib/mailman/cron#
No. :( What next? I know no python, fwiw.
--
On Mon, Feb 07, 2000 at 08:09:18PM +0000, Lazarus Long wrote:
On Mon, Feb 07, 2000 at 06:16:06PM +0100, Gergely Madarasz wrote:
Thanks. Lazarus, please test this patch, and notify me if it worked for you :)
Patching file `gate_news' using Plan A... Hunk #1 FAILED at 125. 1 out of 1 hunk FAILED -- saving rejects to gate_news.rej
Ok, the patch doesn't work for mailman-1.1 gate_news ;P I've attached a version that should. Let me know if it still fails, or if you're using a different version of mailman.
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
"TW" == Thomas Wouters <thomas@xs4all.net> writes:
TW> Ok, well, because the reader attempting the 'group' command,
TW> in cron/gate_news, isn't using authorization, we can just send
TW> the 'mode reader' command when we get the error 500. The
TW> attached patch should work, I think. It fixes the first call
TW> to 'group' instead of the constructor of nntplib.NNTP, so it
TW> should be usable with all nntplib version.
Thanks. I'll apply this patch (with a slightly rewritten comment) to the CVS snapshot.
-Barry
On Mon, Feb 07, 2000 at 05:19:59PM +0100, Thomas Wouters wrote:
On Mon, Feb 07, 2000 at 04:57:37PM +0100, Gergely Madarasz wrote:
On Mon, 7 Feb 2000, Thomas Wouters wrote:
send a patch to the python-patches list. In the mean time you can apply the patch mentioned in that posting, to your own copy of nntplib, as long as you dont use nntplib in server mode anywhere (Not very likely, that last part)
That is for the reporter of the problem... But I need to make a fix in the mailman .deb package for debian potato before potato is released... :)
Ok, well, because the reader attempting the 'group' command, in cron/gate_news, isn't using authorization, we can just send the 'mode reader' command when we get the error 500. The attached patch should work, I think. It fixes the first call to 'group' instead of the constructor of nntplib.NNTP, so it should be usable with all nntplib version.
That patch would not apply here, as I believe I just posted to your list as well with my previous mail.
I'm not sure if gate_news in the Debian packages differs from the CVS version or not however. Gergely?
--
On Mon, Feb 07, 2000 at 04:57:37PM +0100, Gergely Madarasz wrote:
send a patch to the python-patches list. In the mean time you can apply the patch mentioned in that posting, to your own copy of nntplib, as long as you dont use nntplib in server mode anywhere (Not very likely, that last part)
That is for the reporter of the problem... But I need to make a fix in the mailman .deb package for debian potato before potato is released... :)
Following up to what I've received here so far on this thread (some of which I appear to have missed, judging by quoted portions) I am running current standard versions of most of the involved packages here on a Debian system, including INN2 as the NNTP daemon, so I imagine standard commands are supported.
In case specifics are useful to anyone, here is a list which I hope covers all potentially-involved packages based upon Debian package dependency information. I'll include those I suspect are irrelevant, in case I am wrong, in the interest of completeness.
||/ Name Version Description +++-===========================-===========================-====================================================================== ii task-news-server 2.2.2.2000.01.31-1 USENET News Server ii inn2 2.2.2.2000.01.31-1 News transport system `InterNetNews' by the ISC and Rich Salz ii libc6 2.1.2-13 GNU C Library: Shared libraries and Timezone data ii libgdbmg1 1.7.3-26.2 GNU dbm database routines (runtime version). [libc6 version] ii cron 3.0pl1-55 management of regular background processing ii postfix-tls 0.0.19991231pl02+0.51-1 A mail transport agent with RFC2487 encryption ii time 1.7-8 The GNU time command. ii inn2-inews 2.2.2.2000.01.31-1 NNTP client news injector, from InterNetNews (INN) ii grep 2.4-2 GNU grep, egrep and fgrep. ii perl-5.005 5.005.03-5.3 Larry Wall's Practical Extracting and Report Language. ii python-base 1.5.2-6 An interactive object-oriented scripting language. ii libncurses4 4.2-8 Shared libraries for terminal handling ii libreadlineg2 2.1-17 GNU readline and history libraries, run-time libraries. [libc6] ii mailman 1.1-2 Powerful, web based list processor ii logrotate 3.2-11 Log rotation utility ii apache 1.3.9-10 Versatile, high-performance HTTP server ii apache-ssl 1.3.9.10+1.37-1 Versatile, high-performance HTTP server with SSL support
The original Debian bug report contained a similar list, but I would imagine it was not included on this list, since there was question of which NNTP commands were supported by the daemon in question.
BTW, mangling python-base to prevent server mode connections will not be an option for me, nor would I imagine it to be acceptable for Debian-as-a-whole, although I don't speak for the Debian project in any way.
Thanks in advance for your collective efforts, on behalf of all of the systems likely to be encountering this problem in the future (which should include most that install mailman on a Debian box.)
--
"GM" == Gergely Madarasz <gorgo@sztaki.hu> writes:
GM> Hmm... I found what might cause this... this if from the
GM> mailman list archives:
GM> http://www.python.org/pipermail/mailman-users/1999-October/002371.html
GM> so does this mean that there was no workaround made for this
GM> in mailman 1.1 ? Is there a patch somewhere perhaps ?
Since this is a bug that appears to be best fixed in Python's nntplib.py, I will float the message to patches@python.org. If nobody objects I'll make the change for Python 1.6 and then back-copy the file into Mailman 1.2.
The quick fix is to do the following:
copy Python 1.5.2's nntplib.py into Mailman/pythonlib
apply the patch
Change all occurrances of "import nntplib" to "from Mailman.pythonlib import nntplib"
-Barry
I'm cutting and pasting a message that originated on the mailman-users mailing list. I think this message is fairly self-explanatory. Can other NNTP experts look this over and see if it makes sense? I'll apply it if there are no objections. Note: the bare except is bothersome. For reference, the thread is here: http://www.python.org/pipermail/mailman-users/1999-October/002371.html -Barry -------------------- snip snip -------------------- On Sun, Oct 10, 1999 at 06:23:41PM -0700, Michael Ghens wrote:
Tried a news gateway test. This is the error: [...] nntplib.error_perm: 500 "GROUP" not implemented; try "help".
Were you running the mailman gateway on the same machine as the news server? (Or on another machine that is an NNTP peer of the news server?) Python's standard nntplib assumes that when it connects it will default to (NNRP) reader mode. If the connection ends up in NNTP/news feed mode, many commands, including "GROUP" will not be recognized. A quick hack is to add this to your nntplib.py: diff -u nntplib.py.dist nntplib.py --- nntplib.py.dist Tue Apr 28 17:43:35 1998 +++ nntplib.py Tue Jun 23 22:06:00 1998 @@ -71,6 +71,10 @@ self.file = self.sock.makefile('rb') self.debugging = 0 self.welcome = self.getresp() + try: + self.welcome = self.shortcmd('mode reader') + except: + pass if user: resp = self.shortcmd('authinfo user '+user) if resp[:3] == '381': This makes nntplib use 'mode reader' for all connections. As Harald Meland pointed out, this should probably be controlled by adding another optional argument to nntplib.NNTP(), but if you only use the library with mailman or in other "client" applications this will suffice. Jim P.S. You could also do the 'mode reader' stanza in GatewayManager, but then you also need to repeat the 'authinfo' code there if your news server needs authentication, since that must follow the 'mode reader' command. -- Jim Tittsler, Tokyo
On Mon, Feb 07, 2000 at 12:53:17PM -0500, Barry A. Warsaw wrote:
I'm cutting and pasting a message that originated on the mailman-users mailing list. I think this message is fairly self-explanatory. Can other NNTP experts look this over and see if it makes sense? I'll apply it if there are no objections. Note: the bare except is bothersome.
I've discussed this with two of my colleagues, who do and have done a fair lot with INN, and the general concensus is that it should work just fine. Servers who dont need 'mode reader' but recognize it should ignore it, Servers who dont understand it should give a 500 error, 'error_perm', with 'unimplemented' or 'what ?' or some such as message text.
Note, though, that i've already posted a small patch to mailman to fix this. Since the 'group' command is executed by gate_news, which doesn't need authentication, it's easy enough to try the group, and set the connection to readermode if it fails.
Also note that I've already sent a patch to patches@python.org ;) with a pointer to the mailman-users discussion in question.
http://www.python.org/pipermail/patches/2000-February/000015.html
My patch uses an extra argument to NNTP.__init__, and avoids the bare except. To get the same behaviour as the patch below, sending 'mode reader' by default, the default value of readermode can be set to 1. I'm not sure if that's a wise thing, however, as some users of nntplib.NNTP might depend on the connection being able to do things that you cant do in readermode.
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
On Mon, Feb 07, 2000 at 07:17:13PM +0100, Thomas Wouters wrote:
On Mon, Feb 07, 2000 at 12:53:17PM -0500, Barry A. Warsaw wrote:
I'm cutting and pasting a message that originated on the mailman-users mailing list. I think this message is fairly self-explanatory. Can other NNTP experts look this over and see if it makes sense? I'll apply it if there are no objections. Note: the bare except is bothersome.
I confess I wasn't sure if a news server that didn't recognize the 'mode reader' could be counted on to return a 500 series error. It seemed logical, but I couldn't be sure. (All of the servers I have access to accept the 'mode reader'.)
Note, though, that i've already posted a small patch to mailman to fix this. Since the 'group' command is executed by gate_news, which doesn't need authentication, it's easy enough to try the group, and set the connection to readermode if it fails.
I dislike your proposed solution for two reasons:
- It uses the nntplib's shortcmd outside of nntplib, even though it is documented as "internal".
- It doesn't work when you *do* need authentication. The group command will claim 'No such group' for groups that are hidden by authentication. (One of my mailman run on such a machine.) You need to do the 'mode reader' before authenticating. I still think it better to change nntplib.
Also note that I've already sent a patch to patches@python.org ;) with a pointer to the mailman-users discussion in question.
http://www.python.org/pipermail/patches/2000-February/000015.html
My patch uses an extra argument to NNTP.__init__, and avoids the bare except. To get the same behaviour as the patch below, sending 'mode reader' by default, the default value of readermode can be set to 1. I'm not sure if that's a wise thing, however, as some users of nntplib.NNTP might depend on the connection being able to do things that you cant do in readermode.
I sent a similar nntplib patch to mailman-users last week, although I defaulted to the current behavior and required the additional argument (or a user specified for authentication) to get the "newsreader" behavior. http://www.python.org/pipermail/mailman-users/2000-February/003935.html
Jim
On Tue, Feb 08, 2000 at 11:47:06AM +0900, Jim Tittsler wrote:
On Mon, Feb 07, 2000 at 07:17:13PM +0100, Thomas Wouters wrote:
Note, though, that i've already posted a small patch to mailman to fix this. Since the 'group' command is executed by gate_news, which doesn't need authentication, it's easy enough to try the group, and set the connection to readermode if it fails.
I dislike your proposed solution for two reasons:
- It uses the nntplib's shortcmd outside of nntplib, even though it is documented as "internal".
- It doesn't work when you *do* need authentication. The group command will claim 'No such group' for groups that are hidden by authentication. (One of my mailman run on such a machine.) You need to do the 'mode reader' before authenticating. I still think it better to change nntplib.
So do I. However, Mailman does currently *not* use authentication there, so this is the simplest fix, including backwards to mailman 1.1. or earlier. I was not aware that shortcmd() is nntplib-private, though. I assumed it was public because it does not start with a _. If this is a problem, fixing nntplib and using a private copy might be the better solution.
Also note that I've already sent a patch to patches@python.org ;) with a pointer to the mailman-users discussion in question.
http://www.python.org/pipermail/patches/2000-February/000015.html
I sent a similar nntplib patch to mailman-users last week, although I
Ah, sorry, I dont read mailman-users, apparently. I thought I did, though, Strange. I'm sorry if I seem to have stolen your idea, it was not intentional. Anyway, the right place for this patch is not Mailman, it is Python. nntplib is part of the standard library, nowadays, Mailman only has its own local copy for compatibility with older python distributions. I'm a bit fearful of setting readermode so often, though -- aren't there possibly cases where people want to provide authentication, but do not want readermode ?
(I'm not concerned with newsservers that dont understand 'mode reader'. If they barf on that, they are highly likely to barf on everything else you try out, too. I am concerned with setting a newsconnection to reader when you dont want a reader -- though I'm not sure what would be the effect.)
-- Thomas Wouters <thomas@xs4all.net>
Hi! I'm a .signature virus! copy me into your .signature file to help me spread!
"JT" == Jim Tittsler <jwt@dskk.co.jp> writes:
JT> I still think it better to change nntplib.
I agree. I'd still like to get rid of your bare except though; I'm guessing that error_perm is probably correct because of this:
import nntplib x = nntplib.NNTP('ournews') x.shortcmd('mode foobar') Traceback (innermost last): File "<stdin>", line 1, in ? File "/depot/sundry/lib/python1.5/nntplib.py", line 158, in shortcmd return self.getresp() File "/depot/sundry/lib/python1.5/nntplib.py", line 134, in getresp raise error_perm, resp nntplib.error_perm: 500 Syntax error or bad command
The Right Thing To Do is to recast the nntplib errors as exception classes and perhaps use it's base class in the except. I'd be willing to make this change, and merge in your patch, but you'll need to resend your patch with the standard email disclaimer appended. See
http://www.python.org/patches/
for details. Would you be willing to do that?
Thanks, -Barry
Okay, here's my proposed patch to the current CVS version of nntplib.py. It merges Jim's and Thomas's patches, and re-implements the module's exceptions as class-based (with backwards compatibility).
I'm not sure what to do about the email disclaimers, but I'd say to be safe that both Jim and Thomas should re-submit their patches with the disclaimer attached (you can just to this to patches@python.org).
Everyone else on patches@python.org: please let me know if you have any objections to this change. Otherwise, I'll commit it (and make the necessary documentation updates).
-Barry
-------------------- snip snip -------------------- Index: nntplib.py
RCS file: /projects/cvsroot/python/dist/src/Lib/nntplib.py,v retrieving revision 1.17 diff -c -r1.17 nntplib.py *** nntplib.py 2000/02/04 15:10:33 1.17 --- nntplib.py 2000/02/08 23:11:44
*** 34,47 **** import string
! # Exception raised when an error or invalid response is received ! error_reply = 'nntplib.error_reply' # unexpected [123]xx reply ! error_temp = 'nntplib.error_temp' # 4xx errors ! error_perm = 'nntplib.error_perm' # 5xx errors ! error_proto = 'nntplib.error_proto' # response does not begin with [1-5] ! error_data = 'nntplib.error_data' # error in response data
# Standard port used by NNTP servers NNTP_PORT = 119
--- 34,79 ---- import string
! ! # Exceptions raised when an error or invalid response is received ! class NNTPError(Exception): ! """Base class for all nntplib exceptions""" ! def __init__(self, *args): ! apply(Exception.__init__, (self,)+args) ! try: ! self.response = args[0] ! except IndexError: ! self.response = 'No response given' ! ! class NNTPReplyError(NNTPError): ! """Unexpected [123]xx reply""" ! pass ! ! class NNTPTemporaryError(NNTPError): ! """4xx errors""" ! pass ! ! class NNTPPermanentError(NNTPError): ! """5xx errors""" ! pass ! ! class NNTPProtocolError(NNTPError): ! """Response does not begin with [1-5]""" ! pass ! ! class NNTPDataError(NNTPError): ! """Error in response data""" ! pass ! ! # for backwards compatibility ! error_reply = NNTPReplyError ! error_temp = NNTPTemporaryError ! error_perm = NNTPPermanentError ! error_proto = NNTPProtocolError ! error_data = NNTPDataError
- # Standard port used by NNTP servers NNTP_PORT = 119
*** 54,68 **** CRLF = '\r\n'
# The class itself
class NNTP: ! ! def __init__(self, host, port = NNTP_PORT, user=None, password=None): """Initialize an instance. Arguments: - host: hostname to connect to ! - port: port to connect to (default the standard NNTP port)""" ! self.host = host self.port = port self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) --- 86,108 ---- CRLF = '\r\n'
- # The class itself class NNTP: ! def __init__(self, host, port = NNTP_PORT, user=None, password=None, ! readermode=None): """Initialize an instance. Arguments: - host: hostname to connect to ! - port: port to connect to (default the standard NNTP port) ! - user: username to authenticate with ! - password: password to use with username ! - readermode: if true, send 'mode reader' command after ! connecting. ! ! readermode is sometimes necessary if you are connecting to an ! NNTP server on your local machine and intend to call the ! group() method. ! """ self.host = host self.port = port self.sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
*** 70,85 **** self.file = self.sock.makefile('rb') self.debugging = 0 self.welcome = self.getresp() if user: resp = self.shortcmd('authinfo user '+user) if resp[:3] == '381': if not password: ! raise error_reply, resp else: resp = self.shortcmd( 'authinfo pass '+password) if resp[:3] != '281': ! raise error_perm, resp
def getwelcome(self):
"""Get the welcome message from the server
--- 110,136 ---- self.file = self.sock.makefile('rb') self.debugging = 0 self.welcome = self.getresp()
if readermode:
if user: resp = self.shortcmd('authinfo user '+user) if resp[:3] == '381': if not password:
! raise NNTPReplyError(resp) else: resp = self.shortcmd( 'authinfo pass '+password) if resp[:3] != '281': ! raise NNTPPermanentError(resp) ! ! # Get the welcome message from the server ! # (this is read and squirreled away by __init__()). ! # If the response code is 200, posting is allowed; ! # if it 201, posting is not allowed
def getwelcome(self): """Get the welcome message from the server
*** 128,138 ****
if self.debugging: print '*resp*', resp
c = resp[:1]
if c == '4':
! raise error_temp, resp
if c == '5':
! raise error_perm, resp
if c not in '123':
! raise error_proto, resp
return resp
def getlongresp(self):
--- 179,189 ----
if self.debugging: print '*resp*', resp
c = resp[:1]
if c == '4':
! raise NNTPTemporaryError(resp)
if c == '5':
! raise NNTPPermanentError(resp)
if c not in '123':
! raise NNTPProtocolError(resp)
return resp
def getlongresp(self):
*** 140,146 **** Raise various errors if the response indicates an error.""" resp = self.getresp() if resp[:3] not in LONGRESP: ! raise error_reply, resp list = [] while 1: line = self.getline() --- 191,197 ---- Raise various errors if the response indicates an error.""" resp = self.getresp() if resp[:3] not in LONGRESP: ! raise NNTPReplyError(resp) list = [] while 1: line = self.getline()
*** 206,212 ****
resp = self.shortcmd('GROUP ' + name)
if resp[:3] <> '211':
! raise error_reply, resp words = string.split(resp) count = first = last = 0 n = len(words) --- 257,263 ----
resp = self.shortcmd('GROUP ' + name)
if resp[:3] <> '211':
! raise NNTPReplyError(resp) words = string.split(resp) count = first = last = 0 n = len(words)
*** 230,236 **** def statparse(self, resp): """Internal: parse the response of a STAT, NEXT or LAST command.""" if resp[:2] <> '22': ! raise error_reply, resp words = string.split(resp) nr = 0 id = '' --- 281,287 ---- def statparse(self, resp): """Internal: parse the response of a STAT, NEXT or LAST command.""" if resp[:2] <> '22': ! raise NNTPReplyError(resp) words = string.split(resp) nr = 0 id = ''
*** 349,355 **** elem[6], elem[7])) except IndexError: ! raise error_data,line return resp,xover_lines
def xgtitle(self, group):
--- 400,406 ---- elem[6], elem[7])) except IndexError: ! raise NNTPDataError(line) return resp,xover_lines
def xgtitle(self, group):
*** 377,387 ****
resp = self.shortcmd("XPATH " + id)
if resp[:3] <> '223':
! raise error_reply, resp try: [resp_num, path] = string.split(resp) except ValueError: ! raise error_reply, resp else: return resp, path
--- 428,438 ----
resp = self.shortcmd("XPATH " + id)
if resp[:3] <> '223':
! raise NNTPReplyError(resp) try: [resp_num, path] = string.split(resp) except ValueError: ! raise NNTPReplyError(resp) else: return resp, path
*** 395,408 ****
resp = self.shortcmd("DATE")
if resp[:3] <> '111':
! raise error_reply, resp elem = string.split(resp) if len(elem) != 2: ! raise error_data, resp date = elem[1][2:8] time = elem[1][-6:] if len(date) != 6 or len(time) != 6: ! raise error_data, resp return resp, date, time
--- 446,459 ----
resp = self.shortcmd("DATE")
if resp[:3] <> '111':
! raise NNTPReplyError(resp) elem = string.split(resp) if len(elem) != 2: ! raise NNTPDataError(resp) date = elem[1][2:8] time = elem[1][-6:] if len(date) != 6 or len(time) != 6: ! raise NNTPDataError(resp) return resp, date, time
*** 415,421 **** resp = self.shortcmd('POST') # Raises error_??? if posting is not allowed if resp[0] <> '3': ! raise error_reply, resp while 1: line = f.readline() if not line: --- 466,472 ---- resp = self.shortcmd('POST') # Raises error_??? if posting is not allowed if resp[0] <> '3': ! raise NNTPReplyError(resp) while 1: line = f.readline() if not line:
*** 439,445 **** resp = self.shortcmd('IHAVE ' + id) # Raises error_??? if the server already has it if resp[0] <> '3': ! raise error_reply, resp while 1: line = f.readline() if not line: --- 490,496 ---- resp = self.shortcmd('IHAVE ' + id) # Raises error_??? if the server already has it if resp[0] <> '3': ! raise NNTPReplyError(resp) while 1: line = f.readline() if not line:
*** 465,471 ****
def _test(): """Minimal test function.""" ! s = NNTP('news') resp, count, first, last, name = s.group('comp.lang.python') print resp print 'Group', name, 'has', count, 'articles, range', first, 'to', last --- 516,522 ----
def _test(): """Minimal test function.""" ! s = NNTP('news', readermode='reader') resp, count, first, last, name = s.group('comp.lang.python') print resp print 'Group', name, 'has', count, 'articles, range', first, 'to', last
participants (6)
-
Barry A. Warsaw
-
bwarsaw@cnri.reston.va.us
-
Gergely Madarasz
-
Jim Tittsler
-
Lazarus Long
-
Thomas Wouters