mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
bpo-42413: socket.timeout is now an alias of TimeoutError (GH-23413)
Signed-off-by: Christian Heimes <christian@python.org>
This commit is contained in:
parent
7ddbaa7a1b
commit
03c8ddd9e9
24 changed files with 72 additions and 62 deletions
|
@ -1611,7 +1611,7 @@ class GeneralModuleTests(unittest.TestCase):
|
|||
if with_timeout:
|
||||
signal.signal(signal.SIGALRM, ok_handler)
|
||||
signal.alarm(1)
|
||||
self.assertRaises(socket.timeout, c.sendall,
|
||||
self.assertRaises(TimeoutError, c.sendall,
|
||||
b"x" * support.SOCK_MAX_SIZE)
|
||||
finally:
|
||||
signal.alarm(0)
|
||||
|
@ -2966,7 +2966,7 @@ class SendmsgStreamTests(SendmsgTests):
|
|||
try:
|
||||
while True:
|
||||
self.sendmsgToServer([b"a"*512])
|
||||
except socket.timeout:
|
||||
except TimeoutError:
|
||||
pass
|
||||
except OSError as exc:
|
||||
if exc.errno != errno.ENOMEM:
|
||||
|
@ -2974,7 +2974,7 @@ class SendmsgStreamTests(SendmsgTests):
|
|||
# bpo-33937 the test randomly fails on Travis CI with
|
||||
# "OSError: [Errno 12] Cannot allocate memory"
|
||||
else:
|
||||
self.fail("socket.timeout not raised")
|
||||
self.fail("TimeoutError not raised")
|
||||
finally:
|
||||
self.misc_event.set()
|
||||
|
||||
|
@ -3109,7 +3109,7 @@ class RecvmsgGenericTests(SendrecvmsgBase):
|
|||
# Check that timeout works.
|
||||
try:
|
||||
self.serv_sock.settimeout(0.03)
|
||||
self.assertRaises(socket.timeout,
|
||||
self.assertRaises(TimeoutError,
|
||||
self.doRecvmsg, self.serv_sock, len(MSG))
|
||||
finally:
|
||||
self.misc_event.set()
|
||||
|
@ -4827,7 +4827,7 @@ class FileObjectClassTestCase(SocketConnectedTest):
|
|||
self.cli_conn.settimeout(1)
|
||||
self.read_file.read(3)
|
||||
# First read raises a timeout
|
||||
self.assertRaises(socket.timeout, self.read_file.read, 1)
|
||||
self.assertRaises(TimeoutError, self.read_file.read, 1)
|
||||
# Second read is disallowed
|
||||
with self.assertRaises(OSError) as ctx:
|
||||
self.read_file.read(1)
|
||||
|
@ -5092,7 +5092,7 @@ class NetworkConnectionNoServer(unittest.TestCase):
|
|||
|
||||
class MockSocket(socket.socket):
|
||||
def connect(self, *args):
|
||||
raise socket.timeout('timed out')
|
||||
raise TimeoutError('timed out')
|
||||
|
||||
@contextlib.contextmanager
|
||||
def mocked_socket_module(self):
|
||||
|
@ -5142,13 +5142,13 @@ class NetworkConnectionNoServer(unittest.TestCase):
|
|||
with self.mocked_socket_module():
|
||||
try:
|
||||
socket.create_connection((HOST, 1234))
|
||||
except socket.timeout:
|
||||
except TimeoutError:
|
||||
pass
|
||||
except OSError as exc:
|
||||
if socket_helper.IPV6_ENABLED or exc.errno != errno.EAFNOSUPPORT:
|
||||
raise
|
||||
else:
|
||||
self.fail('socket.timeout not raised')
|
||||
self.fail('TimeoutError not raised')
|
||||
|
||||
|
||||
class NetworkConnectionAttributesTest(SocketTCPTest, ThreadableTest):
|
||||
|
@ -5250,7 +5250,7 @@ class NetworkConnectionBehaviourTest(SocketTCPTest, ThreadableTest):
|
|||
|
||||
def _testOutsideTimeout(self):
|
||||
self.cli = sock = socket.create_connection((HOST, self.port), timeout=1)
|
||||
self.assertRaises(socket.timeout, lambda: sock.recv(5))
|
||||
self.assertRaises(TimeoutError, lambda: sock.recv(5))
|
||||
|
||||
|
||||
class TCPTimeoutTest(SocketTCPTest):
|
||||
|
@ -5259,7 +5259,7 @@ class TCPTimeoutTest(SocketTCPTest):
|
|||
def raise_timeout(*args, **kwargs):
|
||||
self.serv.settimeout(1.0)
|
||||
self.serv.accept()
|
||||
self.assertRaises(socket.timeout, raise_timeout,
|
||||
self.assertRaises(TimeoutError, raise_timeout,
|
||||
"Error generating a timeout exception (TCP)")
|
||||
|
||||
def testTimeoutZero(self):
|
||||
|
@ -5267,7 +5267,7 @@ class TCPTimeoutTest(SocketTCPTest):
|
|||
try:
|
||||
self.serv.settimeout(0.0)
|
||||
foo = self.serv.accept()
|
||||
except socket.timeout:
|
||||
except TimeoutError:
|
||||
self.fail("caught timeout instead of error (TCP)")
|
||||
except OSError:
|
||||
ok = True
|
||||
|
@ -5292,7 +5292,7 @@ class TCPTimeoutTest(SocketTCPTest):
|
|||
try:
|
||||
signal.alarm(2) # POSIX allows alarm to be up to 1 second early
|
||||
foo = self.serv.accept()
|
||||
except socket.timeout:
|
||||
except TimeoutError:
|
||||
self.fail("caught timeout instead of Alarm")
|
||||
except Alarm:
|
||||
pass
|
||||
|
@ -5316,7 +5316,7 @@ class UDPTimeoutTest(SocketUDPTest):
|
|||
def raise_timeout(*args, **kwargs):
|
||||
self.serv.settimeout(1.0)
|
||||
self.serv.recv(1024)
|
||||
self.assertRaises(socket.timeout, raise_timeout,
|
||||
self.assertRaises(TimeoutError, raise_timeout,
|
||||
"Error generating a timeout exception (UDP)")
|
||||
|
||||
def testTimeoutZero(self):
|
||||
|
@ -5324,7 +5324,7 @@ class UDPTimeoutTest(SocketUDPTest):
|
|||
try:
|
||||
self.serv.settimeout(0.0)
|
||||
foo = self.serv.recv(1024)
|
||||
except socket.timeout:
|
||||
except TimeoutError:
|
||||
self.fail("caught timeout instead of error (UDP)")
|
||||
except OSError:
|
||||
ok = True
|
||||
|
@ -5341,7 +5341,7 @@ class UDPLITETimeoutTest(SocketUDPLITETest):
|
|||
def raise_timeout(*args, **kwargs):
|
||||
self.serv.settimeout(1.0)
|
||||
self.serv.recv(1024)
|
||||
self.assertRaises(socket.timeout, raise_timeout,
|
||||
self.assertRaises(TimeoutError, raise_timeout,
|
||||
"Error generating a timeout exception (UDPLITE)")
|
||||
|
||||
def testTimeoutZero(self):
|
||||
|
@ -5349,7 +5349,7 @@ class UDPLITETimeoutTest(SocketUDPLITETest):
|
|||
try:
|
||||
self.serv.settimeout(0.0)
|
||||
foo = self.serv.recv(1024)
|
||||
except socket.timeout:
|
||||
except TimeoutError:
|
||||
self.fail("caught timeout instead of error (UDPLITE)")
|
||||
except OSError:
|
||||
ok = True
|
||||
|
@ -5365,6 +5365,8 @@ class TestExceptions(unittest.TestCase):
|
|||
self.assertTrue(issubclass(socket.herror, OSError))
|
||||
self.assertTrue(issubclass(socket.gaierror, OSError))
|
||||
self.assertTrue(issubclass(socket.timeout, OSError))
|
||||
self.assertIs(socket.error, OSError)
|
||||
self.assertIs(socket.timeout, TimeoutError)
|
||||
|
||||
def test_setblocking_invalidfd(self):
|
||||
# Regression test for issue #28471
|
||||
|
@ -6167,7 +6169,7 @@ class SendfileUsingSendTest(ThreadedTCPSocketTest):
|
|||
with socket.create_connection(address) as sock:
|
||||
sock.settimeout(0.01)
|
||||
meth = self.meth_from_sock(sock)
|
||||
self.assertRaises(socket.timeout, meth, file)
|
||||
self.assertRaises(TimeoutError, meth, file)
|
||||
|
||||
def testWithTimeoutTriggeredSend(self):
|
||||
conn = self.accept_conn()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue