bpo-42756: Configure LMTP Unix-domain socket to use global default timeout when timeout not provided (GH-23969)
This commit is contained in:
parent
de6f20a6de
commit
3bf05327c2
|
@ -1082,6 +1082,7 @@ class LMTP(SMTP):
|
|||
# Handle Unix-domain sockets.
|
||||
try:
|
||||
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||||
if self.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
|
||||
self.sock.settimeout(self.timeout)
|
||||
self.file = None
|
||||
self.sock.connect(host)
|
||||
|
|
|
@ -107,6 +107,9 @@ class MockSocket:
|
|||
def close(self):
|
||||
pass
|
||||
|
||||
def connect(self, host):
|
||||
pass
|
||||
|
||||
|
||||
def socket(family=None, type=None, proto=None):
|
||||
return MockSocket(family)
|
||||
|
@ -152,8 +155,12 @@ error = socket_module.error
|
|||
|
||||
|
||||
# Constants
|
||||
_GLOBAL_DEFAULT_TIMEOUT = socket_module._GLOBAL_DEFAULT_TIMEOUT
|
||||
AF_INET = socket_module.AF_INET
|
||||
AF_INET6 = socket_module.AF_INET6
|
||||
SOCK_STREAM = socket_module.SOCK_STREAM
|
||||
SOL_SOCKET = None
|
||||
SO_REUSEADDR = None
|
||||
|
||||
if hasattr(socket_module, 'AF_UNIX'):
|
||||
AF_UNIX = socket_module.AF_UNIX
|
||||
|
|
|
@ -165,6 +165,17 @@ class LMTPGeneralTests(GeneralTests, unittest.TestCase):
|
|||
|
||||
client = smtplib.LMTP
|
||||
|
||||
@unittest.skipUnless(hasattr(socket, 'AF_UNIX'), "test requires Unix domain socket")
|
||||
def testUnixDomainSocketTimeoutDefault(self):
|
||||
local_host = '/some/local/lmtp/delivery/program'
|
||||
mock_socket.reply_with(b"220 Hello world")
|
||||
try:
|
||||
client = self.client(local_host, self.port)
|
||||
finally:
|
||||
mock_socket.setdefaulttimeout(None)
|
||||
self.assertIsNone(client.sock.gettimeout())
|
||||
client.close()
|
||||
|
||||
def testTimeoutZero(self):
|
||||
super().testTimeoutZero()
|
||||
local_host = '/some/local/lmtp/delivery/program'
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Configure LMTP Unix-domain socket to use socket global default timeout when
|
||||
a timeout is not explicitly provided.
|
Loading…
Reference in New Issue