]> granicus.if.org Git - python/commitdiff
Issue #7472: remove unused code from email.encoders.encode_7or8bit.
authorR. David Murray <rdmurray@bitdance.com>
Wed, 5 May 2010 17:31:03 +0000 (17:31 +0000)
committerR. David Murray <rdmurray@bitdance.com>
Wed, 5 May 2010 17:31:03 +0000 (17:31 +0000)
Yukihiro Nakadaira noticed a typo in encode_7or8bit that was trying
to special case iso-2022 codecs.  It turns out that the code in
question is never used, because whereas it was designed to trigger
if the payload encoding was eight bit but its output encoding was
7 bit, in practice the payload is always converted to the 7bit
encoding before encode_7or8bit is called.  Patch by Shawat Anand.

Lib/email/encoders.py
Lib/email/test/test_email.py

index c1a44aa88c8d2c684474f512b9708e6b00fcefeb..af45e62c333100021a7c8f8e51f85769d8eba0ac 100644 (file)
@@ -72,13 +72,7 @@ def encode_7or8bit(msg):
     try:
         orig.encode('ascii')
     except UnicodeError:
-        # iso-2022-* is non-ASCII but still 7-bit
-        charset = msg.get_charset()
-        output_cset = charset and charset.output_charset
-        if output_cset and output_cset.lower().startswith('iso-2022-'):
-            msg['Content-Transfer-Encoding'] = '7bit'
-        else:
-            msg['Content-Transfer-Encoding'] = '8bit'
+        msg['Content-Transfer-Encoding'] = '8bit'
     else:
         msg['Content-Transfer-Encoding'] = '7bit'
 
index 01d2a672a2f2f54aeddd25e4d16935249dee6512..bf41be7570319ad47ce25662c9988e386ee52c31 100644 (file)
@@ -564,6 +564,13 @@ class TestEncoders(unittest.TestCase):
         msg = MIMEText('hello \xf8 world', _charset='iso-8859-1')
         eq(msg['content-transfer-encoding'], 'quoted-printable')
 
+    def test_encode7or8bit(self):
+        # Make sure a charset whose input character set is 8bit but
+        # whose output character set is 7bit gets a transfer-encoding
+        # of 7bit.
+        eq = self.assertEqual
+        msg = email.MIMEText.MIMEText('\xca\xb8', _charset='euc-jp')
+        eq(msg['content-transfer-encoding'], '7bit')
 
 \f
 # Test long header wrapping