summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorDong-hee Na <donghee.na92@gmail.com>2020-01-14 07:49:59 (GMT)
committerVictor Stinner <vstinner@python.org>2020-01-14 07:49:59 (GMT)
commit62e3973395fb9fab2eb8f651bcd0fea4e695e1cf (patch)
tree63c213ab1284ed6e7b28f858e7fecac4593f6246 /Lib/smtplib.py
parent2de064e6305008d16571a21e5f0c178e62e81f27 (diff)
downloadcpython-62e3973395fb9fab2eb8f651bcd0fea4e695e1cf.zip
cpython-62e3973395fb9fab2eb8f651bcd0fea4e695e1cf.tar.gz
cpython-62e3973395fb9fab2eb8f651bcd0fea4e695e1cf.tar.bz2
bpo-39259: smtp.SMTP/SMTP_SSL now reject timeout = 0 (GH-17958)
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 6513842e..4d5cdb5 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -303,6 +303,8 @@ class SMTP:
def _get_socket(self, host, port, timeout):
# This makes it simpler for SMTP_SSL to use the SMTP connect code
# and just alter the socket connection bit.
+ if timeout is not None and not timeout:
+ raise ValueError('Non-blocking socket (timeout=0) is not supported')
if self.debuglevel > 0:
self._print_debug('connect: to', (host, port), self.source_address)
return socket.create_connection((host, port), timeout,
@@ -1030,13 +1032,12 @@ if _have_ssl:
keyfile=keyfile)
self.context = context
SMTP.__init__(self, host, port, local_hostname, timeout,
- source_address)
+ source_address)
def _get_socket(self, host, port, timeout):
if self.debuglevel > 0:
self._print_debug('connect:', (host, port))
- new_socket = socket.create_connection((host, port), timeout,
- self.source_address)
+ new_socket = super()._get_socket(host, port, timeout)
new_socket = self.context.wrap_socket(new_socket,
server_hostname=self._host)
return new_socket
@@ -1065,15 +1066,15 @@ class LMTP(SMTP):
ehlo_msg = "lhlo"
def __init__(self, host='', port=LMTP_PORT, local_hostname=None,
- source_address=None):
+ source_address=None):
"""Initialize a new instance."""
- SMTP.__init__(self, host, port, local_hostname=local_hostname,
- source_address=source_address)
+ super().__init__(host, port, local_hostname=local_hostname,
+ source_address=source_address)
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 SMTP.connect(self, host, port, source_address=source_address)
+ return super().connect(host, port, source_address=source_address)
# Handle Unix-domain sockets.
try: