Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
ec317a89
Commit
ec317a89
authored
Feb 11, 2013
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#17171: fix email.encoders.encode_7or8bit when applied to binary data.
parent
b3e8384c
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
2 deletions
+24
-2
Lib/email/encoders.py
Lib/email/encoders.py
+3
-1
Lib/email/test/test_email.py
Lib/email/test/test_email.py
+18
-1
Misc/NEWS
Misc/NEWS
+3
-0
No files found.
Lib/email/encoders.py
View file @
ec317a89
...
@@ -62,15 +62,17 @@ def encode_7or8bit(msg):
...
@@ -62,15 +62,17 @@ def encode_7or8bit(msg):
else
:
else
:
orig
.
decode
(
'ascii'
)
orig
.
decode
(
'ascii'
)
except
UnicodeError
:
except
UnicodeError
:
# iso-2022-* is non-ASCII but still 7-bit
charset
=
msg
.
get_charset
()
charset
=
msg
.
get_charset
()
output_cset
=
charset
and
charset
.
output_charset
output_cset
=
charset
and
charset
.
output_charset
# iso-2022-* is non-ASCII but encodes to a 7-bit representation
if
output_cset
and
output_cset
.
lower
().
startswith
(
'iso-2022-'
):
if
output_cset
and
output_cset
.
lower
().
startswith
(
'iso-2022-'
):
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
else
:
else
:
msg
[
'Content-Transfer-Encoding'
]
=
'8bit'
msg
[
'Content-Transfer-Encoding'
]
=
'8bit'
else
:
else
:
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
msg
[
'Content-Transfer-Encoding'
]
=
'7bit'
if
not
isinstance
(
orig
,
str
):
msg
.
set_payload
(
orig
.
decode
(
'ascii'
,
'surrogateescape'
))
...
...
Lib/email/test/test_email.py
View file @
ec317a89
...
@@ -1438,7 +1438,24 @@ class TestMIMEApplication(unittest.TestCase):
...
@@ -1438,7 +1438,24 @@ class TestMIMEApplication(unittest.TestCase):
eq
(
msg
.
get_payload
().
strip
(),
'+vv8/f7/'
)
eq
(
msg
.
get_payload
().
strip
(),
'+vv8/f7/'
)
eq
(
msg
.
get_payload
(
decode
=
True
),
bytesdata
)
eq
(
msg
.
get_payload
(
decode
=
True
),
bytesdata
)
def
test_body_with_encode_noop
(
self
):
def
test_binary_body_with_encode_7or8bit
(
self
):
# Issue 17171.
bytesdata
=
b'
\
xfa
\
xfb
\
xfc
\
xfd
\
xfe
\
xff
'
msg
=
MIMEApplication
(
bytesdata
,
_encoder
=
encoders
.
encode_7or8bit
)
# Treated as a string, this will be invalid code points.
self
.
assertEqual
(
msg
.
get_payload
(),
'
\
uFFFD
'
*
len
(
bytesdata
))
self
.
assertEqual
(
msg
.
get_payload
(
decode
=
True
),
bytesdata
)
self
.
assertEqual
(
msg
[
'Content-Transfer-Encoding'
],
'8bit'
)
s
=
BytesIO
()
g
=
BytesGenerator
(
s
)
g
.
flatten
(
msg
)
wireform
=
s
.
getvalue
()
msg2
=
email
.
message_from_bytes
(
wireform
)
self
.
assertEqual
(
msg
.
get_payload
(),
'
\
uFFFD
'
*
len
(
bytesdata
))
self
.
assertEqual
(
msg2
.
get_payload
(
decode
=
True
),
bytesdata
)
self
.
assertEqual
(
msg2
[
'Content-Transfer-Encoding'
],
'8bit'
)
def
test_binary_body_with_encode_noop
(
self
):
# Issue 16564: This does not produce an RFC valid message, since to be
# Issue 16564: This does not produce an RFC valid message, since to be
# valid it should have a CTE of binary. But the below works in
# valid it should have a CTE of binary. But the below works in
# Python2, and is documented as working this way.
# Python2, and is documented as working this way.
...
...
Misc/NEWS
View file @
ec317a89
...
@@ -221,6 +221,9 @@ Core and Builtins
...
@@ -221,6 +221,9 @@ Core and Builtins
Library
Library
-------
-------
- Issue #16564: Fixed regression relative to Python2 in the operation of
email.encoders.encode_7or8bit when used with binary data.
- Issue #17052: unittest discovery should use self.testLoader.
- Issue #17052: unittest discovery should use self.testLoader.
- Issue #17141: random.vonmisesvariate() no more hangs for large kappas.
- Issue #17141: random.vonmisesvariate() no more hangs for large kappas.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment