Back to index

python3.2  3.2.2
Public Member Functions | Public Attributes | Static Public Attributes | Private Member Functions | Private Attributes
nntplib._NNTPBase Class Reference
Inheritance diagram for nntplib._NNTPBase:
Inheritance graph
[legend]
Collaboration diagram for nntplib._NNTPBase:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getwelcome
def getcapabilities
def set_debuglevel
def capabilities
def newgroups
def newnews
def list
def description
def descriptions
def group
def help
def stat
def next
def last
def head
def body
def article
def slave
def xhdr
def xover
def over
def xgtitle
def xpath
def date
def post
def ihave
def quit
def login
def starttls

Public Attributes

 host
 file
 debugging
 welcome
 readermode_afterauth
 tls_on
 authenticated
 nntp_version
 nntp_implementation
 sock

Static Public Attributes

string encoding = 'utf-8'
string errors = 'surrogateescape'
 debug = set_debuglevel

Private Member Functions

def _putline
def _putcmd
def _getline
def _getresp
def _getlongresp
def _shortcmd
def _longcmd
def _longcmdstring
def _getoverviewfmt
def _grouplist
def _getdescriptions
def _statparse
def _statcmd
def _artcmd
def _post
def _close
def _setreadermode

Private Attributes

 _caps
 _cachedoverviewfmt

Detailed Description

Definition at line 291 of file nntplib.py.


Constructor & Destructor Documentation

def nntplib._NNTPBase.__init__ (   self,
  file,
  host,
  readermode = None,
  timeout = _GLOBAL_DEFAULT_TIMEOUT 
)
Initialize an instance.  Arguments:
- file: file-like object (open for read/write in binary mode)
- host: hostname of the server
- readermode: if true, send 'mode reader' command after
      connecting.
- timeout: timeout (in seconds) used for socket connections

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

Definition at line 308 of file nntplib.py.

00308 
00309                  readermode=None, timeout=_GLOBAL_DEFAULT_TIMEOUT):
00310         """Initialize an instance.  Arguments:
00311         - file: file-like object (open for read/write in binary mode)
00312         - host: hostname of the server
00313         - readermode: if true, send 'mode reader' command after
00314                       connecting.
00315         - timeout: timeout (in seconds) used for socket connections
00316 
00317         readermode is sometimes necessary if you are connecting to an
00318         NNTP server on the local machine and intend to call
00319         reader-specific commands, such as `group'.  If you get
00320         unexpected NNTPPermanentErrors, you might need to set
00321         readermode.
00322         """
00323         self.host = host
00324         self.file = file
00325         self.debugging = 0
00326         self.welcome = self._getresp()
00327 
00328         # 'MODE READER' is sometimes necessary to enable 'reader' mode.
00329         # However, the order in which 'MODE READER' and 'AUTHINFO' need to
00330         # arrive differs between some NNTP servers. If _setreadermode() fails
00331         # with an authorization failed error, it will set this to True;
00332         # the login() routine will interpret that as a request to try again
00333         # after performing its normal function.
00334         self.readermode_afterauth = False
00335         if readermode:
00336             self._setreadermode()
00337 
00338         # RFC 4642 2.2.2: Both the client and the server MUST know if there is
00339         # a TLS session active.  A client MUST NOT attempt to start a TLS
00340         # session if a TLS session is already active.
00341         self.tls_on = False
00342 
00343         # Inquire about capabilities (RFC 3977).
00344         self._caps = None
00345         self.getcapabilities()
00346 
00347         # Log in and encryption setup order is left to subclasses.
00348         self.authenticated = False

Here is the caller graph for this function:


Member Function Documentation

def nntplib._NNTPBase._artcmd (   self,
  line,
  file = None 
) [private]
Internal: process a HEAD, BODY or ARTICLE command.

Definition at line 698 of file nntplib.py.

00698 
00699     def _artcmd(self, line, file=None):
00700         """Internal: process a HEAD, BODY or ARTICLE command."""
00701         resp, lines = self._longcmd(line, file)
00702         resp, art_num, message_id = self._statparse(resp)
00703         return resp, ArticleInfo(art_num, message_id, lines)

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._close (   self) [private]

Reimplemented in nntplib.NNTP_SSL, and nntplib.NNTP.

Definition at line 901 of file nntplib.py.

00901 
00902     def _close(self):
00903         self.file.close()
00904         del self.file

Here is the caller graph for this function:

def nntplib._NNTPBase._getdescriptions (   self,
  group_pattern,
  return_all 
) [private]

Definition at line 585 of file nntplib.py.

