]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42756: Configure LMTP Unix-domain socket to use global default timeout when timeo...
authorRoss <rrhodes@users.noreply.github.com>
Fri, 1 Jan 2021 17:20:25 +0000 (17:20 +0000)
committerGitHub <noreply@github.com>
Fri, 1 Jan 2021 17:20:25 +0000 (02:20 +0900)
Lib/smtplib.py
Lib/test/mock_socket.py
Lib/test/test_smtplib.py
Misc/NEWS.d/next/Library/2020-12-27-21-22-01.bpo-42756.dHMPJ9.rst [new file with mode: 0644]

index e2dbbbcf2e6d1640af4e87260af24d5b2d8b69dc..e81a9f05d60c4ecce47448347078e3ec19d70c2c 100755 (executable)
@@ -1082,7 +1082,8 @@ class LMTP(SMTP):
         # Handle Unix-domain sockets.
         try:
             self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
-            self.sock.settimeout(self.timeout)
+            if self.timeout is not socket._GLOBAL_DEFAULT_TIMEOUT:
+                self.sock.settimeout(self.timeout)
             self.file = None
             self.sock.connect(host)
         except OSError:
index cda4db25cba59446aa315e78c3f6e0b92134fbb5..c7abddcf5fafd34c209e35ea692192fe5a93d002 100644 (file)
@@ -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
index 91985384ec7ff96b1d85a37d93ba3ea43d3e0598..1ad45d8c780d172377fde9c36df1ea516a39b86f 100644 (file)
@@ -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'
diff --git a/Misc/NEWS.d/next/Library/2020-12-27-21-22-01.bpo-42756.dHMPJ9.rst b/Misc/NEWS.d/next/Library/2020-12-27-21-22-01.bpo-42756.dHMPJ9.rst
new file mode 100644 (file)
index 0000000..93a0bb0
--- /dev/null
@@ -0,0 +1,2 @@
+Configure LMTP Unix-domain socket to use socket global default timeout when
+a timeout is not explicitly provided.