cpython: 5a0478bd5f11 (original) (raw)
Mercurial > cpython
changeset 82099:5a0478bd5f11
Merge: #16564: Fix regression in use of encoders.encode_noop with binary data. [#16564]
R David Murray rdmurray@bitdance.com | |
---|---|
date | Sat, 09 Feb 2013 13:13:14 -0500 |
parents | 80320773d755(current diff)2b1edefc1e99(diff) |
children | c4512797b879 |
files | Misc/NEWS |
diffstat | 4 files changed, 28 insertions(+), 0 deletions(-)[+] [-] Lib/email/encoders.py 6 Lib/email/generator.py 3 Lib/test/test_email/test_email.py 16 Misc/NEWS 3 |
line wrap: on
line diff
--- a/Lib/email/encoders.py +++ b/Lib/email/encoders.py @@ -76,3 +76,9 @@ def encode_7or8bit(msg): def encode_noop(msg): """Do nothing."""
Well, not quite nothing: in Python3 we have to turn bytes into a string
in our internal surrogateescaped form in order to keep the model
consistent.
- orig = msg.get_payload()
- if not isinstance(orig, str):
msg.set_payload(orig.decode('ascii', 'surrogateescape'))[](#l1.12)
--- a/Lib/email/generator.py +++ b/Lib/email/generator.py @@ -406,6 +406,9 @@ class BytesGenerator(Generator): else: super(BytesGenerator,self)._handle_text(msg)
+ @classmethod def _compile_re(cls, s, flags): return re.compile(s.encode('ascii'), flags)
--- a/Lib/test/test_email/test_email.py +++ b/Lib/test/test_email/test_email.py @@ -1440,6 +1440,22 @@ class TestMIMEApplication(unittest.TestC eq(msg.get_payload().strip(), '+vv8/f7/') eq(msg.get_payload(decode=True), bytesdata)
- def test_body_with_encode_noop(self):
# Issue 16564: This does not produce an RFC valid message, since to be[](#l3.8)
# valid it should have a CTE of binary. But the below works in[](#l3.9)
# Python2, and is documented as working this way.[](#l3.10)
bytesdata = b'\xfa\xfb\xfc\xfd\xfe\xff'[](#l3.11)
msg = MIMEApplication(bytesdata, _encoder=encoders.encode_noop)[](#l3.12)
# Treated as a string, this will be invalid code points.[](#l3.13)
self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata))[](#l3.14)
self.assertEqual(msg.get_payload(decode=True), bytesdata)[](#l3.15)
s = BytesIO()[](#l3.16)
g = BytesGenerator(s)[](#l3.17)
g.flatten(msg)[](#l3.18)
wireform = s.getvalue()[](#l3.19)
msg2 = email.message_from_bytes(wireform)[](#l3.20)
self.assertEqual(msg.get_payload(), '\uFFFD' * len(bytesdata))[](#l3.21)
self.assertEqual(msg2.get_payload(decode=True), bytesdata)[](#l3.22)
Test the basic MIMEText class
--- a/Misc/NEWS +++ b/Misc/NEWS @@ -241,6 +241,9 @@ Core and Builtins Library ------- +- Issue #16564: Fixed regression relative to Python2 in the operation of