Update of /cvsroot/mailman/mailman/Mailman
In directory sc8-pr-cvs1:/tmp/cvs-serv2534
Modified Files:
Tag: Release_2_1-maint
Utils.py
Log Message:
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.
Index: Utils.py
===================================================================
RCS file: /cvsroot/mailman/mailman/Mailman/Utils.py,v
retrieving revision 2.45.2.6
retrieving revision 2.45.2.7
diff -u -d -r2.45.2.6 -r2.45.2.7
--- Utils.py 1 Dec 2003 00:57:16 -0000 2.45.2.6
+++ Utils.py 26 Dec 2003 22:50:04 -0000 2.45.2.7
@@ -34,6 +34,7 @@
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 @@
False = 0
EMPTYSTRING = ''
+UEMPTYSTRING = u''
NL = '\n'
DOT = '.'
IDENTCHARS = ascii_letters + digits + '_'
@@ -794,6 +796,7 @@
# Nope, it contains funny characters, so html-ref it
return uquote(s)
+
def uquote(s):
a = []
for c in s:
@@ -804,3 +807,15 @@
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())
_______________________________________________
Mailman-checkins mailing list
[EMAIL PROTECTED]
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org