List:Commits« Previous MessageNext Message »
From:Chad MILLER Date:June 26 2008 3:30pm
Subject:bzr commit into mysql_plugins branch (chad:118)
View as plain text  
#At file:///home/cmiller/.bazaar/plugins/mysql/

  118 Chad MILLER	2008-06-26
      I don't really know if the revision properties are unicode or not
      (I suspect they aren't), so conditionally encode them to UTF-8.  I'm
      not especially happy with the condition.
      
      The previous "s.encode()" call assumed they were.  If they weren't,
      it would magically decode() it as ASCII first to get Unicode, then 
      perform the encode() step.
modified:
  emailer.py

=== modified file 'emailer.py'
--- a/emailer.py	2008-06-19 00:03:41 +0000
+++ b/emailer.py	2008-06-26 15:30:55 +0000
@@ -133,6 +133,7 @@ class EmailSender(object):
     def search_for_bugs(self, commit_message):
         """ scan entire log output for mentions of bugs, worklogs """
 
+        assert isinstance(commit_message, unicode)
         self.bug_ids_found = list(set(re.findall(r"(?i)\bbug[ ]*#[ ]*(\d+)",
                                                  commit_message.encode("utf8"))))
         self.worklog_ids_found = list(set(re.findall(r"(?i)\bwl[ ]*#[ ]*(\d+)",
@@ -154,7 +155,7 @@ class EmailSender(object):
         produces the body of the email
         """
         if self._body is None:
-            self._body = ""
+            self._body = u""
         return self._body
 
     def get_diff(self):
@@ -317,13 +318,18 @@ class EmailSender(object):
 
 
     def per_file_messages_as_string(self, a_revision):
-        """ Concatenates all file messages for inclusion in the email """
+        """Concatenates all file messages for inclusion in the email,
+        returning a utf-8 encoded string."""
         # see revisionview.py in bzr-gtk plugin: per-file messages are in
         # property 'file-info' and bencode/decode-d.
         file_info = a_revision.properties.get('file-info', None)
         if file_info is None:
             return ''
-        file_info = bencode.bdecode(file_info.encode('UTF-8'))
+
+        if isinstance(file_info, unicode):
+            file_info = file_info.encode("utf-8")
+
+        file_info = bencode.bdecode(file_info)
         if not file_info:
             return ''
         text = ''
@@ -427,6 +433,7 @@ class CommitSender(EmailSender):
             # Decode the stuff planned for output to get Unicode.
             self._body = outf.getvalue().decode(self.encoding)
 
+        assert isinstance(self._body, unicode)
         return self._body
 
 class PushSender(EmailSender):
@@ -470,6 +477,7 @@ class PushSender(EmailSender):
             self._body = outf.getvalue().decode(self.encoding)
             note("Sending post-push message")
 
+        assert isinstance(self._body, unicode)
         return self._body
 
     def get_diff(self):

Thread
bzr commit into mysql_plugins branch (chad:118) Chad MILLER26 Jun