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.
diff --git a/Lib/nntplib.py b/Lib/nntplib.py
index 0ab5185..8951203 100644
--- a/Lib/nntplib.py
+++ b/Lib/nntplib.py
@@ -1056,6 +1056,8 @@
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)
diff --git a/Lib/test/test_nntplib.py b/Lib/test/test_nntplib.py
index 88c54f4..fdd76f9 100644
--- a/Lib/test/test_nntplib.py
+++ b/Lib/test/test_nntplib.py
@@ -258,6 +258,10 @@
# 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'):