summaryrefslogtreecommitdiffstats
path: root/Lib/email/header.py
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2011-06-19 14:38:02 (GMT)
committerBenjamin Peterson <benjamin@python.org>2011-06-19 14:38:02 (GMT)
commit12f2bffce1be0e36e2cf11a8be80de7fcb76dd54 (patch)
tree1f37a3639480738daf90d359dbc239ac664860f3 /Lib/email/header.py
parentdefe6f61fe8595d0d2cc194c120ef0b3dc3a4286 (diff)
parent2510d9e8d9d3244c8d35efdd01bca265755655de (diff)
downloadcpython-12f2bffce1be0e36e2cf11a8be80de7fcb76dd54.zip
cpython-12f2bffce1be0e36e2cf11a8be80de7fcb76dd54.tar.gz
cpython-12f2bffce1be0e36e2cf11a8be80de7fcb76dd54.tar.bz2
merge heads
Diffstat (limited to 'Lib/email/header.py')
-rw-r--r--Lib/email/header.py10
1 files changed, 7 insertions, 3 deletions
diff --git a/Lib/email/header.py b/Lib/email/header.py
index 0a66df5..2e687b7 100644
--- a/Lib/email/header.py
+++ b/Lib/email/header.py
@@ -73,9 +73,10 @@ def decode_header(header):
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)]
@@ -274,7 +275,10 @@ class Header:
charset = Charset(charset)
if not isinstance(s, str):
input_charset = charset.input_codec or 'us-ascii'
- s = s.decode(input_charset, errors)
+ if input_charset == _charset.UNKNOWN8BIT:
+ s = s.decode('us-ascii', 'surrogateescape')
+ else:
+ s = s.decode(input_charset, errors)
# Ensure that the bytes we're storing can be decoded to the output
# character set, otherwise an early error is thrown.
output_charset = charset.output_codec or 'us-ascii'