aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbwarsaw <>2003-12-26 22:50:04 +0000
committerbwarsaw <>2003-12-26 22:50:04 +0000
commit95e3d60bf33db57cd326a665baa9d7db3b3021b8 (patch)
tree49da7b585adb9e6af990022940cdc609777178ee
parent63d1e846b4ba4d5ee7befe767a94f0ec1319081d (diff)
downloadmailman2-95e3d60bf33db57cd326a665baa9d7db3b3021b8.tar.gz
mailman2-95e3d60bf33db57cd326a665baa9d7db3b3021b8.tar.xz
mailman2-95e3d60bf33db57cd326a665baa9d7db3b3021b8.zip
oneline(): Another part of TK's patch # 865661. This one adds a
utility function that returns a header in an i18n-safe way such that it is guaranteed to span exactly one line.
-rw-r--r--Mailman/Utils.py15
1 files changed, 15 insertions, 0 deletions
diff --git a/Mailman/Utils.py b/Mailman/Utils.py
index 43665d9d..54e63ddf 100644
--- a/Mailman/Utils.py
+++ b/Mailman/Utils.py
@@ -34,6 +34,7 @@ import errno
import time
import cgi
import htmlentitydefs
+import email.Header
import email.Iterators
from types import UnicodeType
from string import whitespace, digits
@@ -57,6 +58,7 @@ except NameError:
False = 0
EMPTYSTRING = ''
+UEMPTYSTRING = u''
NL = '\n'
DOT = '.'
IDENTCHARS = ascii_letters + digits + '_'
@@ -794,6 +796,7 @@ def uncanonstr(s, lang=None):
# Nope, it contains funny characters, so html-ref it
return uquote(s)
+
def uquote(s):
a = []
for c in s:
@@ -804,3 +807,15 @@ def uquote(s):
a.append(c)
# Join characters together and coerce to byte string
return str(EMPTYSTRING.join(a))
+
+
+def oneline(s, cset):
+ # Decode header string in one line and convert into specified charset
+ try:
+ h = email.Header.make_header(email.Header.decode_header(s))
+ ustr = h.__unicode__()
+ line = UEMPTYSTRING.join(ustr.splitlines())
+ return line.encode(cset, 'replace')
+ except (LookupError, UnicodeError):
+ # possibly charset problem. return with undecoded string in one line.
+ return EMPTYSTRING.join(s.splitlines())