diff options
| author | bwarsaw | 2007-03-21 21:16:56 +0000 |
|---|---|---|
| committer | bwarsaw | 2007-03-21 21:16:56 +0000 |
| commit | cdefb7ba2792083a520f8dc40993a0f946ad3434 (patch) | |
| tree | 9db25722807381a8bae8cf28e4354c4aa68ffb5d | |
| parent | fc51f4c9de9751c03fb21394b393253e8c225453 (diff) | |
| download | mailman-cdefb7ba2792083a520f8dc40993a0f946ad3434.tar.gz mailman-cdefb7ba2792083a520f8dc40993a0f946ad3434.tar.zst mailman-cdefb7ba2792083a520f8dc40993a0f946ad3434.zip | |
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.
| -rw-r--r-- | Mailman/Handlers/Decorate.py | 26 | ||||
| -rw-r--r-- | Mailman/Queue/Switchboard.py | 4 | ||||
| -rw-r--r-- | Mailman/bin/senddigests.py | 1 |
3 files changed, 12 insertions, 19 deletions
diff --git a/Mailman/Handlers/Decorate.py b/Mailman/Handlers/Decorate.py index a5712947c..0b135b5ce 100644 --- a/Mailman/Handlers/Decorate.py +++ b/Mailman/Handlers/Decorate.py @@ -50,10 +50,6 @@ def process(mlist, msg, msgdata): 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 @@ def process(mlist, msg, msgdata): 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 @@ def process(mlist, msg, msgdata): 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': diff --git a/Mailman/Queue/Switchboard.py b/Mailman/Queue/Switchboard.py index 43d121f6f..fabb1d099 100644 --- a/Mailman/Queue/Switchboard.py +++ b/Mailman/Queue/Switchboard.py @@ -94,7 +94,9 @@ class Switchboard: 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 diff --git a/Mailman/bin/senddigests.py b/Mailman/bin/senddigests.py index 9fc5fad0c..96e3cfabd 100644 --- a/Mailman/bin/senddigests.py +++ b/Mailman/bin/senddigests.py @@ -21,7 +21,6 @@ import optparse 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 |