00585 
00586     def _getdescriptions(self, group_pattern, return_all):
00587         line_pat = re.compile('^(?P<group>[^ \t]+)[ \t]+(.*)$')
00588         # Try the more std (acc. to RFC2980) LIST NEWSGROUPS first
00589         resp, lines = self._longcmdstring('LIST NEWSGROUPS ' + group_pattern)
00590         if not resp.startswith('215'):
00591             # Now the deprecated XGTITLE.  This either raises an error
00592             # or succeeds with the same output structure as LIST
00593             # NEWSGROUPS.
00594             resp, lines = self._longcmdstring('XGTITLE ' + group_pattern)
00595         groups = {}
00596         for raw_line in lines:
00597             match = line_pat.search(raw_line.strip())
00598             if match:
00599                 name, desc = match.group(1, 2)
00600                 if not return_all:
00601                     return desc
00602                 groups[name] = desc
00603         if return_all:
00604             return resp, groups
00605         else:
00606             # Nothing found
00607             return ''

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._getline (   self,
  strip_crlf = True 
) [private]
Internal: return one line from the server, stripping _CRLF.
Raise EOFError if the connection is closed.
Returns a bytes object.

Definition at line 404 of file nntplib.py.

00404 
00405     def _getline(self, strip_crlf=True):
00406         """Internal: return one line from the server, stripping _CRLF.
00407         Raise EOFError if the connection is closed.
00408         Returns a bytes object."""
00409         line = self.file.readline()
00410         if self.debugging > 1:
00411             print('*get*', repr(line))
00412         if not line: raise EOFError
00413         if strip_crlf:
00414             if line[-2:] == _CRLF:
00415                 line = line[:-2]
00416             elif line[-1:] in _CRLF:
00417                 line = line[:-1]
00418         return line

Here is the caller graph for this function:

def nntplib._NNTPBase._getlongresp (   self,
  file = None 
) [private]
Internal: get a response plus following text from the server.
Raise various errors if the response indicates an error.

Returns a (response, lines) tuple where `response` is an unicode
string and `lines` is a list of bytes objects.
If `file` is a file-like object, it must be open in binary mode.

Definition at line 435 of file nntplib.py.

00435 
00436     def _getlongresp(self, file=None):
00437         """Internal: get a response plus following text from the server.
00438         Raise various errors if the response indicates an error.
00439 
00440         Returns a (response, lines) tuple where `response` is an unicode
00441         string and `lines` is a list of bytes objects.
00442         If `file` is a file-like object, it must be open in binary mode.
00443         """
00444 
00445         openedFile = None
00446         try:
00447             # If a string was passed then open a file with that name
00448             if isinstance(file, (str, bytes)):
00449                 openedFile = file = open(file, "wb")
00450 
00451             resp = self._getresp()
00452             if resp[:3] not in _LONGRESP:
00453                 raise NNTPReplyError(resp)
00454 
00455             lines = []
00456             if file is not None:
00457                 # XXX lines = None instead?
00458                 terminators = (b'.' + _CRLF, b'.\n')
00459                 while 1:
00460                     line = self._getline(False)
00461                     if line in terminators:
00462                         break
00463                     if line.startswith(b'..'):
00464                         line = line[1:]
00465                     file.write(line)
00466             else:
00467                 terminator = b'.'
00468                 while 1:
00469                     line = self._getline()
00470                     if line == terminator:
00471                         break
00472                     if line.startswith(b'..'):
00473                         line = line[1:]
00474                     lines.append(line)
00475         finally:
00476             # If this method created the file, then it must close it
00477             if openedFile:
00478                 openedFile.close()
00479 
00480         return resp, lines

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._getoverviewfmt (   self) [private]
Internal: get the overview format. Queries the server if not
already done, else returns the cached value.

Definition at line 503 of file nntplib.py.

00503 
00504     def _getoverviewfmt(self):
00505         """Internal: get the overview format. Queries the server if not
00506         already done, else returns the cached value."""
00507         try:
00508             return self._cachedoverviewfmt
00509         except AttributeError:
00510             pass
00511         try:
00512             resp, lines = self._longcmdstring("LIST OVERVIEW.FMT")
00513         except NNTPPermanentError:
00514             # Not supported by server?
00515             fmt = _DEFAULT_OVERVIEW_FMT[:]
00516         else:
00517             fmt = _parse_overview_fmt(lines)
00518         self._cachedoverviewfmt = fmt
00519         return fmt

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._getresp (   self) [private]
Internal: get a response from the server.
Raise various errors if the response indicates an error.
Returns an unicode string.

Definition at line 419 of file nntplib.py.

00419 
00420     def _getresp(self):
00421         """Internal: get a response from the server.
00422         Raise various errors if the response indicates an error.
00423         Returns an unicode string."""
00424         resp = self._getline()
00425         if self.debugging: print('*resp*', repr(resp))
00426         resp = resp.decode(self.encoding, self.errors)
00427         c = resp[:1]
00428         if c == '4':
00429             raise NNTPTemporaryError(resp)
00430         if c == '5':
00431             raise NNTPPermanentError(resp)
00432         if c not in '123':
00433             raise NNTPProtocolError(resp)
00434         return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._grouplist (   self,
  lines 
) [private]

Definition at line 520 of file nntplib.py.

