Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> |
2 | <html> | |
3 | <head> | |
4 | <link rel="STYLESHEET" href="lib.css" type='text/css' /> | |
5 | <link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" /> | |
6 | <link rel='start' href='../index.html' title='Python Documentation Index' /> | |
7 | <link rel="first" href="lib.html" title='Python Library Reference' /> | |
8 | <link rel='contents' href='contents.html' title="Contents" /> | |
9 | <link rel='index' href='genindex.html' title='Index' /> | |
10 | <link rel='last' href='about.html' title='About this document...' /> | |
11 | <link rel='help' href='about.html' title='About this document...' /> | |
12 | <link rel="next" href="module-smtplib.html" /> | |
13 | <link rel="prev" href="module-imaplib.html" /> | |
14 | <link rel="parent" href="internet.html" /> | |
15 | <link rel="next" href="nntp-objects.html" /> | |
16 | <meta name='aesop' content='information' /> | |
17 | <title>11.11 nntplib -- NNTP protocol client</title> | |
18 | </head> | |
19 | <body> | |
20 | <DIV CLASS="navigation"> | |
21 | <div id='top-navigation-panel' xml:id='top-navigation-panel'> | |
22 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
23 | <tr> | |
24 | <td class='online-navigation'><a rel="prev" title="11.10.2 IMAP4 Example" | |
25 | href="imap4-example.html"><img src='../icons/previous.png' | |
26 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
27 | <td class='online-navigation'><a rel="parent" title="11. Internet Protocols and" | |
28 | href="internet.html"><img src='../icons/up.png' | |
29 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
30 | <td class='online-navigation'><a rel="next" title="11.11.1 NNTP Objects" | |
31 | href="nntp-objects.html"><img src='../icons/next.png' | |
32 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
33 | <td align="center" width="100%">Python Library Reference</td> | |
34 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
35 | href="contents.html"><img src='../icons/contents.png' | |
36 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
37 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
38 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
39 | <td class='online-navigation'><a rel="index" title="Index" | |
40 | href="genindex.html"><img src='../icons/index.png' | |
41 | border='0' height='32' alt='Index' width='32' /></A></td> | |
42 | </tr></table> | |
43 | <div class='online-navigation'> | |
44 | <b class="navlabel">Previous:</b> | |
45 | <a class="sectref" rel="prev" href="imap4-example.html">11.10.2 IMAP4 Example</A> | |
46 | <b class="navlabel">Up:</b> | |
47 | <a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A> | |
48 | <b class="navlabel">Next:</b> | |
49 | <a class="sectref" rel="next" href="nntp-objects.html">11.11.1 NNTP Objects</A> | |
50 | </div> | |
51 | <hr /></div> | |
52 | </DIV> | |
53 | <!--End of Navigation Panel--> | |
54 | ||
55 | <H1><A NAME="SECTION00131100000000000000000"> | |
56 | 11.11 <tt class="module">nntplib</tt> -- | |
57 | NNTP protocol client</A> | |
58 | </H1> | |
59 | ||
60 | <P> | |
61 | <A NAME="module-nntplib"></A> | |
62 | ||
63 | <P> | |
64 | <a id='l2h-3453' xml:id='l2h-3453'></a><a id='l2h-3461' xml:id='l2h-3461'></a> | |
65 | ||
66 | <P> | |
67 | This module defines the class <tt class="class">NNTP</tt> which implements the client | |
68 | side of the NNTP protocol. It can be used to implement a news reader | |
69 | or poster, or automated news processors. For more information on NNTP | |
70 | (Network News Transfer Protocol), see Internet <a class="rfc" id='rfcref-90274' xml:id='rfcref-90274' | |
71 | href="http://www.faqs.org/rfcs/rfc977.html">RFC 977</a>. | |
72 | ||
73 | <P> | |
74 | Here are two small examples of how it can be used. To list some | |
75 | statistics about a newsgroup and print the subjects of the last 10 | |
76 | articles: | |
77 | ||
78 | <P> | |
79 | <div class="verbatim"><pre> | |
80 | >>> s = NNTP('news.cwi.nl') | |
81 | >>> resp, count, first, last, name = s.group('comp.lang.python') | |
82 | >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last | |
83 | Group comp.lang.python has 59 articles, range 3742 to 3803 | |
84 | >>> resp, subs = s.xhdr('subject', first + '-' + last) | |
85 | >>> for id, sub in subs[-10:]: print id, sub | |
86 | ... | |
87 | 3792 Re: Removing elements from a list while iterating... | |
88 | 3793 Re: Who likes Info files? | |
89 | 3794 Emacs and doc strings | |
90 | 3795 a few questions about the Mac implementation | |
91 | 3796 Re: executable python scripts | |
92 | 3797 Re: executable python scripts | |
93 | 3798 Re: a few questions about the Mac implementation | |
94 | 3799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules | |
95 | 3802 Re: executable python scripts | |
96 | 3803 Re: \POSIX{} wait and SIGCHLD | |
97 | >>> s.quit() | |
98 | '205 news.cwi.nl closing connection. Goodbye.' | |
99 | </pre></div> | |
100 | ||
101 | <P> | |
102 | To post an article from a file (this assumes that the article has | |
103 | valid headers): | |
104 | ||
105 | <P> | |
106 | <div class="verbatim"><pre> | |
107 | >>> s = NNTP('news.cwi.nl') | |
108 | >>> f = open('/tmp/article') | |
109 | >>> s.post(f) | |
110 | '240 Article posted successfully.' | |
111 | >>> s.quit() | |
112 | '205 news.cwi.nl closing connection. Goodbye.' | |
113 | </pre></div> | |
114 | ||
115 | <P> | |
116 | The module itself defines the following items: | |
117 | ||
118 | <P> | |
119 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
120 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3454' xml:id='l2h-3454' class="class">NNTP</tt></b>(</nobr></td> | |
121 | <td><var>host</var><big>[</big><var>, port | |
122 | </var><big>[</big><var>, user</var><big>[</big><var>, password | |
123 | </var><big>[</big><var>, readermode</var><big>]</big><var> | |
124 | </var><big>[</big><var>, usenetrc</var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var><big>]</big><var></var>)</td></tr></table></dt> | |
125 | <dd> | |
126 | Return a new instance of the <tt class="class">NNTP</tt> class, representing a | |
127 | connection to the NNTP server running on host <var>host</var>, listening at | |
128 | port <var>port</var>. The default <var>port</var> is 119. If the optional | |
129 | <var>user</var> and <var>password</var> are provided, | |
130 | or if suitable credentials are present in <span class="file"> /.netrc</span> and the | |
131 | optional flag <var>usenetrc</var> is true (the default), | |
132 | the "<tt class="samp">AUTHINFO USER</tt>" and "<tt class="samp">AUTHINFO PASS</tt>" commands are used to | |
133 | identify and authenticate the user to the server. If the optional | |
134 | flag <var>readermode</var> is true, then a "<tt class="samp">mode reader</tt>" command is | |
135 | sent before authentication is performed. Reader mode is sometimes | |
136 | necessary if you are connecting to an NNTP server on the local machine | |
137 | and intend to call reader-specific commands, such as "<tt class="samp">group</tt>". If | |
138 | you get unexpected <code>NNTPPermanentError</code>s, you might need to set | |
139 | <var>readermode</var>. <var>readermode</var> defaults to <code>None</code>. | |
140 | <var>usenetrc</var> defaults to <code>True</code>. | |
141 | ||
142 | <P> | |
143 | ||
144 | <span class="versionnote">Changed in version 2.4: | |
145 | <var>usenetrc</var> argument added.</span> | |
146 | ||
147 | </dl> | |
148 | ||
149 | <P> | |
150 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
151 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3455' xml:id='l2h-3455' class="class">NNTPError</tt></b>(</nobr></td> | |
152 | <td><var></var>)</td></tr></table></dt> | |
153 | <dd> | |
154 | Derived from the standard exception <code>Exception</code>, this is the base | |
155 | class for all exceptions raised by the <code>nntplib</code> module. | |
156 | </dl> | |
157 | ||
158 | <P> | |
159 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
160 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3456' xml:id='l2h-3456' class="class">NNTPReplyError</tt></b>(</nobr></td> | |
161 | <td><var></var>)</td></tr></table></dt> | |
162 | <dd> | |
163 | Exception raised when an unexpected reply is received from the | |
164 | server. For backwards compatibility, the exception <code>error_reply</code> | |
165 | is equivalent to this class. | |
166 | </dl> | |
167 | ||
168 | <P> | |
169 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
170 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3457' xml:id='l2h-3457' class="class">NNTPTemporaryError</tt></b>(</nobr></td> | |
171 | <td><var></var>)</td></tr></table></dt> | |
172 | <dd> | |
173 | Exception raised when an error code in the range 400-499 is | |
174 | received. For backwards compatibility, the exception | |
175 | <code>error_temp</code> is equivalent to this class. | |
176 | </dl> | |
177 | ||
178 | <P> | |
179 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
180 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3458' xml:id='l2h-3458' class="class">NNTPPermanentError</tt></b>(</nobr></td> | |
181 | <td><var></var>)</td></tr></table></dt> | |
182 | <dd> | |
183 | Exception raised when an error code in the range 500-599 is | |
184 | received. For backwards compatibility, the exception | |
185 | <code>error_perm</code> is equivalent to this class. | |
186 | </dl> | |
187 | ||
188 | <P> | |
189 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
190 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3459' xml:id='l2h-3459' class="class">NNTPProtocolError</tt></b>(</nobr></td> | |
191 | <td><var></var>)</td></tr></table></dt> | |
192 | <dd> | |
193 | Exception raised when a reply is received from the server that does | |
194 | not begin with a digit in the range 1-5. For backwards | |
195 | compatibility, the exception <code>error_proto</code> is equivalent to this | |
196 | class. | |
197 | </dl> | |
198 | ||
199 | <P> | |
200 | <dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline"> | |
201 | <td><nobr><b><span class="typelabel">class</span> <tt id='l2h-3460' xml:id='l2h-3460' class="class">NNTPDataError</tt></b>(</nobr></td> | |
202 | <td><var></var>)</td></tr></table></dt> | |
203 | <dd> | |
204 | Exception raised when there is some error in the response data. For | |
205 | backwards compatibility, the exception <code>error_data</code> is | |
206 | equivalent to this class. | |
207 | </dl> | |
208 | ||
209 | <P> | |
210 | ||
211 | <p><br /></p><hr class='online-navigation' /> | |
212 | <div class='online-navigation'> | |
213 | <!--Table of Child-Links--> | |
214 | <A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a> | |
215 | ||
216 | <UL CLASS="ChildLinks"> | |
217 | <LI><A href="nntp-objects.html">11.11.1 NNTP Objects</a> | |
218 | </ul> | |
219 | <!--End of Table of Child-Links--> | |
220 | </div> | |
221 | ||
222 | <DIV CLASS="navigation"> | |
223 | <div class='online-navigation'> | |
224 | <p></p><hr /> | |
225 | <table align="center" width="100%" cellpadding="0" cellspacing="2"> | |
226 | <tr> | |
227 | <td class='online-navigation'><a rel="prev" title="11.10.2 IMAP4 Example" | |
228 | href="imap4-example.html"><img src='../icons/previous.png' | |
229 | border='0' height='32' alt='Previous Page' width='32' /></A></td> | |
230 | <td class='online-navigation'><a rel="parent" title="11. Internet Protocols and" | |
231 | href="internet.html"><img src='../icons/up.png' | |
232 | border='0' height='32' alt='Up One Level' width='32' /></A></td> | |
233 | <td class='online-navigation'><a rel="next" title="11.11.1 NNTP Objects" | |
234 | href="nntp-objects.html"><img src='../icons/next.png' | |
235 | border='0' height='32' alt='Next Page' width='32' /></A></td> | |
236 | <td align="center" width="100%">Python Library Reference</td> | |
237 | <td class='online-navigation'><a rel="contents" title="Table of Contents" | |
238 | href="contents.html"><img src='../icons/contents.png' | |
239 | border='0' height='32' alt='Contents' width='32' /></A></td> | |
240 | <td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png' | |
241 | border='0' height='32' alt='Module Index' width='32' /></a></td> | |
242 | <td class='online-navigation'><a rel="index" title="Index" | |
243 | href="genindex.html"><img src='../icons/index.png' | |
244 | border='0' height='32' alt='Index' width='32' /></A></td> | |
245 | </tr></table> | |
246 | <div class='online-navigation'> | |
247 | <b class="navlabel">Previous:</b> | |
248 | <a class="sectref" rel="prev" href="imap4-example.html">11.10.2 IMAP4 Example</A> | |
249 | <b class="navlabel">Up:</b> | |
250 | <a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A> | |
251 | <b class="navlabel">Next:</b> | |
252 | <a class="sectref" rel="next" href="nntp-objects.html">11.11.1 NNTP Objects</A> | |
253 | </div> | |
254 | </div> | |
255 | <hr /> | |
256 | <span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span> | |
257 | </DIV> | |
258 | <!--End of Navigation Panel--> | |
259 | <ADDRESS> | |
260 | See <i><a href="about.html">About this document...</a></i> for information on suggesting changes. | |
261 | </ADDRESS> | |
262 | </BODY> | |
263 | </HTML> |