<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<!--Converted with LaTeX2HTML 98.2 beta6 (August 14th, 1998)
original version by:  Nikos Drakos, CBLU, University of Leeds
* revised and updated by:  Marcus Hennecke, Ross Moore, Herb Swan
* with significant contributions from:
  Jens Lippmann, Marek Rouchal, Martin Wilck and others -->
<HTML>
<HEAD>
<TITLE>11.8.1 NNTP Objects </TITLE>
<META NAME="description" CONTENT="11.8.1 NNTP Objects ">
<META NAME="keywords" CONTENT="lib">
<META NAME="resource-type" CONTENT="document">
<META NAME="distribution" CONTENT="global">
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso-8859-1">
<LINK REL="STYLESHEET" HREF="lib.css">
<LINK REL="previous" HREF="module-nntplib.html">
<LINK REL="up" HREF="module-nntplib.html">
<LINK REL="next" HREF="module-smtplib.html">
</HEAD>
<BODY bgcolor="#ffffff">
<div class=navigation>
<table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-smtplib.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-nntplib.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-nntplib.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-smtplib.html">11.9 smtplib  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-nntplib.html">11.8 nntplib  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-nntplib.html">11.8 nntplib  </A></span>
<br><hr></div>
<!--End of Navigation Panel-->

<H2><A NAME="SECTION0013810000000000000000"></A>
<BR>
11.8.1 NNTP Objects 
</H2>

<P>
NNTP instances have the following methods.  The <var>response</var> that is
returned as the first item in the return tuple of almost all methods
is the server's response: a string beginning with a three-digit code.
If the server's response indicates an error, the method raises one of
the above exceptions.

<P>
<dl><dt><b><a name="l2h-1738"><tt class=method>getwelcome</tt></a></b> ()
<dd>
Return the welcome message sent by the server in reply to the initial
connection.  (This message sometimes contains disclaimers or help
information that may be relevant to the user.)
</dl>

<P>
<dl><dt><b><a name="l2h-1739"><tt class=method>set_debuglevel</tt></a></b> (<var>level</var>)
<dd>
Set the instance's debugging level.  This controls the amount of
debugging output printed.  The default, <tt>0</tt>, produces no debugging
output.  A value of <tt>1</tt> produces a moderate amount of debugging
output, generally a single line per request or response.  A value of
<tt>2</tt> or higher produces the maximum amount of debugging output,
logging each line sent and received on the connection (including
message text).
</dl>

<P>
<dl><dt><b><a name="l2h-1740"><tt class=method>newgroups</tt></a></b> (<var>date, time</var>)
<dd>
Send a "<tt class=samp>NEWGROUPS</tt>" command.  The <var>date</var> argument should be a
string of the form <tt>'<var>yy</var><var>mm</var><var>dd</var>'</tt> indicating the
date, and <var>time</var> should be a string of the form
<tt>'<var>hh</var><var>mm</var><var>ss</var>'</tt> indicating the time.  Return a pair
<tt>(<var>response</var>, <var>groups</var>)</tt> where <var>groups</var> is a list of
group names that are new since the given date and time.
</dl>

<P>
<dl><dt><b><a name="l2h-1741"><tt class=method>newnews</tt></a></b> (<var>group, date, time</var>)
<dd>
Send a "<tt class=samp>NEWNEWS</tt>" command.  Here, <var>group</var> is a group name or
<tt>'*'</tt>, and <var>date</var> and <var>time</var> have the same meaning as for
<tt class=method>newgroups()</tt>.  Return a pair <tt>(<var>response</var>,
<var>articles</var>)</tt> where <var>articles</var> is a list of article ids.
</dl>

<P>
<dl><dt><b><a name="l2h-1742"><tt class=method>list</tt></a></b> ()
<dd>
Send a "<tt class=samp>LIST</tt>" command.  Return a pair <tt>(<var>response</var>,
<var>list</var>)</tt> where <var>list</var> is a list of tuples.  Each tuple has the
form <tt>(<var>group</var>, <var>last</var>, <var>first</var>, <var>flag</var>)</tt>, where
<var>group</var> is a group name, <var>last</var> and <var>first</var> are the last
and first article numbers (as strings), and <var>flag</var> is
<tt>'y'</tt> if posting is allowed, <tt>'n'</tt> if not, and <tt>'m'</tt> if
the newsgroup is moderated.  (Note the ordering: <var>last</var>,
<var>first</var>.)
</dl>