00520 
00521     def _grouplist(self, lines):
00522         # Parse lines into "group last first flag"
00523         return [GroupInfo(*line.split()) for line in lines]

Here is the caller graph for this function:

def nntplib._NNTPBase._longcmd (   self,
  line,
  file = None 
) [private]
Internal: send a command and get the response plus following text.
Same return value as _getlongresp().

Definition at line 487 of file nntplib.py.

00487 
00488     def _longcmd(self, line, file=None):
00489         """Internal: send a command and get the response plus following text.
00490         Same return value as _getlongresp()."""
00491         self._putcmd(line)
00492         return self._getlongresp(file)

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._longcmdstring (   self,
  line,
  file = None 
) [private]
Internal: send a command and get the response plus following text.
Same as _longcmd() and _getlongresp(), except that the returned `lines`
are unicode strings rather than bytes objects.

Definition at line 493 of file nntplib.py.

00493 
00494     def _longcmdstring(self, line, file=None):
00495         """Internal: send a command and get the response plus following text.
00496         Same as _longcmd() and _getlongresp(), except that the returned `lines`
00497         are unicode strings rather than bytes objects.
00498         """
00499         self._putcmd(line)
00500         resp, list = self._getlongresp(file)
00501         return resp, [line.decode(self.encoding, self.errors)
00502                       for line in list]

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._post (   self,
  command,
  f 
) [private]

Definition at line 864 of file nntplib.py.

00864 
00865     def _post(self, command, f):
00866         resp = self._shortcmd(command)
00867         # Raises a specific exception if posting is not allowed
00868         if not resp.startswith('3'):
00869             raise NNTPReplyError(resp)
00870         if isinstance(f, (bytes, bytearray)):
00871             f = f.splitlines()
00872         # We don't use _putline() because:
00873         # - we don't want additional CRLF if the file or iterable is already
00874         #   in the right format
00875         # - we don't want a spurious flush() after each line is written
00876         for line in f:
00877             if not line.endswith(_CRLF):
00878                 line = line.rstrip(b"\r\n") + _CRLF
00879             if line.startswith(b'.'):
00880                 line = b'.' + line
00881             self.file.write(line)
00882         self.file.write(b".\r\n")
00883         self.file.flush()
00884         return self._getresp()

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._putcmd (   self,
  line 
) [private]
Internal: send one command to the server (through _putline()).
The `line` must be an unicode string.

Definition at line 397 of file nntplib.py.

00397 
00398     def _putcmd(self, line):
00399         """Internal: send one command to the server (through _putline()).
00400         The `line` must be an unicode string."""
00401         if self.debugging: print('*cmd*', repr(line))
00402         line = line.encode(self.encoding, self.errors)
00403         self._putline(line)

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._putline (   self,
  line 
) [private]
Internal: send one line to the server, appending CRLF.
The `line` must be a bytes-like object.

Definition at line 389 of file nntplib.py.

00389 
00390     def _putline(self, line):
00391         """Internal: send one line to the server, appending CRLF.
00392         The `line` must be a bytes-like object."""
00393         line = line + _CRLF
00394         if self.debugging > 1: print('*put*', repr(line))
00395         self.file.write(line)
00396         self.file.flush()

Here is the caller graph for this function:

def nntplib._NNTPBase._setreadermode (   self) [private]

Definition at line 948 of file nntplib.py.

00948 
00949     def _setreadermode(self):
00950         try:
00951             self.welcome = self._shortcmd('mode reader')
00952         except NNTPPermanentError:
00953             # Error 5xx, probably 'not implemented'
00954             pass
00955         except NNTPTemporaryError as e:
00956             if e.response.startswith('480'):
00957                 # Need authorization before 'mode reader'
00958                 self.readermode_afterauth = True
00959             else:
00960                 raise

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._shortcmd (   self,
  line 
) [private]
Internal: send a command and get the response.
Same return value as _getresp().

Definition at line 481 of file nntplib.py.

00481 
00482     def _shortcmd(self, line):
00483         """Internal: send a command and get the response.
00484         Same return value as _getresp()."""
00485         self._putcmd(line)
00486         return self._getresp()

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._statcmd (   self,
  line 
) [private]
Internal: process a STAT, NEXT or LAST command.

Definition at line 671 of file nntplib.py.

00671 
00672     def _statcmd(self, line):
00673         """Internal: process a STAT, NEXT or LAST command."""
00674         resp = self._shortcmd(line)
00675         return self._statparse(resp)

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase._statparse (   self,
  resp 
) [private]
Internal: parse the response line of a STAT, NEXT, LAST,
ARTICLE, HEAD or BODY command.

Definition at line 661 of file nntplib.py.

00661 
00662     def _statparse(self, resp):
00663         """Internal: parse the response line of a STAT, NEXT, LAST,
00664         ARTICLE, HEAD or BODY command."""
00665         if not resp.startswith('22'):
00666             raise NNTPReplyError(resp)
00667         words = resp.split()
00668         art_num = int(words[1])
00669         message_id = words[2]
00670         return resp, art_num, message_id

