1
     /�ÆÅÄa–Ãa¾”J_)â‚Á;q—Å£È  $    /‹      sËÌIUÈË/QHË/ÍKÑã +�©!        1ˆÁÃ„M²À¾È 8Ã    1
:mod:`nntplib` --- NNTP protocol client
=======================================

.. module:: nntplib
   :synopsis: NNTP protocol client (requires sockets).


.. index::
   pair: NNTP; protocol
   single: Network News Transfer Protocol

**Source code:** :source:`Lib/nntplib.py`

--------------

This module defines the class :class:`NNTP` which implements the client side of
the NNTP protocol.  It can be used to implement a news reader or poster, or
automated news processors.  For more information on NNTP (Network News Transfer
Protocol), see Internet :rfc:`977`.

Here are two small examples of how it can be used.  To list some statistics
about a newsgroup and print the subjects of the last 10 articles::

   >>> s = NNTP('news.gmane.org')
   >>> resp, count, first, last, name = s.group('gmane.comp.python.committers')
   >>> print 'Group', name, 'has', count, 'articles, range', first, 'to', last
   Group gmane.comp.python.committers has 1071 articles, range 1 to 1071
   >>> resp, subs = s.xhdr('subject', first + '-' + last)
   >>> for id, sub in subs[-10:]: print id, sub
   ...
   1062 Re: Mercurial Status?
   1063 Re: [python-committers]  (Windows) buildbots on 3.x
   1064 Re: Mercurial Status?
   1065 Re: Mercurial Status?
   1066 Python 2.6.6 status
   1067 Commit Privileges for Ask Solem
   1068 Re: Commit Privileges for Ask Solem
   1069 Re: Commit Privileges for Ask Solem
   1070 Re: Commit Privileges for Ask Solem
   1071 2.6.6 rc 2
   >>> s.quit()
   '205 Bye!'

To post an article from a file (this assumes that the article has valid
headers, and that you have right to post on the particular newsgroup)::

   >>> s = NNTP('news.gmane.org')
   >>> f = open('articlefile')
   >>> s.post(f)
   '240 Article posted successfully.'
   >>> s.quit()
   '205 Bye!'

The module itself defines the following items:


.. class:: NNTP(host[, port [, user[, password [, readermode] [, usenetrc]]]])

   Return a new instance of the :class:`NNTP` class, representing a connection
   to the NNTP server running on host *host*, listening at port *port*.  The
   default *port* is 119.  If the optional *user* and *password* are provided,
   or if suitable credentials are present in :file:`/.netrc` and the optional
   flag *usenetrc* is true (the default), the ``AUTHINFO USER`` and ``AUTHINFO
   PASS`` commands are used to identify and authenticate the user to the server.
   If the optional flag *readermode* is true, then a ``mode reader`` command is
   sent before authentication is performed.  Reader mode 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
   :exc:`NNTPPermanentError`\ s, you might need to set *readermode*.
   *readermode* defaults to ``None``. *usenetrc* defaults to ``True``.

   .. versionchanged:: 2.4
      *usenetrc* argument added.


.. exception:: NNTPError

   Derived from the standard exception :exc:`Exception`, this is the base class for
   all exceptions raised by the :mod:`nntplib` module.


.. exception:: NNTPReplyError

   Exception raised when an unexpected reply is received from the server.  For
   backwards compatibility, the exception ``error_reply`` is equivalent to this
   class.


.. exception:: NNTPTemporaryError

   Exception raised when an error code in the range 400--499 is received.  For
   backwards compatibility, the exception ``error_temp`` is equivalent to this
   class.


.. exception:: NNTPPermanentError

   Exception raised when an error code in the range 500--599 is received.  For
   backwards compatibility, the exception ``error_perm`` is equivalent to this
   class.


.. exception:: NNTPProtocolError

   Exception raised when a reply is received from the server that does not begin
   with a digit in the range 1--5.  For backwards compatibility, the exception
   ``error_proto`` is equivalent to this class.


.. exception:: NNTPDataError

   Exception raised 