[Python-checkins] r42272 - in python/branches/release24-maint/Lib/email: Charset.py Generator.py Message.py test/test_email.py test/test_email_codecs.py

barry.warsaw python-checkins at python.org
Wed Feb 8 15:58:56 CET 2006


Author: barry.warsaw
Date: Wed Feb  8 15:58:55 2006
New Revision: 42272

Modified:
   python/branches/release24-maint/Lib/email/Charset.py
   python/branches/release24-maint/Lib/email/Generator.py
   python/branches/release24-maint/Lib/email/Message.py
   python/branches/release24-maint/Lib/email/test/test_email.py
   python/branches/release24-maint/Lib/email/test/test_email_codecs.py
Log:
Port of r42271 from the trunk -- relevant patches for SF 1409455 for email
3.0/Python 2.4.


Modified: python/branches/release24-maint/Lib/email/Charset.py
==============================================================================
--- python/branches/release24-maint/Lib/email/Charset.py	(original)
+++ python/branches/release24-maint/Lib/email/Charset.py	Wed Feb  8 15:58:55 2006
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2004 Python Software Foundation
+# Copyright (C) 2001-2006 Python Software Foundation
 # Author: Ben Gertzfield, Barry Warsaw
 # Contact: email-sig at python.org
 
@@ -206,7 +206,7 @@
         self.input_codec = CODEC_MAP.get(self.input_charset,
                                          self.input_charset)
         self.output_codec = CODEC_MAP.get(self.output_charset,
-                                            self.output_charset)
+                                          self.output_charset)
 
     def __str__(self):
         return self.input_charset.lower()

Modified: python/branches/release24-maint/Lib/email/Generator.py
==============================================================================
--- python/branches/release24-maint/Lib/email/Generator.py	(original)
+++ python/branches/release24-maint/Lib/email/Generator.py	Wed Feb  8 15:58:55 2006
@@ -1,4 +1,4 @@
-# Copyright (C) 2001-2004 Python Software Foundation
+# Copyright (C) 2001-2006 Python Software Foundation
 # Author: Barry Warsaw
 # Contact: email-sig at python.org
 
@@ -175,9 +175,6 @@
         payload = msg.get_payload()
         if payload is None:
             return
-        cset = msg.get_charset()
-        if cset is not None:
-            payload = cset.body_encode(payload)
         if not isinstance(payload, basestring):
             raise TypeError('string payload expected: %s' % type(payload))
         if self._mangle_from_:

Modified: python/branches/release24-maint/Lib/email/Message.py
==============================================================================
--- python/branches/release24-maint/Lib/email/Message.py	(original)
+++ python/branches/release24-maint/Lib/email/Message.py	Wed Feb  8 15:58:55 2006
@@ -250,11 +250,14 @@
                             charset=charset.get_output_charset())
         else:
             self.set_param('charset', charset.get_output_charset())
+        if str(charset) <> charset.get_output_charset():
+            self._payload = charset.body_encode(self._payload)
         if not self.has_key('Content-Transfer-Encoding'):
             cte = charset.get_body_encoding()
             try:
                 cte(self)
             except TypeError:
+                self._payload = charset.body_encode(self._payload)
                 self.add_header('Content-Transfer-Encoding', cte)
 
     def get_charset(self):

Modified: python/branches/release24-maint/Lib/email/test/test_email.py
==============================================================================
--- python/branches/release24-maint/Lib/email/test/test_email.py	(original)
+++ python/branches/release24-maint/Lib/email/test/test_email.py	Wed Feb  8 15:58:55 2006
@@ -2221,7 +2221,8 @@
         charset = Charset(charsets[0])
         eq(charset.get_body_encoding(), 'base64')
         msg.set_payload('hello world', charset=charset)
-        eq(msg.get_payload(), 'hello world')
+        eq(msg.get_payload(), 'aGVsbG8gd29ybGQ=\n')
+        eq(msg.get_payload(decode=True), 'hello world')
         eq(msg['content-transfer-encoding'], 'base64')
         # Try another one
         msg = Message()

Modified: python/branches/release24-maint/Lib/email/test/test_email_codecs.py
==============================================================================
--- python/branches/release24-maint/Lib/email/test/test_email_codecs.py	(original)
+++ python/branches/release24-maint/Lib/email/test/test_email_codecs.py	Wed Feb  8 15:58:55 2006
@@ -1,4 +1,5 @@
-# Copyright (C) 2002 Python Software Foundation
+# Copyright (C) 2002-2006 Python Software Foundation
+# Contact: email-sig at python.org
 # email package unit tests for (optional) Asian codecs
 
 import unittest
@@ -7,6 +8,8 @@
 from email.test.test_email import TestEmailBase
 from email.Charset import Charset
 from email.Header import Header, decode_header
+from email.Message import Message
+
 
 
 class TestEmailAsianCodecs(TestEmailBase):
@@ -42,6 +45,14 @@
         # TK: full decode comparison
         eq(h.__unicode__().encode('euc-jp'), long)
 
+    def test_payload_encoding(self):
+        jhello = '\xa5\xcf\xa5\xed\xa1\xbc\xa5\xef\xa1\xbc\xa5\xeb\xa5\xc9\xa1\xaa'
+        jcode  = 'euc-jp'
+        msg = Message()
+        msg.set_payload(jhello, jcode)
+        ustr = unicode(msg.get_payload(), msg.get_content_charset())
+        self.assertEqual(jhello, ustr.encode(jcode))
+
 
 
 def suite():


More information about the Python-checkins mailing list