Initial commit of OpenSPARC T2 architecture model.
[OpenSPARC-T2-SAM] / sam-t2 / devtools / v8plus / html / python / lib / module-nntplib.html
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<link rel="STYLESHEET" href="lib.css" type='text/css' />
<link rel="SHORTCUT ICON" href="../icons/pyfav.png" type="image/png" />
<link rel='start' href='../index.html' title='Python Documentation Index' />
<link rel="first" href="lib.html" title='Python Library Reference' />
<link rel='contents' href='contents.html' title="Contents" />
<link rel='index' href='genindex.html' title='Index' />
<link rel='last' href='about.html' title='About this document...' />
<link rel='help' href='about.html' title='About this document...' />
<link rel="next" href="module-smtplib.html" />
<link rel="prev" href="module-imaplib.html" />
<link rel="parent" href="internet.html" />
<link rel="next" href="nntp-objects.html" />
<meta name='aesop' content='information' />
<title>11.11 nntplib -- NNTP protocol client</title>
</head>
<body>
<DIV CLASS="navigation">
<div id='top-navigation-panel' xml:id='top-navigation-panel'>
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="11.10.2 IMAP4 Example"
href="imap4-example.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="11. Internet Protocols and"
href="internet.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="11.11.1 NNTP Objects"
href="nntp-objects.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="imap4-example.html">11.10.2 IMAP4 Example</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="nntp-objects.html">11.11.1 NNTP Objects</A>
</div>
<hr /></div>
</DIV>
<!--End of Navigation Panel-->
<H1><A NAME="SECTION00131100000000000000000">
11.11 <tt class="module">nntplib</tt> --
NNTP protocol client</A>
</H1>
<P>
<A NAME="module-nntplib"></A>
<P>
<a id='l2h-3453' xml:id='l2h-3453'></a><a id='l2h-3461' xml:id='l2h-3461'></a>
<P>
This module defines the class <tt class="class">NNTP</tt> which implements the client
side of the NNTP protocol. It can be used to implement a news reader
or poster, or automated news processors. For more information on NNTP
(Network News Transfer Protocol), see Internet <a class="rfc" id='rfcref-90274' xml:id='rfcref-90274'
href="http://www.faqs.org/rfcs/rfc977.html">RFC 977</a>.
<P>
Here are two small examples of how it can be used. To list some
statistics about a newsgroup and print the subjects of the last 10
articles:
<P>
<div class="verbatim"><pre>
&gt;&gt;&gt; s = NNTP('news.cwi.nl')
&gt;&gt;&gt; resp, count, first, last, name = s.group('comp.lang.python')
&gt;&gt;&gt; print 'Group', name, 'has', count, 'articles, range', first, 'to', last
Group comp.lang.python has 59 articles, range 3742 to 3803
&gt;&gt;&gt; resp, subs = s.xhdr('subject', first + '-' + last)
&gt;&gt;&gt; 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
&gt;&gt;&gt; s.quit()
'205 news.cwi.nl closing connection. Goodbye.'
</pre></div>
<P>
To post an article from a file (this assumes that the article has
valid headers):
<P>
<div class="verbatim"><pre>
&gt;&gt;&gt; s = NNTP('news.cwi.nl')
&gt;&gt;&gt; f = open('/tmp/article')
&gt;&gt;&gt; s.post(f)
'240 Article posted successfully.'
&gt;&gt;&gt; s.quit()
'205 news.cwi.nl closing connection. Goodbye.'
</pre></div>
<P>
The module itself defines the following items:
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3454' xml:id='l2h-3454' class="class">NNTP</tt></b>(</nobr></td>
<td><var>host</var><big>[</big><var>, port
</var><big>[</big><var>, user</var><big>[</big><var>, password
</var><big>[</big><var>, readermode</var><big>]</big><var>
</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>
<dd>
Return a new instance of the <tt class="class">NNTP</tt> class, representing a
connection to the NNTP server running on host <var>host</var>, listening at
port <var>port</var>. The default <var>port</var> is 119. If the optional
<var>user</var> and <var>password</var> are provided,
or if suitable credentials are present in <span class="file">&nbsp;/.netrc</span> and the
optional flag <var>usenetrc</var> is true (the default),
the "<tt class="samp">AUTHINFO USER</tt>" and "<tt class="samp">AUTHINFO PASS</tt>" commands are used to
identify and authenticate the user to the server. If the optional
flag <var>readermode</var> is true, then a "<tt class="samp">mode reader</tt>" command is
sent before authentication is performed. Reader mode is sometimes
necessary if you are connecting to an NNTP server on the local machine
and intend to call reader-specific commands, such as "<tt class="samp">group</tt>". If
you get unexpected <code>NNTPPermanentError</code>s, you might need to set
<var>readermode</var>. <var>readermode</var> defaults to <code>None</code>.
<var>usenetrc</var> defaults to <code>True</code>.
<P>
<span class="versionnote">Changed in version 2.4:
<var>usenetrc</var> argument added.</span>
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3455' xml:id='l2h-3455' class="class">NNTPError</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Derived from the standard exception <code>Exception</code>, this is the base
class for all exceptions raised by the <code>nntplib</code> module.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3456' xml:id='l2h-3456' class="class">NNTPReplyError</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Exception raised when an unexpected reply is received from the
server. For backwards compatibility, the exception <code>error_reply</code>
is equivalent to this class.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3457' xml:id='l2h-3457' class="class">NNTPTemporaryError</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Exception raised when an error code in the range 400-499 is
received. For backwards compatibility, the exception
<code>error_temp</code> is equivalent to this class.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3458' xml:id='l2h-3458' class="class">NNTPPermanentError</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Exception raised when an error code in the range 500-599 is
received. For backwards compatibility, the exception
<code>error_perm</code> is equivalent to this class.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3459' xml:id='l2h-3459' class="class">NNTPProtocolError</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Exception raised when a reply is received from the server that does
not begin with a digit in the range 1-5. For backwards
compatibility, the exception <code>error_proto</code> is equivalent to this
class.
</dl>
<P>
<dl><dt><table cellpadding="0" cellspacing="0"><tr valign="baseline">
<td><nobr><b><span class="typelabel">class</span>&nbsp;<tt id='l2h-3460' xml:id='l2h-3460' class="class">NNTPDataError</tt></b>(</nobr></td>
<td><var></var>)</td></tr></table></dt>
<dd>
Exception raised when there is some error in the response data. For
backwards compatibility, the exception <code>error_data</code> is
equivalent to this class.
</dl>
<P>
<p><br /></p><hr class='online-navigation' />
<div class='online-navigation'>
<!--Table of Child-Links-->
<A NAME="CHILD_LINKS"><STRONG>Subsections</STRONG></a>
<UL CLASS="ChildLinks">
<LI><A href="nntp-objects.html">11.11.1 NNTP Objects</a>
</ul>
<!--End of Table of Child-Links-->
</div>
<DIV CLASS="navigation">
<div class='online-navigation'>
<p></p><hr />
<table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td class='online-navigation'><a rel="prev" title="11.10.2 IMAP4 Example"
href="imap4-example.html"><img src='../icons/previous.png'
border='0' height='32' alt='Previous Page' width='32' /></A></td>
<td class='online-navigation'><a rel="parent" title="11. Internet Protocols and"
href="internet.html"><img src='../icons/up.png'
border='0' height='32' alt='Up One Level' width='32' /></A></td>
<td class='online-navigation'><a rel="next" title="11.11.1 NNTP Objects"
href="nntp-objects.html"><img src='../icons/next.png'
border='0' height='32' alt='Next Page' width='32' /></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td class='online-navigation'><a rel="contents" title="Table of Contents"
href="contents.html"><img src='../icons/contents.png'
border='0' height='32' alt='Contents' width='32' /></A></td>
<td class='online-navigation'><a href="modindex.html" title="Module Index"><img src='../icons/modules.png'
border='0' height='32' alt='Module Index' width='32' /></a></td>
<td class='online-navigation'><a rel="index" title="Index"
href="genindex.html"><img src='../icons/index.png'
border='0' height='32' alt='Index' width='32' /></A></td>
</tr></table>
<div class='online-navigation'>
<b class="navlabel">Previous:</b>
<a class="sectref" rel="prev" href="imap4-example.html">11.10.2 IMAP4 Example</A>
<b class="navlabel">Up:</b>
<a class="sectref" rel="parent" href="internet.html">11. Internet Protocols and</A>
<b class="navlabel">Next:</b>
<a class="sectref" rel="next" href="nntp-objects.html">11.11.1 NNTP Objects</A>
</div>
</div>
<hr />
<span class="release-info">Release 2.4.2, documentation updated on 28 September 2005.</span>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
See <i><a href="about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>