summaryrefslogtreecommitdiff
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2018-09-07 15:29:27 -0700
committerGitHub <noreply@github.com>2018-09-07 15:29:27 -0700
commit9835696ec4c57a9a30f1c11cfb4c5d3e121bf97c (patch)
tree206919b7d0b7c91f64d4a5f4283d5ff3d6ca3fe0 /Lib/smtplib.py
parent73994077250bd70385cb8e7a92f24874129369d1 (diff)
downloadcpython-git-9835696ec4c57a9a30f1c11cfb4c5d3e121bf97c.tar.gz
bpo-34246: Use no mutable default args in smtplib (GH-8554)
Some methods of the SMTP class use mutable default arguments. Specially `send_message` is affected as it mutates one of the args by appending items to it, which has side effects on further calls. (cherry picked from commit d5fbe9b1a3d65ceeb9159c5ba999ee966a945f76) Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py12
1 files changed, 6 insertions, 6 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index b679875fd2..048c6bfb06 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -513,7 +513,7 @@ class SMTP:
"""SMTP 'noop' command -- doesn't do anything :>"""
return self.docmd("noop")
- def mail(self, sender, options=[]):
+ def mail(self, sender, options=()):
"""SMTP 'mail' command -- begins mail xfer session.
This method may raise the following exceptions:
@@ -534,7 +534,7 @@ class SMTP:
self.putcmd("mail", "FROM:%s%s" % (quoteaddr(sender), optionlist))
return self.getreply()
- def rcpt(self, recip, options=[]):
+ def rcpt(self, recip, options=()):
"""SMTP 'rcpt' command -- indicates 1 recipient for this mail."""
optionlist = ''
if options and self.does_esmtp:
@@ -785,8 +785,8 @@ class SMTP:
raise SMTPResponseException(resp, reply)
return (resp, reply)
- def sendmail(self, from_addr, to_addrs, msg, mail_options=[],
- rcpt_options=[]):
+ def sendmail(self, from_addr, to_addrs, msg, mail_options=(),
+ rcpt_options=()):
"""This command performs an entire mail transaction.
The arguments are:
@@ -890,7 +890,7 @@ class SMTP:
return senderrs
def send_message(self, msg, from_addr=None, to_addrs=None,
- mail_options=[], rcpt_options={}):
+ mail_options=(), rcpt_options=()):
"""Converts message to a bytestring and passes it to sendmail.
The arguments are as for sendmail, except that msg is an
@@ -958,7 +958,7 @@ class SMTP:
if international:
g = email.generator.BytesGenerator(
bytesmsg, policy=msg.policy.clone(utf8=True))
- mail_options += ['SMTPUTF8', 'BODY=8BITMIME']
+ mail_options = (*mail_options, 'SMTPUTF8', 'BODY=8BITMIME')
else:
g = email.generator.BytesGenerator(bytesmsg)
g.flatten(msg_copy, linesep='\r\n')