[Python-checkins] cpython (3.2): #11584: make decode_header handle Header objects correctly

r.david.murray python-checkins at python.org
Sat Jun 18 18:34:16 CEST 2011


http://hg.python.org/cpython/rev/d62e5682a8ac
changeset: 70860:d62e5682a8ac
branch: 3.2
parent: 70857:8319db2dd342
user: R David Murray <rdmurray at bitdance.com>
date: Sat Jun 18 12:30:55 2011 -0400
summary:
 #11584: make decode_header handle Header objects correctly
This updates b21fdfa0019c, which fixed this bug incorrectly.
files:
 Lib/email/header.py | 5 +++--
 Lib/email/test/test_email.py | 4 ++--
 Misc/NEWS | 3 +++
 3 files changed, 8 insertions(+), 4 deletions(-)
diff --git a/Lib/email/header.py b/Lib/email/header.py
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -73,9 +73,10 @@
 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 it is a Header object, we can just return the encoded chunks.
 if hasattr(header, '_chunks'):
- return list(header._chunks)
+ return [(_charset._encode(string, str(charset)), str(charset))
+ for string, charset in header._chunks]
 # If no encoding, just return the header with no charset.
 if not ecre.search(header):
 return [(header, None)]
diff --git a/Lib/email/test/test_email.py b/Lib/email/test/test_email.py
--- a/Lib/email/test/test_email.py
+++ b/Lib/email/test/test_email.py
@@ -4176,8 +4176,8 @@
 
 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)
+ e = x.decode('ascii', 'surrogateescape')
+ h = Header(e, 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')])
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -25,6 +25,9 @@
 Library
 -------
 
+- Issue #11584: email.header.decode_header no longer fails if the header
+ passed to it is a Header object.
+
 - Issue #11700: mailbox proxy object close methods can now be called multiple
 times without error.
 
-- 
Repository URL: http://hg.python.org/cpython


More information about the Python-checkins mailing list

AltStyle によって変換されたページ (->オリジナル) /