Revision: 8172
          http://svn.sourceforge.net/mailman/?rev=8172&view=rev
Author:   bwarsaw
Date:     2007-03-21 14:16:56 -0700 (Wed, 21 Mar 2007)

Log Message:
-----------
A few style fixes based on commit reviews.

Switchboard.py
    - Use listname.encode('utf-8') to produce the necessary 8-bit string,
      instead of str(listname).  Also update the preceding comment.

senddigests.py
    - Remove an unnecessary import.

Decorate.py
    - Remove a commented out section of code.
    - Remove some redundant local variables
    - Reorganize the section that's trying to find a usable encoding for the
      payload of the modified message.  I don't think it really hurts much to
      try duplicate charsets when lcset == mcset, or when either == utf-8.
      Just go ahead and try them and let them fail.  This simplifies the code.

      Also, try to get just the minimum necessary code under the
      UnicodeError.  I think it's enough to catch the payload.encode() call.

Modified Paths:
--------------
    trunk/mailman/Mailman/Handlers/Decorate.py
    trunk/mailman/Mailman/Queue/Switchboard.py
    trunk/mailman/Mailman/bin/senddigests.py

Modified: trunk/mailman/Mailman/Handlers/Decorate.py
===================================================================
--- trunk/mailman/Mailman/Handlers/Decorate.py  2007-03-21 14:11:53 UTC (rev 
8171)
+++ trunk/mailman/Mailman/Handlers/Decorate.py  2007-03-21 21:16:56 UTC (rev 
8172)
@@ -50,10 +50,6 @@
             d['user_password'] = mlist.getMemberPassword(member)
             d['user_language'] = mlist.getMemberLanguage(member)
             username = mlist.getMemberName(member) or None
-            #try:
-            #    username = 
username.encode(Utils.GetCharSet(d['user_language']))
-            #except (AttributeError, UnicodeError):
-            #    username = member
             d['user_name'] = username or d['user_delivered_to']
             d['user_optionsurl'] = mlist.GetOptionsURL(member)
         except Errors.NotAMemberError:
@@ -89,8 +85,6 @@
     wrap = True
     if not msg.is_multipart() and msgtype == 'text/plain':
         # header/footer is now in unicode (2.2)
-        uheader = header
-        ufooter = footer
         try:
             oldpayload = unicode(msg.get_payload(decode=True), mcset)
             frontsep = endsep = u''
@@ -98,24 +92,22 @@
                 frontsep = u'\n'
             if footer and not oldpayload.endswith('\n'):
                 endsep = u'\n'
-            payload = uheader + frontsep + oldpayload + endsep + ufooter
-            # Try to set message in list charset then message charset.
-            # Fall back to 'utf-8' if both doesn't work.
-            csets = [lcset,]
-            if mcset != lcset:
-                csets.append(mcset)
-            if 'utf-8' not in csets:
-                csets.append('utf-8')
-            for cset in csets:
+            payload = header + frontsep + oldpayload + endsep + footer
+            # When setting the payload for the message, try various charset
+            # encodings until one does not produce a UnicodeError.  We'll try
+            # charsets in this order: the list's charset, the message's
+            # charset, then utf-8.  It's okay if some of these are duplicates.
+            for cset in (lcset, mcset, 'utf-8'):
                 try:
                     payload = payload.encode(cset)
+                except UnicodeError:
+                    pass
+                else:
                     del msg['content-transfer-encoding']
                     del msg['content-type']
                     msg.set_payload(payload, cset)
                     wrap = False
                     break
-                except UnicodeError:
-                    continue
         except (LookupError, UnicodeError):
             pass
     elif msg.get_content_type() == 'multipart/mixed':

Modified: trunk/mailman/Mailman/Queue/Switchboard.py
===================================================================
--- trunk/mailman/Mailman/Queue/Switchboard.py  2007-03-21 14:11:53 UTC (rev 
8171)
+++ trunk/mailman/Mailman/Queue/Switchboard.py  2007-03-21 21:16:56 UTC (rev 
8172)
@@ -94,7 +94,9 @@
         else:
             protocol = 0
             msgsave = cPickle.dumps(str(_msg), protocol)
-        hashfood = msgsave + str(listname) + `now`
+        # listname is unicode but the input to the hash function must be an
+        # 8-bit string (eventually, a bytes object).
+        hashfood = msgsave + listname.encode('utf-8') + `now`
         # Encode the current time into the file name for FIFO sorting in
         # files().  The file name consists of two parts separated by a `+':
         # the received time for this message (i.e. when it first showed up on

Modified: trunk/mailman/Mailman/bin/senddigests.py
===================================================================
--- trunk/mailman/Mailman/bin/senddigests.py    2007-03-21 14:11:53 UTC (rev 
8171)
+++ trunk/mailman/Mailman/bin/senddigests.py    2007-03-21 21:16:56 UTC (rev 
8172)
@@ -21,7 +21,6 @@
 from Mailman import MailList
 from Mailman import Utils
 from Mailman import Version
-from Mailman.configuration import config
 from Mailman.i18n import _
 from Mailman.initialize import initialize
 


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe: 
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org

Reply via email to