<P>
<dl><dt><b><a name="l2h-1743"><tt class=method>group</tt></a></b> (<var>name</var>)
<dd>
Send a "<tt class=samp>GROUP</tt>" command, where <var>name</var> is the group name.
Return a tuple <tt>(<var>response</var>, <var>count</var>, <var>first</var>,
<var>last</var>, <var>name</var>)</tt> where <var>count</var> is the (estimated) number
of articles in the group, <var>first</var> is the first article number in
the group, <var>last</var> is the last article number in the group, and
<var>name</var> is the group name.  The numbers are returned as strings.
</dl>

<P>
<dl><dt><b><a name="l2h-1744"><tt class=method>help</tt></a></b> ()
<dd>
Send a "<tt class=samp>HELP</tt>" command.  Return a pair <tt>(<var>response</var>,
<var>list</var>)</tt> where <var>list</var> is a list of help strings.
</dl>

<P>
<dl><dt><b><a name="l2h-1745"><tt class=method>stat</tt></a></b> (<var>id</var>)
<dd>
Send a "<tt class=samp>STAT</tt>" command, where <var>id</var> is the message id (enclosed
in "<tt class=character>&lt;</tt>" and "<tt class=character>&gt;</tt>") or an article number (as a string).
Return a triple <tt>(<var>response</var>, <var>number</var>, <var>id</var>)</tt> where
<var>number</var> is the article number (as a string) and <var>id</var> is the
article id  (enclosed in "<tt class=character>&lt;</tt>" and "<tt class=character>&gt;</tt>").
</dl>

<P>
<dl><dt><b><a name="l2h-1746"><tt class=method>next</tt></a></b> ()
<dd>
Send a "<tt class=samp>NEXT</tt>" command.  Return as for <tt class=method>stat()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-1747"><tt class=method>last</tt></a></b> ()
<dd>
Send a "<tt class=samp>LAST</tt>" command.  Return as for <tt class=method>stat()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-1748"><tt class=method>head</tt></a></b> (<var>id</var>)
<dd>
Send a "<tt class=samp>HEAD</tt>" command, where <var>id</var> has the same meaning as for
<tt class=method>stat()</tt>.  Return a tuple
<tt>(<var>response</var>, <var>number</var>, <var>id</var>, <var>list</var>)</tt>where the first three are the same as for <tt class=method>stat()</tt>,
and <var>list</var> is a list of the article's headers (an uninterpreted
list of lines, without trailing newlines).
</dl>

<P>
<dl><dt><b><a name="l2h-1749"><tt class=method>body</tt></a></b> (<var>id</var>)
<dd>
Send a "<tt class=samp>BODY</tt>" command, where <var>id</var> has the same meaning as for
<tt class=method>stat()</tt>.  Return as for <tt class=method>head()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-1750"><tt class=method>article</tt></a></b> (<var>id</var>)
<dd>
Send a "<tt class=samp>ARTICLE</tt>" command, where <var>id</var> has the same meaning as
for <tt class=method>stat()</tt>.  Return as for <tt class=method>head()</tt>.
</dl>

<P>
<dl><dt><b><a name="l2h-1751"><tt class=method>slave</tt></a></b> ()
<dd>
Send a "<tt class=samp>SLAVE</tt>" command.  Return the server's <var>response</var>.
</dl>

<P>
<dl><dt><b><a name="l2h-1752"><tt class=method>xhdr</tt></a></b> (<var>header, string</var>)
<dd>
Send an "<tt class=samp>XHDR</tt>" command.  This command is not defined in the RFC
but is a common extension.  The <var>header</var> argument is a header
keyword, e.g. <tt>'subject'</tt>.  The <var>string</var> argument should have
the form <tt>'<var>first</var>-<var>last</var>'</tt> where <var>first</var> and
<var>last</var> are the first and last article numbers to search.  Return a
pair <tt>(<var>response</var>, <var>list</var>)</tt>, where <var>list</var> is a list of
pairs <tt>(<var>id</var>, <var>text</var>)</tt>, where <var>id</var> is an article id
(as a string) and <var>text</var> is the text of the requested header for
that article.
</dl>

<P>
<dl><dt><b><a name="l2h-1753"><tt class=method>post</tt></a></b> (<var>file</var>)
<dd>
Post an article using the "<tt class=samp>POST</tt>" command.  The <var>file</var>
argument is an open file object which is read until EOF using its
<tt class=method>readline()</tt> method.  It should be a well-formed news article,
including the required headers.  The <tt class=method>post()</tt> method
automatically escapes lines beginning with "<tt class=samp>.</tt>".
</dl>

