Skip to content

bpo-39259: nntplib.NNTP/NNTP_SSL now reject timeout = 0 #17936

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 11, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions Doc/library/nntplib.rst
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,10 @@ The module itself defines the following classes:
.. versionchanged:: 3.3
Support for the :keyword:`with` statement was added.

.. versionchanged:: 3.9
If the *timeout* parameter is set to be zero, it will raise a
:class:`ValueError` to prevent the creation of a non-blocking socket.

.. 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
Expand Down Expand Up @@ -122,6 +126,10 @@ The module itself defines the following classes:
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
:data:`ssl.HAS_SNI`).

.. versionchanged:: 3.9
If the *timeout* parameter is set to be zero, it will raise a
:class:`ValueError` to prevent the creation of a non-blocking socket.

.. exception:: NNTPError

Derived from the standard exception :exc:`Exception`, this is the base
Expand Down
7 changes: 7 additions & 0 deletions Doc/whatsnew/3.9.rst
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,13 @@ with this change. The overridden methods of :class:`~imaplib.IMAP4_SSL` and
:class:`~imaplib.IMAP4_stream` were applied to this change.
(Contributed by Dong-hee Na in :issue:`38615`.)

nntplib
-------

:class:`~nntplib.NNTP` and :class:`~nntplib.NNTP_SSL` now raise a :class:`ValueError`
if the given timeout for their constructor is zero to prevent the creation of
a non-blocking socket. (Contributed by Dong-hee Na in :issue:`39259`.)

os
--

Expand Down
2 changes: 2 additions & 0 deletions Lib/nntplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1056,6 +1056,8 @@ def __init__(self, host, port=NNTP_PORT, user=None, password=None,
raise

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

Expand Down
4 changes: 4 additions & 0 deletions Lib/test/test_nntplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,10 @@ def wrapped(self):
# value
setattr(cls, name, wrap_meth(meth))

def test_timeout(self):
with self.assertRaises(ValueError):
self.NNTP_CLASS(self.NNTP_HOST, timeout=0, usenetrc=False)

def test_with_statement(self):
def is_connected():
if not hasattr(server, 'file'):
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
:class:`~nntplib.NNTP` and :class:`~nntplib.NNTP_SSL` now raise a
:class:`ValueError` if the given timeout for their constructor is zero to
prevent the creation of a non-blocking socket. Patch by Dong-hee Na.