Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / amd64 / html / python / lib / module-nntplib.html
CommitLineData
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">
5611.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>
67This module defines the class <tt class="class">NNTP</tt> which implements the client
68side of the NNTP protocol. It can be used to implement a news reader
69or 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'
71href="http://www.faqs.org/rfcs/rfc977.html">RFC 977</a>.
72
73<P>
74Here are two small examples of how it can be used. To list some
75statistics about a newsgroup and print the subjects of the last 10
76articles:
77
78<P>
79<div class="verbatim"><pre>
80&gt;&gt;&gt; s = NNTP('news.cwi.nl')
81&gt;&gt;&gt; resp, count, first, last, name = s.group('comp.lang.python')
82&gt;&gt;&gt; print 'Group', name, 'has', count, 'articles, range', first, 'to', last
83Group comp.lang.python has 59 articles, range 3742 to 3803
84&gt;&gt;&gt; resp, subs = s.xhdr('subject', first + '-' + last)
85&gt;&gt;&gt; for id, sub in subs[-10:]: print id, sub
86...
873792 Re: Removing elements from a list while iterating...
883793 Re: Who likes Info files?
893794 Emacs and doc strings
903795 a few questions about the Mac implementation
913796 Re: executable python scripts
923797 Re: executable python scripts
933798 Re: a few questions about the Mac implementation
943799 Re: PROPOSAL: A Generic Python Object Interface for Python C Modules
953802 Re: executable python scripts
963803 Re: \POSIX{} wait and SIGCHLD
97&gt;&gt;&gt; s.quit()
98'205 news.cwi.nl closing connection. Goodbye.'
99</pre></div>
100
101<P>
102To post an article from a file (this assumes that the article has
103valid headers):
104
105<P>
106<div class="verbatim"><pre>
107&gt;&gt;&gt; s = NNTP('news.cwi.nl')
108&gt;&gt;&gt; f = open('/tmp/article')
109&gt;&gt;&gt; s.post(f)
110'240 Article posted successfully.'
111&gt;&gt;&gt; s.quit()
112'205 news.cwi.nl closing connection. Goodbye.'
113</pre></div>
114
115<P>
116The 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>&nbsp;<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>
126Return a new instance of the <tt class="class">NNTP</tt> class, representing a
127connection to the NNTP server running on host <var>host</var>, listening at
128port <var>port</var>. The default <var>port</var> is 119. If the optional
129<var>user</var> and <var>password</var> are provided,
130or if suitable credentials are present in <span class="file">&nbsp;/.netrc</span> and the
131optional flag <var>usenetrc</var> is true (the default),
132the "<tt class="samp">AUTHINFO USER</tt>" and "<tt class="samp">AUTHINFO PASS</tt>" commands are used to
133identify and authenticate the user to the server. If the optional
134flag <var>readermode</var> is true, then a "<tt class="samp">mode reader</tt>" command is
135sent before authentication is performed. Reader mode is sometimes
136necessary if you are connecting to an NNTP server on the local machine
137and intend to call reader-specific commands, such as "<tt class="samp">group</tt>". If
138you 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>&nbsp;<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>
154Derived from the standard exception <code>Exception</code>, this is the base
155class 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>&nbsp;<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>
163Exception raised when an unexpected reply is received from the
164server. For backwards compatibility, the exception <code>error_reply</code>
165is 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>&nbsp;<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>
173Exception raised when an error code in the range 400-499 is
174received. 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>&nbsp;<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>
183Exception raised when an error code in the range 500-599 is
184received. 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>&nbsp;<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>
193Exception raised when a reply is received from the server that does
194not begin with a digit in the range 1-5. For backwards
195compatibility, the exception <code>error_proto</code> is equivalent to this
196class.
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>&nbsp;<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>
204Exception raised when there is some error in the response data. For
205backwards compatibility, the exception <code>error_data</code> is
206equivalent 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>
260See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
261</ADDRESS>
262</BODY>
263</HTML>