このモジュールでは、 クラス NNTP を定義しています。このクラス は NNTP プロトコルのクライアント側を実装しています。このモジュールを 使えば、ニュースリーダや記事投稿プログラム、または自動的にニュース記事を 処理するプログラムを実装することができます。NNTP (Network News Transfer Protocol、ネットニュース転送プロトコル) の詳細については、 インターネット RFC 977 を参照してください。
以下にこのモジュールの使い方の小さな例を二つ示します。 ニュースグループに関する統計情報を列挙し、最新 10 件の記事を出力 するには以下のようにします:
>>> s = NNTP('news.cwi.nl') >>> resp, count, first, last, name = s.group('comp.lang.python') >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last Group 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 strings 3795 a few questions about the Mac implementation 3796 Re: executable python scripts 3797 Re: executable python scripts 3798 Re: a few questions about the Mac implementation 3799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules 3802 Re: executable python scripts 3803 Re: \POSIX{} wait and SIGCHLD >>> s.quit() '205 news.cwi.nl closing connection. Goodbye.'
ファイルから記事を投稿するには、以下のようにします (この例では記事番号は有効な番号を指定していると仮定しています):
>>> 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.'
このモジュール自体では以下の内容を定義しています:
host[, port [, user[, password [, readermode]]]]) |
NNTPPermanentError
に遭遇したなら、readermode を設定する必要があるかもしれません。
readermode 標準で None
です。
) |
Exception
から導出されており、nntplib
モジュールが送出する全ての例外の基底クラスです。
) |
error_reply
はこのクラスと等価になっています。
) |
error_temp
はこのクラスと等価になっています。
) |
error_perm
はこのクラスと等価になっています。
) |
error_proto
はこのクラスと等価になっています。
) |
error_data
はこのクラスと等価になっています。