diff options
author | Larry Hastings <larry@hastings.org> | 2015-02-26 05:58:48 -0800 |
---|---|---|
committer | Larry Hastings <larry@hastings.org> | 2015-02-26 05:58:48 -0800 |
commit | 8c3ec536e924002dc3afe4ff92e32fe9ed82ebab (patch) | |
tree | f141eec287584ba9d58d32461e1a7d92b5466e91 /Doc/includes | |
parent | e287746401398ee81c8e8a1513a5fe828eb32559 (diff) | |
parent | 7b2c3c6840052ea6f8b41253faf38b9e24f9a453 (diff) | |
download | cpython-git-8c3ec536e924002dc3afe4ff92e32fe9ed82ebab.tar.gz |
Merge 3.4.3 release engineering changes back into 3.4.
Diffstat (limited to 'Doc/includes')
-rw-r--r-- | Doc/includes/email-headers.py | 5 | ||||
-rw-r--r-- | Doc/includes/email-mime.py | 5 | ||||
-rw-r--r-- | Doc/includes/email-read-alternative-new-api.py | 3 | ||||
-rw-r--r-- | Doc/includes/email-simple.py | 7 |
4 files changed, 10 insertions, 10 deletions
diff --git a/Doc/includes/email-headers.py b/Doc/includes/email-headers.py index a53317dbd8..89c8f3af32 100644 --- a/Doc/includes/email-headers.py +++ b/Doc/includes/email-headers.py @@ -1,8 +1,9 @@ # Import the email modules we'll need from email.parser import Parser -# If the e-mail headers are in a file, uncomment this line: -#headers = Parser().parse(open(messagefile, 'r')) +# If the e-mail headers are in a file, uncomment these two lines: +# with open(messagefile) as fp: +# headers = Parser().parse(fp) # Or for parsing headers in a string, use: headers = Parser().parsestr('From: <user@example.com>\n' diff --git a/Doc/includes/email-mime.py b/Doc/includes/email-mime.py index a90edc1373..61d08302a2 100644 --- a/Doc/includes/email-mime.py +++ b/Doc/includes/email-mime.py @@ -20,9 +20,8 @@ msg.preamble = 'Our family reunion' for file in pngfiles: # Open the files in binary mode. Let the MIMEImage class automatically # guess the specific image type. - fp = open(file, 'rb') - img = MIMEImage(fp.read()) - fp.close() + with open(file, 'rb') as fp: + img = MIMEImage(fp.read()) msg.attach(img) # Send the email via our own SMTP server. diff --git a/Doc/includes/email-read-alternative-new-api.py b/Doc/includes/email-read-alternative-new-api.py index 8ab4e9fd16..3f5ab24c0f 100644 --- a/Doc/includes/email-read-alternative-new-api.py +++ b/Doc/includes/email-read-alternative-new-api.py @@ -12,7 +12,8 @@ from email.parser import BytesParser from imaginary import magic_html_parser # In a real program you'd get the filename from the arguments. -msg = BytesParser(policy=policy.default).parse(open('outgoing.msg', 'rb')) +with open('outgoing.msg', 'rb') as fp: + msg = BytesParser(policy=policy.default).parse(fp) # Now the header items can be accessed as a dictionary, and any non-ASCII will # be converted to unicode: diff --git a/Doc/includes/email-simple.py b/Doc/includes/email-simple.py index 077568d563..b9b8b410a6 100644 --- a/Doc/includes/email-simple.py +++ b/Doc/includes/email-simple.py @@ -6,10 +6,9 @@ from email.mime.text import MIMEText # Open a plain text file for reading. For this example, assume that # the text file contains only ASCII characters. -fp = open(textfile, 'rb') -# Create a text/plain message -msg = MIMEText(fp.read()) -fp.close() +with open(textfile) as fp: + # Create a text/plain message + msg = MIMEText(fp.read()) # me == the sender's email address # you == the recipient's email address |