summaryrefslogtreecommitdiffstats
path: root/Doc/library/nntplib.rst
diff options
context:
space:
mode:
authorGiampaolo RodolĂ  <g.rodola@gmail.com>2011-03-03 18:34:06 (GMT)
committerGiampaolo RodolĂ  <g.rodola@gmail.com>2011-03-03 18:34:06 (GMT)
commit424298a155b5cc652ce1e539a1fedb658fba9cd1 (patch)
tree429c5ddf30e4c2cfcc9609fa8e5a2209de686127 /Doc/library/nntplib.rst
parent4db28d3343da7e48946a62036058fc6f0ee7cd71 (diff)
downloadcpython-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/library/nntplib.rst')
-rw-r--r--Doc/library/nntplib.rst13
1 files changed, 13 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])