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
961355a5
Commit
961355a5
authored
Mar 25, 2011
by
R David Murray
Browse files
Options
Browse Files
Download
Plain Diff
Merge #11584: Since __getitem__ returns headers, make decode_header handle them.
parents
fd2c2a52
041015cc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
0 deletions
+20
-0
Lib/email/header.py
Lib/email/header.py
+6
-0
Lib/test/test_email/test_email.py
Lib/test/test_email/test_email.py
+14
-0
No files found.
Lib/email/header.py
View file @
961355a5
...
...
@@ -66,9 +66,15 @@ def decode_header(header):
otherwise a lower-case string containing the name of the character set
specified in the encoded string.
header may be a string that may or may not contain RFC2047 encoded words,
or it may be a Header object.
An email.errors.HeaderParseError may be raised when certain decoding error
occurs (e.g. a base64 decoding exception).
"""
# If it is a Header object, we can just return the chunks.
if
hasattr
(
header
,
'_chunks'
):
return
list
(
header
.
_chunks
)
# If no encoding, just return the header with no charset.
if
not
ecre
.
search
(
header
):
return
[(
header
,
None
)]
...
...
Lib/test/test_email/test_email.py
View file @
961355a5
...
...
@@ -3925,6 +3925,20 @@ A very long line that must get split to something other than at the
h
.
append
(
x
,
errors
=
'replace'
)
eq
(
str
(
h
),
e
)
def
test_escaped_8bit_header
(
self
):
x
=
b'Ynwp4dUEbay Auction Semiar- No Charge
\
x96
Earn Big'
x
=
x
.
decode
(
'ascii'
,
'surrogateescape'
)
h
=
Header
(
x
,
charset
=
email
.
charset
.
UNKNOWN8BIT
)
self
.
assertEqual
(
str
(
h
),
'Ynwp4dUEbay Auction Semiar- No Charge
\
uFFFD
Earn Big'
)
self
.
assertEqual
(
email
.
header
.
decode_header
(
h
),
[(
x
,
'unknown-8bit'
)])
def
test_modify_returned_list_does_not_change_header
(
self
):
h
=
Header
(
'test'
)
chunks
=
email
.
header
.
decode_header
(
h
)
chunks
.
append
((
'ascii'
,
'test2'
))
self
.
assertEqual
(
str
(
h
),
'test'
)
def
test_encoded_adjacent_nonencoded
(
self
):
eq
=
self
.
assertEqual
h
=
Header
()
...
...
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