Here is the caller graph for this function:

def nntplib._NNTPBase.article (   self,
  message_spec = None,
  file = None 
)
Process an ARTICLE command.  Argument:
- message_spec: article number or message id
- file: filename string or file object to store the article in
Returns:
- resp: server response if successful
- ArticleInfo: (article number, message id, list of article lines)

Definition at line 732 of file nntplib.py.

00732 
00733     def article(self, message_spec=None, *, file=None):
00734         """Process an ARTICLE command.  Argument:
00735         - message_spec: article number or message id
00736         - file: filename string or file object to store the article in
00737         Returns:
00738         - resp: server response if successful
00739         - ArticleInfo: (article number, message id, list of article lines)
00740         """
00741         if message_spec is not None:
00742             cmd = 'ARTICLE {0}'.format(message_spec)
00743         else:
00744             cmd = 'ARTICLE'
00745         return self._artcmd(cmd, file)

Here is the call graph for this function:

def nntplib._NNTPBase.body (   self,
  message_spec = None,
  file = None 
)
Process a BODY command.  Argument:
- message_spec: article number or message id
- file: filename string or file object to store the body in
Returns:
- resp: server response if successful
- ArticleInfo: (article number, message id, list of body lines)

Definition at line 718 of file nntplib.py.

00718 
00719     def body(self, message_spec=None, *, file=None):
00720         """Process a BODY command.  Argument:
00721         - message_spec: article number or message id
00722         - file: filename string or file object to store the body in
00723         Returns:
00724         - resp: server response if successful
00725         - ArticleInfo: (article number, message id, list of body lines)
00726         """
00727         if message_spec is not None:
00728             cmd = 'BODY {0}'.format(message_spec)
00729         else:
00730             cmd = 'BODY'
00731         return self._artcmd(cmd, file)

Here is the call graph for this function:

Process a CAPABILITIES command.  Not supported by all servers.
Return:
- resp: server response if successful
- caps: a dictionary mapping capability names to lists of tokens
(for example {'VERSION': ['2'], 'OVER': [], LIST: ['ACTIVE', 'HEADERS'] })

Definition at line 524 of file nntplib.py.

00524 
00525     def capabilities(self):
00526         """Process a CAPABILITIES command.  Not supported by all servers.
00527         Return:
00528         - resp: server response if successful
00529         - caps: a dictionary mapping capability names to lists of tokens
00530         (for example {'VERSION': ['2'], 'OVER': [], LIST: ['ACTIVE', 'HEADERS'] })
00531         """
00532         caps = {}
00533         resp, lines = self._longcmdstring("CAPABILITIES")
00534         for line in lines:
00535             name, *tokens = line.split()
00536             caps[name] = tokens
00537         return resp, caps

Here is the call graph for this function:

def nntplib._NNTPBase.date (   self)
Process the DATE command.
Returns:
- resp: server response if successful
- date: datetime object

Definition at line 847 of file nntplib.py.

00847 
00848     def date(self):
00849         """Process the DATE command.
00850         Returns:
00851         - resp: server response if successful
00852         - date: datetime object
00853         """
00854         resp = self._shortcmd("DATE")
00855         if not resp.startswith('111'):
00856             raise NNTPReplyError(resp)
00857         elem = resp.split()
00858         if len(elem) != 2:
00859             raise NNTPDataError(resp)
00860         date = elem[1]
00861         if len(date) != 14:
00862             raise NNTPDataError(resp)
00863         return resp, _parse_datetime(date, None)

Here is the call graph for this function:

def nntplib._NNTPBase.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.

Definition at line 608 of file nntplib.py.

00608 
00609     def description(self, group):
00610         """Get a description for a single group.  If more than one
00611         group matches ('group' is a pattern), return the first.  If no
00612         group matches, return an empty string.
00613 
00614         This elides the response code from the server, since it can
00615         only be '215' or '285' (for xgtitle) anyway.  If the response
00616         code is needed, use the 'descriptions' method.
00617 
00618         NOTE: This neither checks for a wildcard in 'group' nor does
00619         it check whether the group actually exists."""
00620         return self._getdescriptions(group, False)

Here is the call graph for this function:

def nntplib._NNTPBase.descriptions (   self,
  group_pattern 
)
Get descriptions for a range of groups.

Definition at line 621 of file nntplib.py.

00621 
00622     def descriptions(self, group_pattern):
00623         """Get descriptions for a range of groups."""
00624         return self._getdescriptions(group_pattern, True)

Here is the call graph for this function:

Get the server capabilities, as read by __init__().
If the CAPABILITIES command is not supported, an empty dict is
returned.

Definition at line 358 of file nntplib.py.

