Module nntplib :: Class NNTP
[hide private]
[frames] | no frames]

_ClassType NNTP

Instance Methods [hide private]
 
__init__(self, host, port=119, user=None, password=None, readermode=None, usenetrc=True)
Initialize an instance.
 
getwelcome(self)
Get the welcome message from the server (this is read and squirreled away by __init__()).
 
set_debuglevel(self, level)
Set the debugging level.
 
debug(self, level)
Set the debugging level.
 
putline(self, line)
Internal: send one line to the server, appending CRLF.
 
putcmd(self, line)
Internal: send one command to the server (through putline()).
 
getline(self)
Internal: return one line from the server, stripping CRLF.
 
getresp(self)
Internal: get a response from the server.
 
getlongresp(self, file=None)
Internal: get a response plus following text from the server.
 
shortcmd(self, line)
Internal: send a command and get the response.
 
longcmd(self, line, file=None)
Internal: send a command and get the response plus following text.
 
newgroups(self, date, time, file=None)
Process a NEWGROUPS command.
 
newnews(self, group, date, time, file=None)
Process a NEWNEWS command.
 
list(self, file=None)
Process a LIST command.
 
description(self, group)
Get a description for a single group.
 
descriptions(self, group_pattern)
Get descriptions for a range of groups.
 
group(self, name)
Process a GROUP command.
 
help(self, file=None)
Process a HELP command.
 
statparse(self, resp)
Internal: parse the response of a STAT, NEXT or LAST command.
 
statcmd(self, line)
Internal: process a STAT, NEXT or LAST command.
 
stat(self, id)
Process a STAT command.
 
next(self)
Process a NEXT command.
 
last(self)
Process a LAST command.
 
artcmd(self, line, file=None)
Internal: process a HEAD, BODY or ARTICLE command.
 
head(self, id)
Process a HEAD command.
 
body(self, id, file=None)
Process a BODY command.
 
article(self, id)
Process an ARTICLE command.
 
slave(self)
Process a SLAVE command.
 
xhdr(self, hdr, str, file=None)
Process an XHDR command (optional server extension).
 
xover(self, start, end, file=None)
Process an XOVER command (optional server extension) Arguments:
 
xgtitle(self, group, file=None)
Process an XGTITLE command (optional server extension) Arguments:
 
xpath(self, id)
Process an XPATH command (optional server extension) Arguments:
 
date(self)
Process the DATE command.
 
post(self, f)
Process a POST command.
 
ihave(self, id, f)
Process an IHAVE command.
 
quit(self)
Process a QUIT command and close the socket.
Method Details [hide private]

__init__(self, host, port=119, user=None, password=None, readermode=None, usenetrc=True)
(Constructor)

 

Initialize an instance. Arguments:

  • host: hostname to connect to
  • port: port to connect to (default the standard NNTP port)
  • user: username to authenticate with
  • password: password to use with username
  • readermode: if true, send 'mode reader' command after connecting.

