Skip to content

Commit 1b335ae

Browse files
corona10vstinner
authored andcommitted
bpo-39259: nntplib.NNTP/NNTP_SSL now reject timeout = 0 (GH-17936)
nntplib.NNTP and nntplib.NNTP_SSL now raise a ValueError if the given timeout for their constructor is zero to prevent the creation of a non-blocking socket.
1 parent 136735c commit 1b335ae

File tree

5 files changed

+24
-0
lines changed

5 files changed

+24
-0
lines changed

Doc/library/nntplib.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,10 @@ The module itself defines the following classes:
9393
.. versionchanged:: 3.3
9494
Support for the :keyword:`with` statement was added.
9595

96+
.. versionchanged:: 3.9
97+
If the *timeout* parameter is set to be zero, it will raise a
98+
:class:`ValueError` to prevent the creation of a non-blocking socket.
99+
96100
.. class:: NNTP_SSL(host, port=563, user=None, password=None, ssl_context=None, readermode=None, usenetrc=False, [timeout])
97101

98102
Return a new :class:`NNTP_SSL` object, representing an encrypted
@@ -122,6 +126,10 @@ The module itself defines the following classes:
122126
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
123127
:data:`ssl.HAS_SNI`).
124128

129+
.. versionchanged:: 3.9
130+
If the *timeout* parameter is set to be zero, it will raise a
131+
:class:`ValueError` to prevent the creation of a non-blocking socket.
132+
125133
.. exception:: NNTPError
126134

127135
Derived from the standard exception :exc:`Exception`, this is the base

Doc/whatsnew/3.9.rst

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,13 @@ with this change. The overridden methods of :class:`~imaplib.IMAP4_SSL` and
177177
:class:`~imaplib.IMAP4_stream` were applied to this change.
178178
(Contributed by Dong-hee Na in :issue:`38615`.)
179179

180+
nntplib
181+
-------
182+
183+
:class:`~nntplib.NNTP` and :class:`~nntplib.NNTP_SSL` now raise a :class:`ValueError`
184+
if the given timeout for their constructor is zero to prevent the creation of
185+
a non-blocking socket. (Contributed by Dong-hee Na in :issue:`39259`.)
186+
180187
os
181188
--
182189

Lib/nntplib.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1056,6 +1056,8 @@ def __init__(self, host, port=NNTP_PORT, user=None, password=None,
10561056
raise
10571057

10581058
def _create_socket(self, timeout):
1059+
if timeout is not None and not timeout:
1060+
raise ValueError('Non-blocking socket (timeout=0) is not supported')
10591061
sys.audit("nntplib.connect", self, self.host, self.port)
10601062
return socket.create_connection((self.host, self.port), timeout)
10611063

Lib/test/test_nntplib.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,10 @@ def wrapped(self):
258258
# value
259259
setattr(cls, name, wrap_meth(meth))
260260

261+
def test_timeout(self):
262+
with self.assertRaises(ValueError):
263+
self.NNTP_CLASS(self.NNTP_HOST, timeout=0, usenetrc=False)
264+
261265
def test_with_statement(self):
262266
def is_connected():
263267
if not hasattr(server, 'file'):
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
:class:`~nntplib.NNTP` and :class:`~nntplib.NNTP_SSL` now raise a
2+
:class:`ValueError` if the given timeout for their constructor is zero to
3+
prevent the creation of a non-blocking socket. Patch by Dong-hee Na.

0 commit comments

Comments
 (0)