8000 [3.9] bpo-42756: Configure LMTP Unix-domain socket to use global default timeout when timeout not provided by corona10 · Pull Request #24049 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

[3.9] bpo-42756: Configure LMTP Unix-domain socket to use 10000 global default timeout when timeout not provided #24049

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion Lib/smtplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -1082,7 +1082,8 @@ def connect(self, host='localhost', port=0, source_address=None):
# 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:
Expand Down
7 changes: 7 additions & 0 deletions Lib/test/mock_socket.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ def getpeername(self):
def close(self):
pass

def connect(self, host):
pass


def socket(family=None, type=None, proto=None):
return MockSocket(family)
Expand Down Expand Up @@ -152,8 +155,12 @@ def getaddrinfo(*args, **kw):


# 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
11 changes: 11 additions & 0 deletions Lib/test/test_smtplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Configure LMTP Unix-domain socket to use socket global default timeout when
a timeout is not explicitly provided.
0