00358 
00359     def getcapabilities(self):
00360         """Get the server capabilities, as read by __init__().
00361         If the CAPABILITIES command is not supported, an empty dict is
00362         returned."""
00363         if self._caps is None:
00364             self.nntp_version = 1
00365             self.nntp_implementation = None
00366             try:
00367                 resp, caps = self.capabilities()
00368             except NNTPPermanentError:
00369                 # Server doesn't support capabilities
00370                 self._caps = {}
00371             else:
00372                 self._caps = caps
00373                 if 'VERSION' in caps:
00374                     # The server can advertise several supported versions,
00375                     # choose the highest.
00376                     self.nntp_version = max(map(int, caps['VERSION']))
00377                 if 'IMPLEMENTATION' in caps:
00378                     self.nntp_implementation = ' '.join(caps['IMPLEMENTATION'])
00379         return self._caps

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.

Definition at line 349 of file nntplib.py.

00349 
00350     def getwelcome(self):
00351         """Get the welcome message from the server
00352         (this is read and squirreled away by __init__()).
00353         If the response code is 200, posting is allowed;
00354         if it 201, posting is not allowed."""
00355 
00356         if self.debugging: print('*welcome*', repr(self.welcome))
00357         return self.welcome

def nntplib._NNTPBase.group (   self,
  name 
)
Process a GROUP command.  Argument:
- group: the group name
Returns:
- resp: server response if successful
- count: number of articles
- first: first article number
- last: last article number
- name: the group name

Definition at line 625 of file nntplib.py.

00625 
00626     def group(self, name):
00627         """Process a GROUP command.  Argument:
00628         - group: the group name
00629         Returns:
00630         - resp: server response if successful
00631         - count: number of articles
00632         - first: first article number
00633         - last: last article number
00634         - name: the group name
00635         """
00636         resp = self._shortcmd('GROUP ' + name)
00637         if not resp.startswith('211'):
00638             raise NNTPReplyError(resp)
00639         words = resp.split()
00640         count = first = last = 0
00641         n = len(words)
00642         if n > 1:
00643             count = words[1]
00644             if n > 2:
00645                 first = words[2]
00646                 if n > 3:
00647                     last = words[3]
00648                     if n > 4:
00649                         name = words[4].lower()
00650         return resp, int(count), int(first), int(last), name

Here is the call graph for this function:

def nntplib._NNTPBase.head (   self,
  message_spec = None,
  file = None 
)
Process a HEAD command.  Argument:
- message_spec: article number or message id
- file: filename string or file object to store the headers in
Returns:
- resp: server response if successful
- ArticleInfo: (article number, message id, list of header lines)

Definition at line 704 of file nntplib.py.

00704 
00705     def head(self, message_spec=None, *, file=None):
00706         """Process a HEAD command.  Argument:
00707         - message_spec: article number or message id
00708         - file: filename string or file object to store the headers in
00709         Returns:
00710         - resp: server response if successful
00711         - ArticleInfo: (article number, message id, list of header lines)
00712         """
00713         if message_spec is not None:
00714             cmd = 'HEAD {0}'.format(message_spec)
00715         else:
00716             cmd = 'HEAD'
00717         return self._artcmd(cmd, file)

Here is the call graph for this function:

def nntplib._NNTPBase.help (   self,
  file = None 
)
Process a HELP command. Argument:
- file: Filename string or file object to store the result in
Returns:
- resp: server response if successful
- list: list of strings returned by the server in response to the
HELP command

Definition at line 651 of file nntplib.py.

00651 
00652     def help(self, *, file=None):
00653         """Process a HELP command. Argument:
00654         - file: Filename string or file object to store the result in
00655         Returns:
00656         - resp: server response if successful
00657         - list: list of strings returned by the server in response to the
00658                 HELP command
00659         """
00660         return self._longcmdstring('HELP', file)

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase.ihave (   self,
  message_id,
  data 
)
Process an IHAVE command.  Arguments:
- message_id: message-id of the article
- data: file containing the article
Returns:
- resp: server response if successful
Note that if the server refuses the article an exception is raised.

Definition at line 892 of file nntplib.py.

00892 
00893     def ihave(self, message_id, data):
00894         """Process an IHAVE command.  Arguments:
00895         - message_id: message-id of the article
00896         - data: file containing the article
00897         Returns:
00898         - resp: server response if successful
00899         Note that if the server refuses the article an exception is raised."""
00900         return self._post('IHAVE {0}'.format(message_id), data)

Here is the call graph for this function:

def nntplib._NNTPBase.last (   self)
Process a LAST command.  No arguments.  Return as for STAT.

Definition at line 694 of file nntplib.py.

00694 
00695     def last(self):
00696         """Process a LAST command.  No arguments.  Return as for STAT."""
00697         return self._statcmd('LAST')

Here is the call graph for this function:

def nntplib._NNTPBase.list (   self,
  group_pattern = None,
  file = None 
)
Process a LIST or LIST ACTIVE command. Arguments:
- group_pattern: a pattern indicating which groups to query
- file: Filename string or file object to store the result in
Returns:
- resp: server response if successful
- list: list of (group, last, first, flag) (strings)

