diff options
author | Giampaolo Rodolà <g.rodola@gmail.com> | 2011-03-03 18:34:06 (GMT) |
---|---|---|
committer | Giampaolo Rodolà <g.rodola@gmail.com> | 2011-03-03 18:34:06 (GMT) |
commit | 424298a155b5cc652ce1e539a1fedb658fba9cd1 (patch) | |
tree | 429c5ddf30e4c2cfcc9609fa8e5a2209de686127 /Doc | |
parent | 4db28d3343da7e48946a62036058fc6f0ee7cd71 (diff) | |
download | cpython-424298a155b5cc652ce1e539a1fedb658fba9cd1.zip cpython-424298a155b5cc652ce1e539a1fedb658fba9cd1.tar.gz cpython-424298a155b5cc652ce1e539a1fedb658fba9cd1.tar.bz2 |
Issue 9795: adds context manager protocol to nntplib.NNTP class so that it can used with the 'with' statement.
Diffstat (limited to 'Doc')
-rw-r--r-- | Doc/library/nntplib.rst | 13 | ||||
-rw-r--r-- | Doc/whatsnew/3.3.rst | 16 |
2 files changed, 29 insertions, 0 deletions
diff --git a/Doc/library/nntplib.rst b/Doc/library/nntplib.rst index 164f149..13257cc 100644 --- a/Doc/library/nntplib.rst +++ b/Doc/library/nntplib.rst @@ -70,10 +70,23 @@ The module itself defines the following classes: 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*. + :class:`NNTP` class supports the :keyword:`with` statement to + unconditionally consume :exc:`socket.error` exceptions and to close the NNTP + connection when done. Here is a sample on how using it: + + >>> from nntplib import NNTP + >>> with nntplib.NNTP('news.gmane.org') as n: + ... n.group('gmane.comp.python.committers') + ... + ('211 1454 1 1454 gmane.comp.python.committers', '1454', '1', '1454', '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]) diff --git a/Doc/whatsnew/3.3.rst b/Doc/whatsnew/3.3.rst index c0cb7cf..d86826c 100644 --- a/Doc/whatsnew/3.3.rst +++ b/Doc/whatsnew/3.3.rst @@ -88,6 +88,22 @@ os (Patch submitted by Giampaolo Rodolà in :issue:`10784`.) +nntplib +------- + +The :class:`nntplib.NNTP` class now supports the context manager protocol to +unconditionally consume :exc:`socket.error` exceptions and to close the NNTP +connection when done:: + + >>> from nntplib import NNTP + >>> with nntplib.NNTP('news.gmane.org') as n: + ... n.group('gmane.comp.python.committers') + ... + ('211 1454 1 1454 gmane.comp.python.committers', '1454', '1', '1454', 'gmane.comp.python.committers') + >>> + +(Contributed by Giampaolo Rodolà in :issue:`9795`) + Optimizations ============= |