<P>
<dl><dt><b><a name="l2h-1754"><tt class=method>ihave</tt></a></b> (<var>id, file</var>)
<dd>
Send an "<tt class=samp>IHAVE</tt>" command.  If the response is not an error, treat
<var>file</var> exactly as for the <tt class=method>post()</tt> method.
</dl>

<P>
<dl><dt><b><a name="l2h-1755"><tt class=method>date</tt></a></b> ()
<dd>
Return a triple <tt>(<var>response</var>, <var>date</var>, <var>time</var>)</tt>,
containing the current date and time in a form suitable for the
<tt class=method>newnews()</tt> and <tt class=method>newgroups()</tt> methods.
This is an optional NNTP extension, and may not be supported by all
servers.
</dl>

<P>
<dl><dt><b><a name="l2h-1756"><tt class=method>xgtitle</tt></a></b> (<var>name</var>)
<dd>
Process an "<tt class=samp>XGTITLE</tt>" command, returning a pair <tt>(<var>response</var>,
<var>list</var>)</tt>, where <var>list</var> is a list of tuples containing
<tt>(<var>name</var>, <var>title</var>)</tt>.
This is an optional NNTP extension, and may not be supported by all
servers.
</dl>

<P>
<dl><dt><b><a name="l2h-1757"><tt class=method>xover</tt></a></b> (<var>start, end</var>)
<dd>
Return a pair <tt>(<var>resp</var>, <var>list</var>)</tt>.  <var>list</var> is a list
of tuples, one for each article in the range delimited by the <var>start</var>
and <var>end</var> article numbers.  Each tuple is of the form
<tt>(<var>article number</var>, <var>subject</var>, <var>poster</var>, <var>date</var>,
<var>id</var>, <var>references</var>, <var>size</var>, <var>lines</var>)</tt>.
This is an optional NNTP extension, and may not be supported by all
servers.
</dl>

<P>
<dl><dt><b><a name="l2h-1758"><tt class=method>xpath</tt></a></b> (<var>id</var>)
<dd>
Return a pair <tt>(<var>resp</var>, <var>path</var>)</tt>, where <var>path</var> is the
directory path to the article with message ID <var>id</var>.  This is an
optional NNTP extension, and may not be supported by all servers.
</dl>

<P>
<dl><dt><b><a name="l2h-1759"><tt class=method>quit</tt></a></b> ()
<dd>
Send a "<tt class=samp>QUIT</tt>" command and close the connection.  Once this method
has been called, no other methods of the NNTP object should be called.
</dl><p>
<div class=navigation><hr><table align=center width="100%" cellpadding=0 cellspacing=2>
<tr>
<td><A HREF="module-smtplib.html"><img width=32 height=32 align=bottom border=0 alt="next"
 src="../icons/next.gif"></A></td>
<td><A HREF="module-nntplib.html"><img width=32 height=32 align=bottom border=0 alt="up"
 src="../icons/up.gif"></A></td>
<td><A HREF="module-nntplib.html"><img width=32 height=32 align=bottom border=0 alt="previous"
 src="../icons/previous.gif"></A></td>
<td align=center bgcolor="#99CCFF" width="100%">
 <b class=title>Python Library Reference</b></td>
<td><A HREF="contents.html"><img width=32 height=32 align=bottom border=0 alt="contents"
 src="../icons/contents.gif"></A></td>
<td><a
 href="modindex.html"><img width=32 height=32 align=bottom border=0 alt="modules"
 src="../icons/modules.gif"></a></td>
<td><A HREF="genindex.html"><img width=32 height=32 align=bottom border=0 alt="index"
 src="../icons/index.gif"></A></td>
</tr></table><b class=navlabel>Next:</b> <span class=sectref><A HREF="module-smtplib.html">11.9 smtplib  </A></span>
<b class=navlabel>Up:</b> <span class=sectref><A HREF="module-nntplib.html">11.8 nntplib  </A></span>
<b class=navlabel>Previous:</b> <span class=sectref><A HREF="module-nntplib.html">11.8 nntplib  </A></span>
</div>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>Send comments on this document to <a href="mailto:python-docs@python.org">python-docs@python.org</a>.
</ADDRESS>
</BODY>
</HTML>
