mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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.
This commit is contained in:
parent
136735c1a2
commit
1b335ae281
5 changed files with 24 additions and 0 deletions
|
@ -93,6 +93,10 @@ The module itself defines the following classes:
|
||||||
.. versionchanged:: 3.3
|
.. versionchanged:: 3.3
|
||||||
Support for the :keyword:`with` statement was added.
|
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])
|
.. 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
|
Return a new :class:`NNTP_SSL` object, representing an encrypted
|
||||||
|
@ -122,6 +126,10 @@ The module itself defines the following classes:
|
||||||
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
|
:attr:`ssl.SSLContext.check_hostname` and *Server Name Indication* (see
|
||||||
:data:`ssl.HAS_SNI`).
|
: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
|
.. exception:: NNTPError
|
||||||
|
|
||||||
Derived from the standard exception :exc:`Exception`, this is the base
|
Derived from the standard exception :exc:`Exception`, this is the base
|
||||||
|
|
|
@ -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.
|
:class:`~imaplib.IMAP4_stream` were applied to this change.
|
||||||
(Contributed by Dong-hee Na in :issue:`38615`.)
|
(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
|
os
|
||||||
--
|
--
|
||||||
|
|
||||||
|
|
|
@ -1056,6 +1056,8 @@ class NNTP(_NNTPBase):
|
||||||
raise
|
raise
|
||||||
|
|
||||||
def _create_socket(self, timeout):
|
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)
|
sys.audit("nntplib.connect", self, self.host, self.port)
|
||||||
return socket.create_connection((self.host, self.port), timeout)
|
return socket.create_connection((self.host, self.port), timeout)
|
||||||
|
|
||||||
|
|
|
@ -258,6 +258,10 @@ class NetworkedNNTPTestsMixin:
|
||||||
# value
|
# value
|
||||||
setattr(cls, name, wrap_meth(meth))
|
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 test_with_statement(self):
|
||||||
def is_connected():
|
def is_connected():
|
||||||
if not hasattr(server, 'file'):
|
if not hasattr(server, 'file'):
|
||||||
|
|
|
@ -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.
|
Loading…
Add table
Add a link
Reference in a new issue