summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-01-14 21:42:09 (GMT)
committerVictor Stinner <vstinner@python.org>2020-01-14 21:42:09 (GMT)
commit65a5ce247f177c4c52cfd104d9df0c2f3b1c91f0 (patch)
treef1d71cd0ef97d2f55219e4e349eaa23ce87e49ac /Lib/smtplib.py
parent7d6378051feeadf45b4ce45b4b406b65df255648 (diff)
downloadcpython-65a5ce247f177c4c52cfd104d9df0c2f3b1c91f0.zip
cpython-65a5ce247f177c4c52cfd104d9df0c2f3b1c91f0.tar.gz
cpython-65a5ce247f177c4c52cfd104d9df0c2f3b1c91f0.tar.bz2
bpo-39329: Add timeout parameter for smtplib.LMTP constructor (GH-17998)
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py8
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 4d5cdb5..7808ba0 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -1066,19 +1066,23 @@ class LMTP(SMTP):
ehlo_msg = "lhlo"
def __init__(self, host='', port=LMTP_PORT, local_hostname=None,
- source_address=None):
+ source_address=None, timeout=socket._GLOBAL_DEFAULT_TIMEOUT):
"""Initialize a new instance."""
super().__init__(host, port, local_hostname=local_hostname,
- source_address=source_address)
+ source_address=source_address, timeout=timeout)
def connect(self, host='localhost', port=0, source_address=None):
"""Connect to the LMTP daemon, on either a Unix or a TCP socket."""
if host[0] != '/':
return super().connect(host, port, source_address=source_address)
+ if self.timeout is not None and not self.timeout:
+ raise ValueError('Non-blocking socket (timeout=0) is not supported')
+
# Handle Unix-domain sockets.
try:
self.sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
+ self.sock.settimeout(self.timeout)
self.file = None
self.sock.connect(host)
except OSError: