Rev 2641: (John Arbash Meinel) Small updates for EmailMessage for python2.5 compatibility in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Fri Jul 20 17:15:50 BST 2007


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 2641
revision-id: pqm at pqm.ubuntu.com-20070720161548-nppg3mvd38gbuaid
parent: pqm at pqm.ubuntu.com-20070720151346-fhgw7wgtkuc1fdvj
parent: john at arbash-meinel.com-20070720144248-6qltqb2tkm9x49lw
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Fri 2007-07-20 17:15:48 +0100
message:
  (John Arbash Meinel) Small updates for EmailMessage for python2.5 compatibility
modified:
  bzrlib/email_message.py        email_message.py-20070718143823-660zfcl54xi1v65u-1
  bzrlib/tests/test_email_message.py test_email_message.p-20070718143823-660zfcl54xi1v65u-2
    ------------------------------------------------------------
    revno: 2639.1.2
    merged: john at arbash-meinel.com-20070720144248-6qltqb2tkm9x49lw
    parent: john at arbash-meinel.com-20070720142859-a24s0khul0yw91bh
    committer: John Arbash Meinel <john at arbash-meinel.com>
    branch nick: jam-integration
    timestamp: Fri 2007-07-20 09:42:48 -0500
    message:
      Some cleanups for the EmailMessage class.
      Remove self._msgobj as it can lead to reporting incorrect cached data.
      Update tests for changes in python2.5, adding similar strings
      into a dictionary, with one being unicode and the other string
      causes a UnicodeWarning.
=== modified file 'bzrlib/email_message.py'
--- a/bzrlib/email_message.py	2007-07-19 21:22:53 +0000
+++ b/bzrlib/email_message.py	2007-07-20 14:42:48 +0000
@@ -57,7 +57,6 @@
         self._headers = {}
         self._body = body
         self._parts = []
-        self._msgobj = None
 
         if isinstance(to_address, basestring):
             to_address = [ to_address ]
@@ -93,7 +92,6 @@
             self._body = None
 
         self._parts.append((body, filename, mime_subtype))
-        self._msgobj = None
 
     def as_string(self, boundary=None):
         """Return the entire formatted message as a string.
@@ -101,19 +99,16 @@
         :param boundary: The boundary to use between MIME parts, if applicable.
             Used for tests.
         """
-        if self._msgobj is not None:
-            return self._msgobj.as_string()
-
         if not self._parts:
-            self._msgobj = Message.Message()
+            msgobj = Message.Message()
             if self._body is not None:
                 body, encoding = self.string_with_encoding(self._body)
-                self._msgobj.set_payload(body, encoding)
+                msgobj.set_payload(body, encoding)
         else:
-            self._msgobj = MIMEMultipart.MIMEMultipart()
+            msgobj = MIMEMultipart.MIMEMultipart()
 
             if boundary is not None:
-                self._msgobj.set_boundary(boundary)
+                msgobj.set_boundary(boundary)
 
             for body, filename, mime_subtype in self._parts:
                 body, encoding = self.string_with_encoding(body)
@@ -125,13 +120,13 @@
                     payload.replace_header('Content-Type', content_type)
 
                 payload['Content-Disposition'] = 'inline'
-                self._msgobj.attach(payload)
+                msgobj.attach(payload)
 
         # sort headers here to ease testing
         for header, value in sorted(self._headers.items()):
-            self._msgobj[header] = value
+            msgobj[header] = value
 
-        return self._msgobj.as_string()
+        return msgobj.as_string()
 
     __str__ = as_string
 

=== modified file 'bzrlib/tests/test_email_message.py'
--- a/bzrlib/tests/test_email_message.py	2007-07-19 21:22:53 +0000
+++ b/bzrlib/tests/test_email_message.py	2007-07-20 14:42:48 +0000
@@ -43,7 +43,7 @@
 
 SIMPLE_MESSAGE_ASCII = _SIMPLE_MESSAGE % ('us-ascii', '7bit', 'body')
 SIMPLE_MESSAGE_UTF8 = _SIMPLE_MESSAGE % ('utf-8', 'base64', 'YsOzZHk=\n')
-SIMPLE_MESSAGE_8BIT = _SIMPLE_MESSAGE % ('8-bit', 'base64', 'YvNkeQ==\n')
+SIMPLE_MESSAGE_8BIT = _SIMPLE_MESSAGE % ('8-bit', 'base64', 'YvRkeQ==\n')
 
 
 BOUNDARY = '=====123456=='
@@ -94,7 +94,7 @@
             'body': SIMPLE_MESSAGE_ASCII,
             u'b\xf3dy': SIMPLE_MESSAGE_UTF8,
             'b\xc3\xb3dy': SIMPLE_MESSAGE_UTF8,
-            'b\xf3dy': SIMPLE_MESSAGE_8BIT,
+            'b\xf4dy': SIMPLE_MESSAGE_8BIT,
         }
         for body, expected in pairs.items():
             msg = EmailMessage('from at from.com', 'to at to.com', 'subject', body)
@@ -220,7 +220,7 @@
                 u'P\xe9rez':    ('P\xc3\xa9rez', 'utf-8'),
                 'Perez':         ('Perez', 'ascii'), # u'Pepe' == 'Pepe'
                 'P\xc3\xa9rez': ('P\xc3\xa9rez', 'utf-8'),
-                'P\xe9rez':     ('P\xe9rez', '8-bit'),
+                'P\xe8rez':     ('P\xe8rez', '8-bit'),
         }
         for string_, pair in pairs.items():
             self.assertEqual(pair, EmailMessage.string_with_encoding(string_))




More information about the bazaar-commits mailing list