summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbwarsaw2003-01-20 02:48:18 +0000
committerbwarsaw2003-01-20 02:48:18 +0000
commitcb051571464241022bec312d78d5b3da320c5f5b (patch)
tree31503de440a5353dcd4eca190ff023d4778e03da
parentfdbf0aad277d5b47be35ccecfb809e9cf4a9827e (diff)
downloadmailman-cb051571464241022bec312d78d5b3da320c5f5b.tar.gz
mailman-cb051571464241022bec312d78d5b3da320c5f5b.tar.zst
mailman-cb051571464241022bec312d78d5b3da320c5f5b.zip
A few minor refinements to the previous patch.
guess_all_extensions(): Python 2.1 doesn't have mimetypes.common_types. guess_extension(): all could be empty. process(): Need separate try/except clauses for the conversion to unicode, and the conversion to 8-bit strings. Also, use endswith() instead of t[-1] to be more robust against empty strings.
-rw-r--r--Mailman/Handlers/Scrubber.py16
1 files changed, 10 insertions, 6 deletions
diff --git a/Mailman/Handlers/Scrubber.py b/Mailman/Handlers/Scrubber.py
index 3ba64b945..6cc9aa39b 100644
--- a/Mailman/Handlers/Scrubber.py
+++ b/Mailman/Handlers/Scrubber.py
@@ -64,7 +64,8 @@ except ImportError:
if t == ctype:
all.append(e)
check(mimetypes.types_map)
- if not strict:
+ # Python 2.1 doesn't have common_types. Sigh, sigh.
+ if not strict and hasattr(mimetypes, 'common_types'):
check(mimetypes.common_types)
return all
@@ -78,7 +79,7 @@ def guess_extension(ctype, ext):
all = guess_all_extensions(ctype, strict=0)
if ext in all:
return ext
- return all[0]
+ return all and all[0]
@@ -299,13 +300,16 @@ Url : %(url)s
if partcharset and partcharset <> charset:
try:
t = unicode(t, partcharset, 'replace')
- # Should use HTML-Escape, or try generalizing to UTF-8
- t = t.encode(charset, 'replace')
- except UnicodeError:
+ except (UnicodeError, LookupError):
# Replace funny characters
t = unicode(t, 'ascii', 'replace').encode('ascii')
+ try:
+ # Should use HTML-Escape, or try generalizing to UTF-8
+ t = t.encode(charset, 'replace')
+ except (UnicodeError, LookupError):
+ t = t.encode(lcset, 'replace')
# Separation is useful
- if t[-1] <> '\n':
+ if not t.endswith('\n'):
t += '\n'
text.append(t)
# Now join the text and set the payload