📄 nntp-objects.html
字号:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>11.9.1 NNTP Objects </title>
<META NAME="description" CONTENT="11.9.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" tppabs="http://www.python.org/doc/current/lib/lib.css">
<LINK REL="previous" href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html">
<LINK REL="up" href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html">
<LINK REL="next" href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html">
</head>
<body>
<DIV CLASS="navigation"><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html">11.9 nntplib </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html">11.9 nntplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html">11.10 smtplib </A>
<br><hr></DIV>
<!--End of Navigation Panel-->
<H2>
<BR>
11.9.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-2139'><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-2140'><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, <code>0</code>, produces no debugging
output. A value of <code>1</code> produces a moderate amount of debugging
output, generally a single line per request or response. A value of
<code>2</code> 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-2141'><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 <code>'<var>yy</var><var>mm</var><var>dd</var>'</code> indicating the
date, and <var>time</var> should be a string of the form
<code>'<var>hh</var><var>mm</var><var>ss</var>'</code> indicating the time. Return a pair
<code>(<var>response</var>, <var>groups</var>)</code> 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-2142'><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
<code>'*'</code>, and <var>date</var> and <var>time</var> have the same meaning as for
<tt class="method">newgroups()</tt>. Return a pair <code>(<var>response</var>,
<var>articles</var>)</code> where <var>articles</var> is a list of article ids.
</dl>
<P>
<dl><dt><b><a name='l2h-2143'><tt class='method'>list</tt></a></b> ()
<dd>
Send a "<tt class="samp">LIST</tt>" command. Return a pair <code>(<var>response</var>,
<var>list</var>)</code> where <var>list</var> is a list of tuples. Each tuple has the
form <code>(<var>group</var>, <var>last</var>, <var>first</var>, <var>flag</var>)</code>, 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
<code>'y'</code> if posting is allowed, <code>'n'</code> if not, and <code>'m'</code> if
the newsgroup is moderated. (Note the ordering: <var>last</var>,
<var>first</var>.)
</dl>
<P>
<dl><dt><b><a name='l2h-2144'><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 <code>(<var>response</var>, <var>count</var>, <var>first</var>,
<var>last</var>, <var>name</var>)</code> 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-2145'><tt class='method'>help</tt></a></b> ()
<dd>
Send a "<tt class="samp">HELP</tt>" command. Return a pair <code>(<var>response</var>,
<var>list</var>)</code> where <var>list</var> is a list of help strings.
</dl>
<P>
<dl><dt><b><a name='l2h-2146'><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"><</tt>" and "<tt class="character">></tt>") or an article number (as a string).
Return a triple <code>(<var>response</var>, <var>number</var>, <var>id</var>)</code> where
<var>number</var> is the article number (as a string) and <var>id</var> is the
article id (enclosed in "<tt class="character"><</tt>" and "<tt class="character">></tt>").
</dl>
<P>
<dl><dt><b><a name='l2h-2147'><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-2148'><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-2149'><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
<code>(<var>response</var>, <var>number</var>, <var>id</var>, <var>list</var>)</code>
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-2150'><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-2151'><tt class='method'>article</tt></a></b> (<var>id</var>)
<dd>
Send an "<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-2152'><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-2153'><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. <code>'subject'</code>. The <var>string</var> argument should have
the form <code>'<var>first</var>-<var>last</var>'</code> where <var>first</var> and
<var>last</var> are the first and last article numbers to search. Return a
pair <code>(<var>response</var>, <var>list</var>)</code>, where <var>list</var> is a list of
pairs <code>(<var>id</var>, <var>text</var>)</code>, 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-2154'><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-2155'><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-2156'><tt class='method'>date</tt></a></b> ()
<dd>
Return a triple <code>(<var>response</var>, <var>date</var>, <var>time</var>)</code>,
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-2157'><tt class='method'>xgtitle</tt></a></b> (<var>name</var>)
<dd>
Process an "<tt class="samp">XGTITLE</tt>" command, returning a pair <code>(<var>response</var>,
<var>list</var>)</code>, where <var>list</var> is a list of tuples containing
<code>(<var>name</var>, <var>title</var>)</code>.
This is an optional NNTP extension, and may not be supported by all
servers.
</dl>
<P>
<dl><dt><b><a name='l2h-2158'><tt class='method'>xover</tt></a></b> (<var>start, end</var>)
<dd>
Return a pair <code>(<var>resp</var>, <var>list</var>)</code>. <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
<code>(<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>)</code>.
This is an optional NNTP extension, and may not be supported by all
servers.
</dl>
<P>
<dl><dt><b><a name='l2h-2159'><tt class='method'>xpath</tt></a></b> (<var>id</var>)
<dd>
Return a pair <code>(<var>resp</var>, <var>path</var>)</code>, 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-2160'><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>
<DIV CLASS="navigation"><p><hr><table align="center" width="100%" cellpadding="0" cellspacing="2">
<tr>
<td><A href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html"><img src="previous.gif" tppabs="http://www.python.org/doc/current/icons/previous.gif" border="0" height="32"
alt="Previous Page" width="32"></A></td>
<td><A href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html"><img src="up.gif" tppabs="http://www.python.org/doc/current/icons/up.gif" border="0" height="32"
alt="Up One Level" width="32"></A></td>
<td><A href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html"><img src="next.gif" tppabs="http://www.python.org/doc/current/icons/next.gif" border="0" height="32"
alt="Next Page" width="32"></A></td>
<td align="center" width="100%">Python Library Reference</td>
<td><A href="contents.html" tppabs="http://www.python.org/doc/current/lib/contents.html"><img src="contents.gif" tppabs="http://www.python.org/doc/current/icons/contents.gif" border="0" height="32"
alt="Contents" width="32"></A></td>
<td><a href="modindex.html" tppabs="http://www.python.org/doc/current/lib/modindex.html" title="Module Index"><img src="modules.gif" tppabs="http://www.python.org/doc/current/icons/modules.gif" border="0" height="32"
alt="Module Index" width="32"></a></td>
<td><A href="genindex.html" tppabs="http://www.python.org/doc/current/lib/genindex.html"><img src="index.gif" tppabs="http://www.python.org/doc/current/icons/index.gif" border="0" height="32"
alt="Index" width="32"></A></td>
</tr></table>
<b class="navlabel">Previous:</b> <a class="sectref" href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html">11.9 nntplib </A>
<b class="navlabel">Up:</b> <a class="sectref" href="module-nntplib.html" tppabs="http://www.python.org/doc/current/lib/module-nntplib.html">11.9 nntplib </A>
<b class="navlabel">Next:</b> <a class="sectref" href="module-smtplib.html" tppabs="http://www.python.org/doc/current/lib/module-smtplib.html">11.10 smtplib </A>
</DIV>
<!--End of Navigation Panel-->
<ADDRESS>
<hr>See <i><a href="about.html" tppabs="http://www.python.org/doc/current/lib/about.html">About this document...</a></i> for information on suggesting changes.
</ADDRESS>
</BODY>
</HTML>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -