Movatterモバイル変換


[0]ホーム

URL:


Up one LevelPython Library ReferenceContentsModule IndexIndex

18.12nntplib -- NNTP protocol client

This module defines the classNNTP which implements the clientside of the NNTP protocol. It can be used to implement a news readeror poster, or automated news processors. For more information on NNTP(Network News Transfer Protocol), see InternetRFC 977.

Here are two small examples of how it can be used. To list somestatistics about a newsgroup and print the subjects of the last 10articles:

>>> s = NNTP('news.cwi.nl')>>> resp, count, first, last, name = s.group('comp.lang.python')>>> print 'Group', name, 'has', count, 'articles, range', first, 'to', lastGroup comp.lang.python has 59 articles, range 3742 to 3803>>> resp, subs = s.xhdr('subject', first + '-' + last)>>> for id, sub in subs[-10:]: print id, sub... 3792 Re: Removing elements from a list while iterating...3793 Re: Who likes Info files?3794 Emacs and doc strings3795 a few questions about the Mac implementation3796 Re: executable python scripts3797 Re: executable python scripts3798 Re: a few questions about the Mac implementation 3799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules3802 Re: executable python scripts 3803 Re: \POSIX{} wait and SIGCHLD>>> s.quit()'205 news.cwi.nl closing connection.  Goodbye.'

To post an article from a file (this assumes that the article hasvalid headers):

>>> s = NNTP('news.cwi.nl')>>> f = open('/tmp/article')>>> s.post(f)'240 Article posted successfully.'>>> s.quit()'205 news.cwi.nl closing connection.  Goodbye.'

The module itself defines the following items:

class NNTP(host[, port[, user[, password[, readermode][, usenetrc]]]])
Return a new instance of theNNTP class, representing aconnection to the NNTP server running on hosthost, listening atportport. The defaultport is 119. If the optionaluser andpassword are provided, or if suitable credentials are present in /.netrc and theoptional flagusenetrc is true (the default),the "AUTHINFO USER" and "AUTHINFO PASS" commands are used toidentify and authenticate the user to the server. If the optionalflagreadermode is true, then a "mode reader" command issent before authentication is performed. Reader mode is sometimesnecessary if you are connecting to an NNTP server on the local machineand intend to call reader-specific commands, such as "group". Ifyou get unexpectedNNTPPermanentErrors, you might need to setreadermode.readermode defaults toNone.usenetrc defaults toTrue.

Changed in version 2.4:usenetrc argument added.

exception NNTPError
Derived from the standard exceptionException, this is thebase class for all exceptions raised by thenntplib module.

exception NNTPReplyError
Exception raised when an unexpected reply is received from theserver. For backwards compatibility, the exceptionerror_replyis equivalent to this class.

exception NNTPTemporaryError
Exception raised when an error code in the range 400-499 isreceived. For backwards compatibility, the exceptionerror_temp is equivalent to this class.

exception NNTPPermanentError
Exception raised when an error code in the range 500-599 isreceived. For backwards compatibility, the exceptionerror_perm is equivalent to this class.

exception NNTPProtocolError
Exception raised when a reply is received from the server that doesnot begin with a digit in the range 1-5. For backwardscompatibility, the exceptionerror_proto is equivalent to thisclass.

exception NNTPDataError
Exception raised when there is some error in the response data. Forbackwards compatibility, the exceptionerror_data isequivalent to this class.



Subsections


Up one LevelPython Library ReferenceContentsModule IndexIndex

Release 2.5.2, documentation updated on 21st February, 2008.
SeeAbout this document... for information on suggesting changes.
[8]ページ先頭

©2009-2025 Movatter.jp