NNTP Objects -- Python library reference



Prev: nntplib Up: nntplib Top: Top

11.6.1. NNTP Objects

NNTP instances have the following methods. The response 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.

getwelcome () -- Method on NNTP object
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.)
set_debuglevel (level) -- Method on NNTP object
Set the instance's debugging level. This controls the amount of debugging output printed. The default, 0, produces no debugging output. A value of 1 produces a moderate amount of debugging output, generally a single line per request or response. A value of 2 or higher produces the maximum amount of debugging output, logging each line sent and received on the connection (including message text).
newgroups (date, time) -- Method on NNTP object
Send a `NEWGROUPS' command. The date argument should be a string of the form "yymmdd" indicating the date, and time should be a string of the form "hhmmss" indicating the time. Return a pair (response, groups) where groups is a list of group names that are new since the given date and time.
newnews (group, date, time) -- Method on NNTP object
Send a `NEWNEWS' command. Here, group is a group name or "*", and date and time have the same meaning as for newgroups(). Return a pair (response, articles) where articles is a list of article ids.
list () -- Method on NNTP object
Send a `LIST' command. Return a pair (response, list) where list is a list of tuples. Each tuple has the form (group, last, first, flag), where group is a group name, last and first are the last and first article numbers (as strings), and flag is 'y' if posting is allowed, 'n' if not, and 'm' if the newsgroup is moderated. (Note the ordering: last, first.)
group (name) -- Method on NNTP object
Send a `GROUP' command, where name is the group name. Return a tuple (response, count, first, last, name) where count is the (estimated) number of articles in the group, first is the first article number in the group, last is the last article number in the group, and name is the group name. The numbers are returned as strings.
help () -- Method on NNTP object
Send a `HELP' command. Return a pair (response, list) where list is a list of help strings.
stat (id) -- Method on NNTP object
Send a `STAT' command, where id is the message id (enclosed in `<' and `>') or an article number (as a string). Return a triple (varresponse, number, id) where number is the article number (as a string) and id is the article id (enclosed in `<' and `>').
next () -- Method on NNTP object
Send a `NEXT' command. Return as for stat().
last () -- Method on NNTP object
Send a `LAST' command. Return as for stat().
head (id) -- Method on NNTP object
Send a `HEAD' command, where id has the same meaning as for stat(). Return a pair (response, list) where list is a list of the article's headers (an uninterpreted list of lines, without trailing newlines).
body (id) -- Method on NNTP object
Send a `BODY' command, where id has the same meaning as for stat(). Return a pair (response, list) where list is a list of the article's body text (an uninterpreted list of lines, without trailing newlines).
article (id) -- Method on NNTP object
Send a `ARTICLE' command, where id has the same meaning as for stat(). Return a pair (response, list) where list is a list of the article's header and body text (an uninterpreted list of lines, without trailing newlines).
slave () -- Method on NNTP object
Send a `SLAVE' command. Return the server's response.
xhdr (header, string) -- Method on NNTP object
Send an `XHDR' command. This command is not defined in the RFC but is a common extension. The header argument is a header keyword, e.g. "subject". The string argument should have the form "first-last" where first and last are the first and last article numbers to search. Return a pair (response, list), where list is a list of pairs (id, text), where id is an article id (as a string) and text is the text of the requested header for that article.
post (file) -- Method on NNTP object
Post an article using the `POST' command. The file argument is an open file object which is read until EOF using its readline() method. It should be a well-formed news article, including the required headers. The post() method automatically escapes lines beginning with `.'.
ihave (id, file) -- Method on NNTP object
Send an `IHAVE' command. If the response is not an error, treat file exactly as for the post() method.
quit () -- Method on NNTP object
Send a `QUIT' command and close the connection. Once this method has been called, no other methods of the NNTP object should be called.


Prev: nntplib Up: nntplib Top: Top