readermode is sometimes necessary if you are connecting to an NNTP server on the local machine and intend to call reader-specific comamnds, such as `group'. If you get unexpected NNTPPermanentErrors, you might need to set readermode.

getwelcome(self)

 

Get the welcome message from the server (this is read and squirreled away by __init__()). If the response code is 200, posting is allowed; if it 201, posting is not allowed.

set_debuglevel(self, level)

 

Set the debugging level. Argument 'level' means: 0: no debugging output (default) 1: print commands and responses but not body text etc. 2: also print raw lines read and sent before stripping CR/LF

debug(self, level)

 

Set the debugging level. Argument 'level' means: 0: no debugging output (default) 1: print commands and responses but not body text etc. 2: also print raw lines read and sent before stripping CR/LF

getline(self)

 

Internal: return one line from the server, stripping CRLF. Raise EOFError if the connection is closed.

getresp(self)

 

Internal: get a response from the server. Raise various errors if the response indicates an error.

getlongresp(self, file=None)

 

Internal: get a response plus following text from the server. Raise various errors if the response indicates an error.

newgroups(self, date, time, file=None)

 

Process a NEWGROUPS command. Arguments:

  • date: string 'yymmdd' indicating the date
  • time: string 'hhmmss' indicating the time Return:
  • resp: server response if successful
  • list: list of newsgroup names

newnews(self, group, date, time, file=None)

 

Process a NEWNEWS command. Arguments:

  • group: group name or '*'
  • date: string 'yymmdd' indicating the date
  • time: string 'hhmmss' indicating the time Return:
  • resp: server response if successful
  • list: list of message ids

list(self, file=None)

 

Process a LIST command. Return:

  • resp: server response if successful
  • list: list of (group, last, first, flag) (strings)

description(self, group)

 

Get a description for a single group. If more than one group matches ('group' is a pattern), return the first. If no group matches, return an empty string.

This elides the response code from the server, since it can only be '215' or '285' (for xgtitle) anyway. If the response code is needed, use the 'descriptions' method.

NOTE: This neither checks for a wildcard in 'group' nor does it check whether the group actually exists.

group(self, name)

 

Process a GROUP command. Argument:

  • group: the group name Returns:
  • resp: server response if successful
  • count: number of articles (string)
  • first: first article number (string)
  • last: last article number (string)
  • name: the group name

help(self, file=None)

 

Process a HELP command. Returns:

  • resp: server response if successful
  • list: list of strings

stat(self, id)

 

Process a STAT command. Argument:

  • id: article number or message id Returns:
  • resp: server response if successful
  • nr: the article number
  • id: the message id

next(self)

 

Process a NEXT command. No arguments. Return as for STAT.

last(self)

 

Process a LAST command. No arguments. Return as for STAT.

head(self, id)

 

Process a HEAD command. Argument:

  • id: article number or message id Returns:
  • resp: server response if successful
  • nr: article number
  • id: message id
  • list: the lines of the article's header

body(self, id, file=None)

 

Process a BODY command. Argument:

  • id: article number or message id
  • file: Filename string or file object to store the article in Returns:
  • resp: server response if successful
  • nr: article number
  • id: message id
  • list: the lines of the article's body or an empty list if file was used

article(self, id)

 

Process an ARTICLE command. Argument:

  • id: article number or message id Returns:
  • resp: server response if successful
  • nr: article number
  • id: message id
  • list: the lines of the article

slave(self)

 

Process a SLAVE command. Returns:

  • resp: server response if successful

xhdr(self, hdr, str, file=None)

 

Process an XHDR command (optional server extension). Arguments:

  • hdr: the header type (e.g. 'subject')
  • str: an article nr, a message id, or a range nr1-nr2 Returns:
  • resp: server response if successful
  • list: list of (nr, value) strings

xover(self, start, end, file=None)

 

Process an XOVER command (optional server extension) Arguments:

  • start: start of range
  • end: end of range Returns:
  • resp: server response if successful
  • list: list of (art-nr, subject, poster, date, id, references, size, lines)

xgtitle(self, group, file=None)

 

Process an XGTITLE command (optional server extension) Arguments:

  • group: group name wildcard (i.e. news.*) Returns:
  • resp: server response if successful
  • list: list of (name,title) strings

xpath(self, id)

 

Process an XPATH command (optional server extension) Arguments:

  • id: Message id of article Returns: resp: server response if successful path: directory path to article

date(self)

 

Process the DATE command. Arguments: None Returns: resp: server response if successful date: Date suitable for newnews/newgroups commands etc. time: Time suitable for newnews/newgroups commands etc.

post(self, f)

 

Process a POST command. Arguments:

  • f: file containing the article Returns:
  • resp: server response if successful

ihave(self, id, f)

 

Process an IHAVE command. Arguments:

  • id: message-id of the article
  • f: file containing the article Returns:
  • resp: server response if successful Note that if the server refuses the article an exception is raised.

quit(self)

 

Process a QUIT command and close the socket. Returns:

  • resp: server response if successful