Definition at line 570 of file nntplib.py.

00570 
00571     def list(self, group_pattern=None, *, file=None):
00572         """Process a LIST or LIST ACTIVE command. Arguments:
00573         - group_pattern: a pattern indicating which groups to query
00574         - file: Filename string or file object to store the result in
00575         Returns:
00576         - resp: server response if successful
00577         - list: list of (group, last, first, flag) (strings)
00578         """
00579         if group_pattern is not None:
00580             command = 'LIST ACTIVE ' + group_pattern
00581         else:
00582             command = 'LIST'
00583         resp, lines = self._longcmdstring(command, file)
00584         return resp, self._grouplist(lines)

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase.login (   self,
  user = None,
  password = None,
  usenetrc = True 
)

Definition at line 914 of file nntplib.py.

00914 
00915     def login(self, user=None, password=None, usenetrc=True):
00916         if self.authenticated:
00917             raise ValueError("Already logged in.")
00918         if not user and not usenetrc:
00919             raise ValueError(
00920                 "At least one of `user` and `usenetrc` must be specified")
00921         # If no login/password was specified but netrc was requested,
00922         # try to get them from ~/.netrc
00923         # Presume that if .netrc has an entry, NNRP authentication is required.
00924         try:
00925             if usenetrc and not user:
00926                 import netrc
00927                 credentials = netrc.netrc()
00928                 auth = credentials.authenticators(self.host)
00929                 if auth:
00930                     user = auth[0]
00931                     password = auth[2]
00932         except IOError:
00933             pass
00934         # Perform NNTP authentication if needed.
00935         if not user:
00936             return
00937         resp = self._shortcmd('authinfo user ' + user)
00938         if resp.startswith('381'):
00939             if not password:
00940                 raise NNTPReplyError(resp)
00941             else:
00942                 resp = self._shortcmd('authinfo pass ' + password)
00943                 if not resp.startswith('281'):
00944                     raise NNTPPermanentError(resp)
00945         # Attempt to send mode reader if it was requested after login.
00946         if self.readermode_afterauth:
00947             self._setreadermode()

Here is the call graph for this function:

def nntplib._NNTPBase.newgroups (   self,
  date,
  file = None 
)
Process a NEWGROUPS command.  Arguments:
- date: a date or datetime object
Return:
- resp: server response if successful
- list: list of newsgroup names

Definition at line 538 of file nntplib.py.

00538 
00539     def newgroups(self, date, *, file=None):
00540         """Process a NEWGROUPS command.  Arguments:
00541         - date: a date or datetime object
00542         Return:
00543         - resp: server response if successful
00544         - list: list of newsgroup names
00545         """
00546         if not isinstance(date, (datetime.date, datetime.date)):
00547             raise TypeError(
00548                 "the date parameter must be a date or datetime object, "
00549                 "not '{:40}'".format(date.__class__.__name__))
00550         date_str, time_str = _unparse_datetime(date, self.nntp_version < 2)
00551         cmd = 'NEWGROUPS {0} {1}'.format(date_str, time_str)
00552         resp, lines = self._longcmdstring(cmd, file)
00553         return resp, self._grouplist(lines)

Here is the call graph for this function:

def nntplib._NNTPBase.newnews (   self,
  group,
  date,
  file = None 
)
Process a NEWNEWS command.  Arguments:
- group: group name or '*'
- date: a date or datetime object
Return:
- resp: server response if successful
- list: list of message ids

Definition at line 554 of file nntplib.py.

00554 
00555     def newnews(self, group, date, *, file=None):
00556         """Process a NEWNEWS command.  Arguments:
00557         - group: group name or '*'
00558         - date: a date or datetime object
00559         Return:
00560         - resp: server response if successful
00561         - list: list of message ids
00562         """
00563         if not isinstance(date, (datetime.date, datetime.date)):
00564             raise TypeError(
00565                 "the date parameter must be a date or datetime object, "
00566                 "not '{:40}'".format(date.__class__.__name__))
00567         date_str, time_str = _unparse_datetime(date, self.nntp_version < 2)
00568         cmd = 'NEWNEWS {0} {1} {2}'.format(group, date_str, time_str)
00569         return self._longcmdstring(cmd, file)

Here is the call graph for this function:

def nntplib._NNTPBase.next (   self)
Process a NEXT command.  No arguments.  Return as for STAT.

Definition at line 690 of file nntplib.py.

00690 
00691     def next(self):
00692         """Process a NEXT command.  No arguments.  Return as for STAT."""
00693         return self._statcmd('NEXT')

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase.over (   self,
  message_spec,
  file = None 
)
Process an OVER command.  If the command isn't supported, fall
back to XOVER. Arguments:
- message_spec:
    - either a message id, indicating the article to fetch
      information about
    - or a (start, end) tuple, indicating a range of article numbers;
      if end is None, information up to the newest message will be
      retrieved
    - or None, indicating the current article number must be used
