/usr/share/doc/python3-docs/html/_sources/library
NameSizeModeActions
2to3.rst.txt158980644editdlrm
abc.rst.txt118050644editdlrm
aifc.rst.txt75030644editdlrm
allos.rst.txt6780644editdlrm
archiving.rst.txt4400644editdlrm
argparse.rst.txt774800644editdlrm
array.rst.txt108120644editdlrm
ast.rst.txt101590644editdlrm
asynchat.rst.txt85280644editdlrm
asyncio-dev.rst.txt133980644editdlrm
asyncio-eventloop.rst.txt337010644editdlrm
asyncio-eventloops.rst.txt76600644editdlrm
asyncio-protocol.rst.txt251700644editdlrm
asyncio-queue.rst.txt43280644editdlrm
asyncio-stream.rst.txt143630644editdlrm
asyncio-subprocess.rst.txt155440644editdlrm
asyncio-sync.rst.txt90780644editdlrm
asyncio-task.rst.txt254060644editdlrm
asyncio.rst.txt22720644editdlrm
asyncore.rst.txt136240644editdlrm
atexit.rst.txt36690644editdlrm
audioop.rst.txt107120644editdlrm
base64.rst.txt103710644editdlrm
bdb.rst.txt129850644editdlrm
binary.rst.txt6540644editdlrm
binascii.rst.txt65390644editdlrm
binhex.rst.txt17090644editdlrm
bisect.rst.txt53980644editdlrm
builtins.rst.txt14650644editdlrm
bz2.rst.txt88250644editdlrm
calendar.rst.txt109880644editdlrm
cgi.rst.txt226500644editdlrm
cgitb.rst.txt29180644editdlrm
chunk.rst.txt50940644editdlrm
cmath.rst.txt93260644editdlrm
cmd.rst.txt137950644editdlrm
code.rst.txt78170644editdlrm
codecs.rst.txt755640644editdlrm
codeop.rst.txt30210644editdlrm
collections.abc.rst.txt128610644editdlrm
collections.rst.txt460630644editdlrm
colorsys.rst.txt18200644editdlrm
compileall.rst.txt89750644editdlrm
concurrency.rst.txt6730644editdlrm
concurrent.futures.rst.txt169100644editdlrm
concurrent.rst.txt1710644editdlrm
configparser.rst.txt487560644editdlrm
constants.rst.txt33310644editdlrm
contextlib.rst.txt281750644editdlrm
copy.rst.txt33780644editdlrm
copyreg.rst.txt21820644editdlrm
crypt.rst.txt51220644editdlrm
crypto.rst.txt4110644editdlrm
csv.rst.txt199020644editdlrm
ctypes.rst.txt886130644editdlrm
curses.ascii.rst.txt89200644editdlrm
curses.panel.rst.txt27640644editdlrm
curses.rst.txt763970644editdlrm
custominterp.rst.txt5690644editdlrm
datatypes.rst.txt7510644editdlrm
datetime.rst.txt905240644editdlrm
dbm.rst.txt142930644editdlrm
debug.rst.txt4710644editdlrm
decimal.rst.txt748690644editdlrm
development.rst.txt7040644editdlrm
difflib.rst.txt298610644editdlrm
dis.rst.txt325670644editdlrm
distribution.rst.txt4520644editdlrm
distutils.rst.txt19740644editdlrm
doctest.rst.txt717430644editdlrm
dummy_threading.rst.txt7840644editdlrm
email.charset.rst.txt92930644editdlrm
email.compat32-message.rst.txt334930644editdlrm
email.contentmanager.rst.txt91120644editdlrm
email.encoders.rst.txt27150644editdlrm
email.errors.rst.txt47920644editdlrm
email.examples.rst.txt19150644editdlrm
email.generator.rst.txt136370644editdlrm
email.header.rst.txt91880644editdlrm
email.headerregistry.rst.txt179570644editdlrm
email.iterators.rst.txt27950644editdlrm
email.message.rst.txt330080644editdlrm
email.mime.rst.txt117210644editdlrm
email.parser.rst.txt140920644editdlrm
email.policy.rst.txt270220644editdlrm
email.rst.txt67850644editdlrm
email.util.rst.txt92140644editdlrm
ensurepip.rst.txt49870644editdlrm
enum.rst.txt327510644editdlrm
errno.rst.txt68110644editdlrm
exceptions.rst.txt255700644editdlrm
faulthandler.rst.txt61360644editdlrm
fcntl.rst.txt71520644editdlrm
filecmp.rst.txt56230644editdlrm
fileformats.rst.txt2870644editdlrm
fileinput.rst.txt80510644editdlrm
filesys.rst.txt9610644editdlrm
fnmatch.rst.txt31030644editdlrm
formatter.rst.txt132420644editdlrm
fpectl.rst.txt41800644editdlrm
fractions.rst.txt63640644editdlrm
frameworks.rst.txt3910644editdlrm
ftplib.rst.txt175520644editdlrm
functional.rst.txt3650644editdlrm
functions.rst.txt716210644editdlrm
functools.rst.txt185030644editdlrm
gc.rst.txt96940644editdlrm
getopt.rst.txt65570644editdlrm
getpass.rst.txt18820644editdlrm
gettext.rst.txt255880644editdlrm
glob.rst.txt35080644editdlrm
grp.rst.txt24170644editdlrm
gzip.rst.txt83010644editdlrm
hashlib.rst.txt265230644editdlrm
heapq.rst.txt134020644editdlrm
hmac.rst.txt40200644editdlrm
html.entities.rst.txt13190644editdlrm
html.parser.rst.txt112750644editdlrm
html.rst.txt13040644editdlrm
http.client.rst.txt188700644editdlrm
http.cookiejar.rst.txt278320644editdlrm
http.cookies.rst.txt86450644editdlrm
http.rst.txt70960644editdlrm
http.server.rst.txt176390644editdlrm
i18n.rst.txt4080644editdlrm
idle.rst.txt258340644editdlrm
imaplib.rst.txt203670644editdlrm
imghdr.rst.txt29380644editdlrm
imp.rst.txt155480644editdlrm
importlib.rst.txt535630644editdlrm
index.rst.txt22580644editdlrm
inspect.rst.txt539280644editdlrm
internet.rst.txt9920644editdlrm
intro.rst.txt26450644editdlrm
io.rst.txt403280644editdlrm
ipaddress.rst.txt323400644editdlrm
ipc.rst.txt6490644editdlrm
itertools.rst.txt384590644editdlrm
json.rst.txt278760644editdlrm
keyword.rst.txt6170644editdlrm
language.rst.txt5220644editdlrm
linecache.rst.txt24080644editdlrm
locale.rst.txt254700644editdlrm
logging.config.rst.txt338860644editdlrm
logging.handlers.rst.txt424970644editdlrm
logging.rst.txt604790644editdlrm
lzma.rst.txt173610644editdlrm
macpath.rst.txt7070644editdlrm
mailbox.rst.txt630550644editdlrm
mailcap.rst.txt36910644editdlrm
markup.rst.txt6790644editdlrm
marshal.rst.txt48550644editdlrm
math.rst.txt143750644editdlrm
mimetypes.rst.txt98390644editdlrm
misc.rst.txt2470644editdlrm
mm.rst.txt4310644editdlrm
mmap.rst.txt112320644editdlrm
modulefinder.rst.txt32400644editdlrm
modules.rst.txt3550644editdlrm
msilib.rst.txt186120644editdlrm
msvcrt.rst.txt43920644editdlrm
multiprocessing.rst.txt1044940644editdlrm
netdata.rst.txt3390644editdlrm
netrc.rst.txt30070644editdlrm
nis.rst.txt19930644editdlrm
nntplib.rst.txt218210644editdlrm
numbers.rst.txt80890644editdlrm
numeric.rst.txt6960644editdlrm
operator.rst.txt189890644editdlrm
optparse.rst.txt769960644editdlrm
os.path.rst.txt164190644editdlrm
os.rst.txt1375340644editdlrm
ossaudiodev.rst.txt178450644editdlrm
othergui.rst.txt28220644editdlrm
parser.rst.txt151480644editdlrm
pathlib.rst.txt300450644editdlrm
pdb.rst.txt194540644editdlrm
persistence.rst.txt5910644editdlrm
pickle.rst.txt374400644editdlrm
pickletools.rst.txt37290644editdlrm
pipes.rst.txt25570644editdlrm
pkgutil.rst.txt87300644editdlrm
platform.rst.txt96240644editdlrm
plistlib.rst.txt73980644editdlrm
poplib.rst.txt81970644editdlrm
posix.rst.txt36940644editdlrm
pprint.rst.txt142740644editdlrm
profile.rst.txt279690644editdlrm
pty.rst.txt31230644editdlrm
pwd.rst.txt27390644editdlrm
pyclbr.rst.txt32970644editdlrm
pydoc.rst.txt46880644editdlrm
pyexpat.rst.txt286200644editdlrm
python.rst.txt4750644editdlrm
py_compile.rst.txt38510644editdlrm
queue.rst.txt72680644editdlrm
quopri.rst.txt25710644editdlrm
random.rst.txt185030644editdlrm
re.rst.txt649360644editdlrm
readline.rst.txt119430644editdlrm
reprlib.rst.txt51620644editdlrm
resource.rst.txt122910644editdlrm
rlcompleter.rst.txt22940644editdlrm
runpy.rst.txt82850644editdlrm
sched.rst.txt48420644editdlrm
secrets.rst.txt59300644editdlrm
select.rst.txt281750644editdlrm
selectors.rst.txt89250644editdlrm
shelve.rst.txt83900644editdlrm
shlex.rst.txt164410644editdlrm
shutil.rst.txt260140644editdlrm
signal.rst.txt172180644editdlrm
site.rst.txt96280644editdlrm
smtpd.rst.txt108060644editdlrm
smtplib.rst.txt234390644editdlrm
sndhdr.rst.txt19940644editdlrm
socket.rst.txt682020644editdlrm
socketserver.rst.txt237120644editdlrm
spwd.rst.txt29580644editdlrm
sqlite3.rst.txt392150644editdlrm
ssl.rst.txt960210644editdlrm
stat.rst.txt98050644editdlrm
statistics.rst.txt153010644editdlrm
stdtypes.rst.txt1792400644editdlrm
string.rst.txt353740644editdlrm
stringprep.rst.txt42790644editdlrm
struct.rst.txt195810644editdlrm
subprocess.rst.txt457930644editdlrm
sunau.rst.txt73900644editdlrm
superseded.rst.txt2580644editdlrm
symbol.rst.txt9750644editdlrm
symtable.rst.txt49640644editdlrm
sys.rst.txt582730644editdlrm
sysconfig.rst.txt87490644editdlrm
syslog.rst.txt43020644editdlrm
tabnanny.rst.txt20070644editdlrm
tarfile.rst.txt317490644editdlrm
telnetlib.rst.txt78990644editdlrm
tempfile.rst.txt138570644editdlrm
termios.rst.txt37510644editdlrm
test.rst.txt257640644editdlrm
text.rst.txt5840644editdlrm
textwrap.rst.txt105190644editdlrm
threading.rst.txt392570644editdlrm
time.rst.txt329670644editdlrm
timeit.rst.txt130000644editdlrm
tk.rst.txt16390644editdlrm
tkinter.rst.txt330270644editdlrm
tkinter.scrolledtext.rst.txt12550644editdlrm
tkinter.tix.rst.txt226530644editdlrm
tkinter.ttk.rst.txt584890644editdlrm
token.rst.txt26070644editdlrm
tokenize.rst.txt100020644editdlrm
trace.rst.txt69140644editdlrm
traceback.rst.txt178540644editdlrm
tracemalloc.rst.txt220890644editdlrm
tty.rst.txt10970644editdlrm
turtle.rst.txt712210644editdlrm
types.rst.txt99990644editdlrm
typing.rst.txt343320644editdlrm
undoc.rst.txt7800644editdlrm
unicodedata.rst.txt57620644editdlrm
unittest.mock-examples.rst.txt462060644editdlrm
unittest.mock.rst.txt859910644editdlrm
unittest.rst.txt933040644editdlrm
unix.rst.txt4460644editdlrm
urllib.error.rst.txt21990644editdlrm
urllib.parse.rst.txt273320644editdlrm
urllib.request.rst.txt593600644editdlrm
urllib.robotparser.rst.txt29690644editdlrm
urllib.rst.txt4660644editdlrm
uu.rst.txt23870644editdlrm
uuid.rst.txt87600644editdlrm
venv.rst.txt206210644editdlrm
warnings.rst.txt201520644editdlrm
wave.rst.txt68700644editdlrm
weakref.rst.txt213280644editdlrm
webbrowser.rst.txt97830644editdlrm
windows.rst.txt2720644editdlrm
winreg.rst.txt240730644editdlrm
winsound.rst.txt51340644editdlrm
wsgiref.rst.txt330470644editdlrm
xdrlib.rst.txt80780644editdlrm
xml.dom.minidom.rst.txt101980644editdlrm
xml.dom.pulldom.rst.txt51860644editdlrm
xml.dom.rst.txt395070644editdlrm
xml.etree.elementtree.rst.txt438710644editdlrm
xml.rst.txt60710644editdlrm
xml.sax.handler.rst.txt153990644editdlrm
xml.sax.reader.rst.txt121330644editdlrm
xml.sax.rst.txt71590644editdlrm
xml.sax.utils.rst.txt39010644editdlrm
xmlrpc.client.rst.txt230710644editdlrm
xmlrpc.rst.txt4750644editdlrm
xmlrpc.server.rst.txt149900644editdlrm
zipapp.rst.txt173920644editdlrm
zipfile.rst.txt240050644editdlrm
zipimport.rst.txt58050644editdlrm
zlib.rst.txt139120644editdlrm
_dummy_thread.rst.txt7620644editdlrm
_thread.rst.txt68860644editdlrm
__future__.rst.txt52450644editdlrm
__main__.rst.txt9040644editdlrm
Edit: /usr/share/doc/python3-docs/html/_sources/library/nntplib.rst.txt (21821B)
:mod:`nntplib` --- NNTP protocol client ======================================= .. module:: nntplib :synopsis: NNTP protocol client (requires sockets). **Source code:** :source:`Lib/nntplib.py` .. index:: pair: NNTP; protocol single: Network News Transfer Protocol -------------- This module defines the class :class:`NNTP` which implements the client side of the Network News Transfer Protocol. It can be used to implement a news reader or poster, or automated news processors. It is compatible with :rfc:`3977` as well as the older :rfc:`977` and :rfc:`2980`. 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 = nntplib.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 1096 articles, range 1 to 1096 >>> resp, overviews = s.over((last - 9, last)) >>> for id, over in overviews: ... print(id, nntplib.decode_header(over['subject'])) ... 1087 Re: Commit privileges for Łukasz Langa 1088 Re: 3.2 alpha 2 freeze 1089 Re: 3.2 alpha 2 freeze 1090 Re: Commit privileges for Łukasz Langa 1091 Re: Commit privileges for Łukasz Langa 1092 Updated ssh key 1093 Re: Updated ssh key 1094 Re: Updated ssh key 1095 Hello fellow committers! 1096 Re: Hello fellow committers! >>> s.quit() '205 Bye!' To post an article from a binary file (this assumes that the article has valid headers, and that you have right to post on the particular newsgroup):: >>> s = nntplib.NNTP('news.gmane.org') >>> f = open('article.txt', 'rb') >>> s.post(f) '240 Article posted successfully.' >>> s.quit() '205 Bye!' The module itself defines the following classes: .. class:: NNTP(host, port=119, user=None, password=None, readermode=None, usenetrc=False, [timeout]) Return a new :class:`NNTP` object, representing a connection to the NNTP server running on host *host*, listening at port *port*. An optional *timeout* can be specified for the socket connection. 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 ``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*. The :class:`NNTP` class supports the :keyword:`with` statement to unconditionally consume :exc:`OSError` exceptions and to close the NNTP connection when done, e.g.: >>> from nntplib import NNTP >>> with NNTP('news.gmane.org') as n: ... n.group('gmane.comp.python.committers') ... # doctest: +SKIP ('211 1755 1 1755 gmane.comp.python.committers', 1755, 1, 1755, 'gmane.comp.python.committers') >>> .. versionchanged:: 3.2 *usenetrc* is now ``False`` by default. .. versionchanged:: 3.3 Support for the :keyword:`with` statement was added. .. class:: NNTP_SSL(host, port=563, user=None, password=None, ssl_context=None, readermode=None, usenetrc=False, [timeout]) Return a new :class:`NNTP_SSL` object, representing an encrypted connection to the NNTP server running on host *host*, listening at port *port*. :class:`NNTP_SSL` objects have the same methods as :class:`NNTP` objects. If *port* is omitted, port 563 (NNTPS) is used. *ssl_context* is also optional, and is a :class:`~ssl.SSLContext` object. Please read :ref:`ssl-security` for best practices. All other parameters behave the same as for :class:`NNTP`. Note that SSL-on-563 is discouraged per :rfc:`4642`, in favor of STARTTLS as described below. However, some servers only support the former. .. versionadded:: 3.2 .. versionchanged:: 3.4 The class now supports hostname check with :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see :data:`ssl.HAS_SNI`). .. exception:: NNTPError Derived from the standard exception :exc:`Exception`, this is the base class for all exceptions raised by the :mod:`nntplib` module. Instances of this class have the following attribute: .. attribute:: response The response of the server if available, as a :class:`str` object. .. exception:: NNTPReplyError Exception raised when an unexpected reply is received from the server. .. exception:: NNTPTemporaryError Exception raised when a response code in the range 400--499 is received. .. exception:: NNTPPermanentError Exception raised when a response code in the range 500--599 is received. .. exception:: NNTPProtocolError Exception raised when a reply is received from the server that does not begin with a digit in the range 1--5. .. exception:: NNTPDataError Exception raised when there is some error in the response data. .. _nntp-objects: NNTP Objects ------------ When connected, :class:`NNTP` and :class:`NNTP_SSL` objects support the following methods and attributes. Attributes ^^^^^^^^^^ .. attribute:: NNTP.nntp_version An integer representing the version of the NNTP protocol supported by the server. In practice, this should be ``2`` for servers advertising :rfc:`3977` compliance and ``1`` for others. .. versionadded:: 3.2 .. attribute:: NNTP.nntp_implementation A string describing the software name and version of the NNTP server, or :const:`None` if not advertised by the server. .. versionadded:: 3.2 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. Many of the following methods take an optional keyword-only argument *file*. When the *file* argument is supplied, it must be either a :term:`file object` opened for binary writing, or the name of an on-disk file to be written to. The method will then write any data returned by the server (except for the response line and the terminating dot) to the file; any list of lines, tuples or objects that the method normally returns will be empty. .. versionchanged:: 3.2 Many of the following methods have been reworked and fixed, which makes them incompatible with their 3.1 counterparts. .. method:: NNTP.quit() Send a ``QUIT`` command and close the connection. Once this method has been called, no other methods of the NNTP object should be called. .. method:: NNTP.getwelcome() 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.) .. method:: NNTP.getcapabilities() Return the :rfc:`3977` capabilities advertised by the server, as a :class:`dict` instance mapping capability names to (possibly empty) lists of values. On legacy servers which don't understand the ``CAPABILITIES`` command, an empty dictionary is returned instead. >>> s = NNTP('news.gmane.org') >>> 'POST' in s.getcapabilities() True .. versionadded:: 3.2 .. method:: NNTP.login(user=None, password=None, usenetrc=True) Send ``AUTHINFO`` commands with the user name and password. If *user* and *password* are ``None`` and *usenetrc* is true, credentials from ``~/.netrc`` will be used if possible. Unless intentionally delayed, login is normally performed during the :class:`NNTP` object initialization and separately calling this function is unnecessary. To force authentication to be delayed, you must not set *user* or *password* when creating the object, and must set *usenetrc* to False. .. versionadded:: 3.2 .. method:: NNTP.starttls(ssl_context=None) Send a ``STARTTLS`` command. This will enable encryption on the NNTP connection. The *ssl_context* argument is optional and should be a :class:`ssl.SSLContext` object. Please read :ref:`ssl-security` for best practices. Note that this may not be done after authentication information has been transmitted, and authentication occurs by default if possible during a :class:`NNTP` object initialization. See :meth:`NNTP.login` for information on suppressing this behavior. .. versionadded:: 3.2 .. versionchanged:: 3.4 The method now supports hostname check with :attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see :data:`ssl.HAS_SNI`). .. method:: NNTP.newgroups(date, *, file=None) Send a ``NEWGROUPS`` command. The *date* argument should be a :class:`datetime.date` or :class:`datetime.datetime` object. Return a pair ``(response, groups)`` where *groups* is a list representing the groups that are new since the given *date*. If *file* is supplied, though, then *groups* will be empty. >>> from datetime import date, timedelta >>> resp, groups = s.newgroups(date.today() - timedelta(days=3)) >>> len(groups) # doctest: +SKIP 85 >>> groups[0] # doctest: +SKIP GroupInfo(group='gmane.network.tor.devel', last='4', first='1', flag='m') .. method:: NNTP.newnews(group, date, *, file=None) Send a ``NEWNEWS`` command. Here, *group* is a group name or ``'*'``, and *date* has the same meaning as for :meth:`newgroups`. Return a pair ``(response, articles)`` where *articles* is a list of message ids. This command is frequently disabled by NNTP server administrators. .. method:: NNTP.list(group_pattern=None, *, file=None) Send a ``LIST`` or ``LIST ACTIVE`` command. Return a pair ``(response, list)`` where *list* is a list of tuples representing all the groups available from this NNTP server, optionally matching the pattern string *group_pattern*. 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, and *flag* usually takes one of these values: * ``y``: Local postings and articles from peers are allowed. * ``m``: The group is moderated and all postings must be approved. * ``n``: No local postings are allowed, only articles from peers. * ``j``: Articles from peers are filed in the junk group instead. * ``x``: No local postings, and articles from peers are ignored. * ``=foo.bar``: Articles are filed in the ``foo.bar`` group instead. If *flag* has another value, then the status of the newsgroup should be considered unknown. This command can return very large results, especially if *group_pattern* is not specified. It is best to cache the results offline unless you really need to refresh them. .. versionchanged:: 3.2 *group_pattern* was added. .. method:: NNTP.descriptions(grouppattern) Send a ``LIST NEWSGROUPS`` command, where *grouppattern* is a wildmat string as specified in :rfc:`3977` (it's essentially the same as DOS or UNIX shell wildcard strings). Return a pair ``(response, descriptions)``, where *descriptions* is a dictionary mapping group names to textual descriptions. >>> resp, descs = s.descriptions('gmane.comp.python.*') >>> len(descs) # doctest: +SKIP 295 >>> descs.popitem() # doctest: +SKIP ('gmane.comp.python.bio.general', 'BioPython discussion list (Moderated)') .. method:: NNTP.description(group) Get a description for a single group *group*. If more than one group matches (if 'group' is a real wildmat string), return the first match. If no group matches, return an empty string. This elides the response code from the server. If the response code is needed, use :meth:`descriptions`. .. method:: NNTP.group(name) Send a ``GROUP`` command, where *name* is the group name. The group is selected as the current group, if it exists. 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. .. method:: NNTP.over(message_spec, *, file=None) Send an ``OVER`` command, or an ``XOVER`` command on legacy servers. *message_spec* can be either a string representing a message id, or a ``(first, last)`` tuple of numbers indicating a range of articles in the current group, or a ``(first, None)`` tuple indicating a range of articles starting from *first* to the last article in the current group, or :const:`None` to select the current article in the current group. Return a pair ``(response, overviews)``. *overviews* is a list of ``(article_number, overview)`` tuples, one for each article selected by *message_spec*. Each *overview* is a dictionary with the same number of items, but this number depends on the server. These items are either message headers (the key is then the lower-cased header name) or metadata items (the key is then the metadata name prepended with ``":"``). The following items are guaranteed to be present by the NNTP specification: * the ``subject``, ``from``, ``date``, ``message-id`` and ``references`` headers * the ``:bytes`` metadata: the number of bytes in the entire raw article (including headers and body) * the ``:lines`` metadata: the number of lines in the article body The value of each item is either a string, or :const:`None` if not present. It is advisable to use the :func:`decode_header` function on header values when they may contain non-ASCII characters:: >>> _, _, first, last, _ = s.group('gmane.comp.python.devel') >>> resp, overviews = s.over((last, last)) >>> art_num, over = overviews[0] >>> art_num 117216 >>> list(over.keys()) ['xref', 'from', ':lines', ':bytes', 'references', 'date', 'message-id', 'subject'] >>> over['from'] '=?UTF-8?B?Ik1hcnRpbiB2LiBMw7Z3aXMi?= ' >>> nntplib.decode_header(over['from']) '"Martin v. Löwis" ' .. versionadded:: 3.2 .. method:: NNTP.help(*, file=None) Send a ``HELP`` command. Return a pair ``(response, list)`` where *list* is a list of help strings. .. method:: NNTP.stat(message_spec=None) Send a ``STAT`` command, where *message_spec* is either a message id (enclosed in ``'<'`` and ``'>'``) or an article number in the current group. If *message_spec* is omitted or :const:`None`, the current article in the current group is considered. Return a triple ``(response, number, id)`` where *number* is the article number and *id* is the message id. >>> _, _, first, last, _ = s.group('gmane.comp.python.devel') >>> resp, number, message_id = s.stat(first) >>> number, message_id (9099, '<20030112190404.GE29873@epoch.metaslash.com>') .. method:: NNTP.next() Send a ``NEXT`` command. Return as for :meth:`.stat`. .. method:: NNTP.last() Send a ``LAST`` command. Return as for :meth:`.stat`. .. method:: NNTP.article(message_spec=None, *, file=None) Send an ``ARTICLE`` command, where *message_spec* has the same meaning as for :meth:`.stat`. Return a tuple ``(response, info)`` where *info* is a :class:`~collections.namedtuple` with three attributes *number*, *message_id* and *lines* (in that order). *number* is the article number in the group (or 0 if the information is not available), *message_id* the message id as a string, and *lines* a list of lines (without terminating newlines) comprising the raw message including headers and body. >>> resp, info = s.article('<20030112190404.GE29873@epoch.metaslash.com>') >>> info.number 0 >>> info.message_id '<20030112190404.GE29873@epoch.metaslash.com>' >>> len(info.lines) 65 >>> info.lines[0] b'Path: main.gmane.org!not-for-mail' >>> info.lines[1] b'From: Neal Norwitz ' >>> info.lines[-3:] [b'There is a patch for 2.3 as well as 2.2.', b'', b'Neal'] .. method:: NNTP.head(message_spec=None, *, file=None) Same as :meth:`article()`, but sends a ``HEAD`` command. The *lines* returned (or written to *file*) will only contain the message headers, not the body. .. method:: NNTP.body(message_spec=None, *, file=None) Same as :meth:`article()`, but sends a ``BODY`` command. The *lines* returned (or written to *file*) will only contain the message body, not the headers. .. method:: NNTP.post(data) Post an article using the ``POST`` command. The *data* argument is either a :term:`file object` opened for binary reading, or any iterable of bytes objects (representing raw lines of the article to be posted). It should represent a well-formed news article, including the required headers. The :meth:`post` method automatically escapes lines beginning with ``.`` and appends the termination line. If the method succeeds, the server's response is returned. If the server refuses posting, a :class:`NNTPReplyError` is raised. .. method:: NNTP.ihave(message_id, data) Send an ``IHAVE`` command. *message_id* is the id of the message to send to the server (enclosed in ``'<'`` and ``'>'``). The *data* parameter and the return value are the same as for :meth:`post()`. .. method:: NNTP.date() Return a pair ``(response, date)``. *date* is a :class:`~datetime.datetime` object containing the current date and time of the server. .. method:: NNTP.slave() Send a ``SLAVE`` command. Return the server's *response*. .. method:: NNTP.set_debuglevel(level) 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). The following are optional NNTP extensions defined in :rfc:`2980`. Some of them have been superseded by newer commands in :rfc:`3977`. .. method:: NNTP.xhdr(hdr, str, *, file=None) Send an ``XHDR`` command. The *hdr* argument is a header keyword, e.g. ``'subject'``. The *str* 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 number (as a string) and *text* is the text of the requested header for that article. If the *file* parameter is supplied, then the output of the ``XHDR`` command is stored in a file. If *file* is a string, then the method will open a file with that name, write to it then close it. If *file* is a :term:`file object`, then it will start calling :meth:`write` on it to store the lines of the command output. If *file* is supplied, then the returned *list* is an empty list. .. method:: NNTP.xover(start, end, *, file=None) Send an ``XOVER`` command. *start* and *end* are article numbers delimiting the range of articles to select. The return value is the same of for :meth:`over()`. It is recommended to use :meth:`over()` instead, since it will automatically use the newer ``OVER`` command if available. .. method:: NNTP.xpath(id) Return a pair ``(resp, path)``, where *path* is the directory path to the article with message ID *id*. Most of the time, this extension is not enabled by NNTP server administrators. .. deprecated:: 3.3 The XPATH extension is not actively used. .. XXX deprecated: .. method:: NNTP.xgtitle(name, *, file=None) Process an ``XGTITLE`` command, returning a pair ``(response, list)``, where *list* is a list of tuples containing ``(name, title)``. If the *file* parameter is supplied, then the output of the ``XGTITLE`` command is stored in a file. If *file* is a string, then the method will open a file with that name, write to it then close it. If *file* is a :term:`file object`, then it will start calling :meth:`write` on it to store the lines of the command output. If *file* is supplied, then the returned *list* is an empty list. This is an optional NNTP extension, and may not be supported by all servers. :rfc:`2980` says "It is suggested that this extension be deprecated". Use :meth:`descriptions` or :meth:`description` instead. Utility functions ----------------- The module also defines the following utility function: .. function:: decode_header(header_str) Decode a header value, un-escaping any escaped non-ASCII characters. *header_str* must be a :class:`str` object. The unescaped value is returned. Using this function is recommended to display some headers in a human readable form:: >>> decode_header("Some subject") 'Some subject' >>> decode_header("=?ISO-8859-15?Q?D=E9buter_en_Python?=") 'Débuter en Python' >>> decode_header("Re: =?UTF-8?B?cHJvYmzDqG1lIGRlIG1hdHJpY2U=?=") 'Re: problème de matrice'