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
29097d5a
Commit
29097d5a
authored
Sep 11, 2016
by
R David Murray
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Merge: #19003: Only replace \r and/or \n line endings in email.generator.
parent
727cc933
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
22 additions
and
6 deletions
+22
-6
Lib/email/generator.py
Lib/email/generator.py
+10
-6
Lib/test/test_email/test_email.py
Lib/test/test_email/test_email.py
+12
-0
No files found.
Lib/email/generator.py
View file @
29097d5a
...
...
@@ -18,6 +18,7 @@ from email.utils import _has_surrogates
UNDERSCORE
=
'_'
NL
=
'
\
n
'
# XXX: no longer used by the code below.
NLCRE
=
re
.
compile
(
r'\r\n|\r|\n'
)
fcre
=
re
.
compile
(
r'^From '
,
re
.
MULTILINE
)
...
...
@@ -149,14 +150,17 @@ class Generator:
# We have to transform the line endings.
if
not
lines
:
return
lines
=
lines
.
splitlines
(
True
)
lines
=
NLCRE
.
split
(
lines
)
for
line
in
lines
[:
-
1
]:
self
.
write
(
line
.
rstrip
(
'
\
r
\
n
'
))
self
.
write
(
self
.
_NL
)
laststripped
=
lines
[
-
1
].
rstrip
(
'
\
r
\
n
'
)
self
.
write
(
laststripped
)
if
len
(
lines
[
-
1
])
!=
len
(
laststripped
):
self
.
write
(
line
)
self
.
write
(
self
.
_NL
)
if
lines
[
-
1
]:
self
.
write
(
lines
[
-
1
])
# XXX logic tells me this else should be needed, but the tests fail
# with it and pass without it. (NLCRE.split ends with a blank element
# if and only if there was a trailing newline.)
#else:
# self.write(self._NL)
def
_write
(
self
,
msg
):
# We can't write the headers yet because of the following scenario:
...
...
Lib/test/test_email/test_email.py
View file @
29097d5a
...
...
@@ -1599,6 +1599,18 @@ class TestMIMEApplication(unittest.TestCase):
self
.
assertEqual
(
msg
.
get_payload
(),
'
\
uFFFD
'
*
len
(
bytesdata
))
self
.
assertEqual
(
msg2
.
get_payload
(
decode
=
True
),
bytesdata
)
def
test_binary_body_with_unicode_linend_encode_noop
(
self
):
# Issue 19003: This is a variation on #16564.
bytesdata
=
b'
\
x0b
\
xfa
\
xfb
\
xfc
\
xfd
\
xfe
\
xff
'
msg
=
MIMEApplication
(
bytesdata
,
_encoder
=
encoders
.
encode_noop
)
self
.
assertEqual
(
msg
.
get_payload
(
decode
=
True
),
bytesdata
)
s
=
BytesIO
()
g
=
BytesGenerator
(
s
)
g
.
flatten
(
msg
)
wireform
=
s
.
getvalue
()
msg2
=
email
.
message_from_bytes
(
wireform
)
self
.
assertEqual
(
msg2
.
get_payload
(
decode
=
True
),
bytesdata
)
def
test_binary_body_with_encode_quopri
(
self
):
# Issue 14360.
bytesdata
=
b'
\
xfa
\
xfb
\
xfc
\
xfd
\
xfe
\
xff
'
...
...
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