- file: Filename string or file object to store the result in
Returns:
- resp: server response if successful
- list: list of dicts containing the response fields

NOTE: the "message id" form isn't supported by XOVER

Definition at line 782 of file nntplib.py.

00782 
00783     def over(self, message_spec, *, file=None):
00784         """Process an OVER command.  If the command isn't supported, fall
00785         back to XOVER. Arguments:
00786         - message_spec:
00787             - either a message id, indicating the article to fetch
00788               information about
00789             - or a (start, end) tuple, indicating a range of article numbers;
00790               if end is None, information up to the newest message will be
00791               retrieved
00792             - or None, indicating the current article number must be used
00793         - file: Filename string or file object to store the result in
00794         Returns:
00795         - resp: server response if successful
00796         - list: list of dicts containing the response fields
00797 
00798         NOTE: the "message id" form isn't supported by XOVER
00799         """
00800         cmd = 'OVER' if 'OVER' in self._caps else 'XOVER'
00801         if isinstance(message_spec, (tuple, list)):
00802             start, end = message_spec
00803             cmd += ' {0}-{1}'.format(start, end or '')
00804         elif message_spec is not None:
00805             cmd = cmd + ' ' + message_spec
00806         resp, lines = self._longcmdstring(cmd, file)
00807         fmt = self._getoverviewfmt()
00808         return resp, _parse_overview(lines, fmt)

Here is the call graph for this function:

def nntplib._NNTPBase.post (   self,
  data 
)
Process a POST command.  Arguments:
- data: bytes object, iterable or file containing the article
Returns:
- resp: server response if successful

Definition at line 885 of file nntplib.py.

00885 
00886     def post(self, data):
00887         """Process a POST command.  Arguments:
00888         - data: bytes object, iterable or file containing the article
00889         Returns:
00890         - resp: server response if successful"""
00891         return self._post('POST', data)

Here is the call graph for this function:

def nntplib._NNTPBase.quit (   self)
Process a QUIT command and close the socket.  Returns:
- resp: server response if successful

Definition at line 905 of file nntplib.py.

00905 
00906     def quit(self):
00907         """Process a QUIT command and close the socket.  Returns:
00908         - resp: server response if successful"""
00909         try:
00910             resp = self._shortcmd('QUIT')
00911         finally:
00912             self._close()
00913         return resp

Here is the call graph for this function:

Here is the caller graph for this function:

def nntplib._NNTPBase.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

Definition at line 380 of file nntplib.py.

00380 
00381     def set_debuglevel(self, level):
00382         """Set the debugging level.  Argument 'level' means:
00383         0: no debugging output (default)
00384         1: print commands and responses but not body text etc.
00385         2: also print raw lines read and sent before stripping CR/LF"""
00386 
        self.debugging = level
def nntplib._NNTPBase.slave (   self)
Process a SLAVE command.  Returns:
- resp: server response if successful

Definition at line 746 of file nntplib.py.

00746 
00747     def slave(self):
00748         """Process a SLAVE command.  Returns:
00749         - resp: server response if successful
00750         """
00751         return self._shortcmd('SLAVE')

Here is the call graph for this function:

def nntplib._NNTPBase.starttls (   self,
  context = None 
)
Process a STARTTLS command. Arguments:
- context: SSL context to use for the encrypted connection

Definition at line 962 of file nntplib.py.

00962 
00963         def starttls(self, context=None):
00964             """Process a STARTTLS command. Arguments:
00965             - context: SSL context to use for the encrypted connection
00966             """
00967             # Per RFC 4642, STARTTLS MUST NOT be sent after authentication or if
00968             # a TLS session already exists.
00969             if self.tls_on:
00970                 raise ValueError("TLS is already enabled.")
00971             if self.authenticated:
00972                 raise ValueError("TLS cannot be started after authentication.")
00973             resp = self._shortcmd('STARTTLS')
00974             if resp.startswith('382'):
00975                 self.file.close()
00976                 self.sock = _encrypt_on(self.sock, context)
00977                 self.file = self.sock.makefile("rwb")
00978                 self.tls_on = True
00979                 # Capabilities may change after TLS starts up, so ask for them
00980                 # again.
00981                 self._caps = None
00982                 self.getcapabilities()
00983             else:
00984                 raise NNTPError("TLS failed to start.")
00985 

Here is the call graph for this function:

def nntplib._NNTPBase.stat (   self,
  message_spec = None 
)
Process a STAT command.  Argument:
- message_spec: article number or message id (if not specified,
  the current article is selected)
Returns:
- resp: server response if successful
- art_num: the article number
- message_id: the message id

Definition at line 676 of file nntplib.py.

00676 
00677     def stat(self, message_spec=None):
00678         """Process a STAT command.  Argument:
00679         - message_spec: article number or message id (if not specified,
00680           the current article is selected)
00681         Returns:
00682         - resp: server response if successful
00683         - art_num: the article number
00684         - message_id: the message id
00685         """
00686         if message_spec:
00687             return self._statcmd('STAT {0}'.format(message_spec))
00688         else:
00689             return self._statcmd('STAT')

Here is the call graph for this function:

def nntplib._NNTPBase.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

Definition at line 809 of file nntplib.py.

00809 
00810     def xgtitle(self, group, *, file=None):
00811         """Process an XGTITLE command (optional server extension) Arguments:
00812         - group: group name wildcard (i.e. news.*)
00813         Returns:
00814         - resp: server response if successful
00815         - list: list of (name,title) strings"""
00816         warnings.warn("The XGTITLE extension is not actively used, "
00817                       "use descriptions() instead",
00818                       PendingDeprecationWarning, 2)
00819         line_pat = re.compile('^([^ \t]+)[ \t]+(.*)$')
00820         resp, raw_lines = self._longcmdstring('XGTITLE ' + group, file)
00821         lines = []
00822         for raw_line in raw_lines:
00823             match = line_pat.search(raw_line.strip())
00824             if match:
00825                 lines.append(match.group(1, 2))
00826         return resp, lines

Here is the call graph for this function:

def nntplib._NNTPBase.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
- file: Filename string or file object to store the result in
Returns:
- resp: server response if successful
- list: list of (nr, value) strings

Definition at line 752 of file nntplib.py.

00752 
00753     def xhdr(self, hdr, str, *, file=None):
00754         """Process an XHDR command (optional server extension).  Arguments:
00755         - hdr: the header type (e.g. 'subject')
00756         - str: an article nr, a message id, or a range nr1-nr2
00757         - file: Filename string or file object to store the result in
00758         Returns:
00759         - resp: server response if successful
00760         - list: list of (nr, value) strings
00761         """
00762         pat = re.compile('^([0-9]+) ?(.*)\n?')
00763         resp, lines = self._longcmdstring('XHDR {0} {1}'.format(hdr, str), file)
00764         def remove_number(line):
00765             m = pat.match(line)
00766             return m.group(1, 2) if m else line
00767         return resp, [remove_number(line) for line in lines]

Here is the call graph for this function:

def nntplib._NNTPBase.xover (   self,
  start,
  end,
  file = None 
)
Process an XOVER command (optional server extension) Arguments:
- start: start of range
- end: end of range
- file: Filename string or file object to store the result in
Returns:
- resp: server response if successful
- list: list of dicts containing the response fields

Definition at line 768 of file nntplib.py.

00768 
00769     def xover(self, start, end, *, file=None):
00770         """Process an XOVER command (optional server extension) Arguments:
00771         - start: start of range
00772         - end: end of range
00773         - file: Filename string or file object to store the result in
00774         Returns:
00775         - resp: server response if successful
00776         - list: list of dicts containing the response fields
00777         """
00778         resp, lines = self._longcmdstring('XOVER {0}-{1}'.format(start, end),
00779                                           file)
00780         fmt = self._getoverviewfmt()
00781         return resp, _parse_overview(lines, fmt)

Here is the call graph for this function:

def nntplib._NNTPBase.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

Definition at line 827 of file nntplib.py.

00827 
00828     def xpath(self, id):
00829         """Process an XPATH command (optional server extension) Arguments:
00830         - id: Message id of article
00831         Returns:
00832         resp: server response if successful
00833         path: directory path to article
00834         """
00835         warnings.warn("The XPATH extension is not actively used",
00836                       PendingDeprecationWarning, 2)
00837 
00838         resp = self._shortcmd('XPATH {0}'.format(id))
00839         if not resp.startswith('223'):
00840             raise NNTPReplyError(resp)
00841         try:
00842             [resp_num, path] = resp.split()
00843         except ValueError:
00844             raise NNTPReplyError(resp)
00845         else:
00846             return resp, path

Here is the call graph for this function:


Member Data Documentation

Definition at line 517 of file nntplib.py.

Definition at line 343 of file nntplib.py.

Definition at line 347 of file nntplib.py.

Definition at line 387 of file nntplib.py.

Definition at line 324 of file nntplib.py.

string nntplib._NNTPBase.encoding = 'utf-8' [static]

Definition at line 304 of file nntplib.py.

string nntplib._NNTPBase.errors = 'surrogateescape' [static]

Definition at line 305 of file nntplib.py.

Definition at line 323 of file nntplib.py.

Reimplemented in nntplib.NNTP.

Definition at line 322 of file nntplib.py.

Definition at line 364 of file nntplib.py.

Definition at line 363 of file nntplib.py.

Definition at line 333 of file nntplib.py.

Reimplemented in nntplib.NNTP_SSL, and nntplib.NNTP.

Definition at line 975 of file nntplib.py.

Definition at line 340 of file nntplib.py.

Definition at line 325 of file nntplib.py.


The documentation for this class was generated from the following file: