summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2011-02-26 21:27:25 -0500
committerBarry Warsaw2011-02-26 21:27:25 -0500
commit2c562fd0191b0af04511dad2b0d0ae57b31198e7 (patch)
treecb4676ece952846f2015c72e2e40c67c8b8c7398
parentca35b80852bd04d5cd39bf494554f8b15e2de048 (diff)
downloadmailman-2c562fd0191b0af04511dad2b0d0ae57b31198e7.tar.gz
mailman-2c562fd0191b0af04511dad2b0d0ae57b31198e7.tar.zst
mailman-2c562fd0191b0af04511dad2b0d0ae57b31198e7.zip
-rw-r--r--src/mailman/Archiver/HyperArch.py8
-rw-r--r--src/mailman/Utils.py38
-rw-r--r--src/mailman/utilities/string.py39
3 files changed, 43 insertions, 42 deletions
diff --git a/src/mailman/Archiver/HyperArch.py b/src/mailman/Archiver/HyperArch.py
index 9d219585d..218c46875 100644
--- a/src/mailman/Archiver/HyperArch.py
+++ b/src/mailman/Archiver/HyperArch.py
@@ -50,7 +50,7 @@ from mailman.Archiver import pipermail
from mailman.config import config
from mailman.core.i18n import _, ctime
from mailman.interfaces.listmanager import IListManager
-from mailman.utilities.string import websafe
+from mailman.utilities.string import uncanonstr, websafe
log = logging.getLogger('mailman.error')
@@ -86,7 +86,7 @@ def html_quote(s, langcode=None):
('"', '"'))
for thing, repl in repls:
s = s.replace(thing, repl)
- return Utils.uncanonstr(s, langcode)
+ return uncanonstr(s, langcode)
def url_quote(s):
@@ -123,7 +123,7 @@ def CGIescape(arg, lang=None):
s = websafe(arg)
else:
s = websafe(str(arg))
- return Utils.uncanonstr(s.replace('"', '"'), lang.code)
+ return uncanonstr(s.replace('"', '"'), lang.code)
# Parenthesized human name
paren_name_pat = re.compile(r'([(].*[)])')
@@ -202,7 +202,7 @@ def quick_maketext(templatefile, dict=None, lang=None, mlist=None):
pass
# Make sure the text is in the given character set, or html-ify any bogus
# characters.
- return Utils.uncanonstr(text, lang.code)
+ return uncanonstr(text, lang.code)
diff --git a/src/mailman/Utils.py b/src/mailman/Utils.py
index 3989947c4..a58ed1d24 100644
--- a/src/mailman/Utils.py
+++ b/src/mailman/Utils.py
@@ -260,41 +260,3 @@ def findtext(templatefile, raw_dict=None, raw=False, lang=None, mlist=None):
def maketext(templatefile, dict=None, raw=False, lang=None, mlist=None):
return findtext(templatefile, dict, raw, lang, mlist)[0]
-
-
-
-# The opposite of canonstr() -- sorta. I.e. it attempts to encode s in the
-# charset of the given language, which is the character set that the page will
-# be rendered in, and failing that, replaces non-ASCII characters with their
-# html references. It always returns a byte string.
-def uncanonstr(s, lang=None):
- if s is None:
- s = u''
- if lang is None:
- charset = 'us-ascii'
- else:
- charset = getUtility(ILanguageManager)[lang].charset
- # See if the string contains characters only in the desired character
- # set. If so, return it unchanged, except for coercing it to a byte
- # string.
- try:
- if isinstance(s, unicode):
- return s.encode(charset)
- else:
- unicode(s, charset)
- return s
- except UnicodeError:
- # Nope, it contains funny characters, so html-ref it
- return uquote(s)
-
-
-def uquote(s):
- a = []
- for c in s:
- o = ord(c)
- if o > 127:
- a.append('&#%3d;' % o)
- else:
- a.append(c)
- # Join characters together and coerce to byte string
- return str(EMPTYSTRING.join(a))
diff --git a/src/mailman/utilities/string.py b/src/mailman/utilities/string.py
index 113403c96..3eda0dc39 100644
--- a/src/mailman/utilities/string.py
+++ b/src/mailman/utilities/string.py
@@ -23,6 +23,7 @@ __metaclass__ = type
__all__ = [
'expand',
'oneline',
+ 'uncanonstr',
'websafe',
]
@@ -33,6 +34,10 @@ import logging
from email.errors import HeaderParseError
from email.header import decode_header, make_header
from string import Template
+from zope.component import getUtility
+
+from mailman.interfaces.languages import ILanguageManager
+
EMPTYSTRING = ''
UEMPTYSTRING = u''
@@ -99,3 +104,37 @@ def oneline(s, cset='us-ascii', in_unicode=False):
def websafe(s):
return cgi.escape(s, quote=True)
+
+
+
+# The opposite of canonstr() -- sorta. I.e. it attempts to encode s in the
+# charset of the given language, which is the character set that the page will
+# be rendered in, and failing that, replaces non-ASCII characters with their
+# html references. It always returns a byte string.
+def uncanonstr(s, lang=None):
+ if s is None:
+ s = u''
+ if lang is None:
+ charset = 'us-ascii'
+ else:
+ charset = getUtility(ILanguageManager)[lang].charset
+ # See if the string contains characters only in the desired character
+ # set. If so, return it unchanged, except for coercing it to a byte
+ # string.
+ try:
+ if isinstance(s, unicode):
+ return s.encode(charset)
+ else:
+ unicode(s, charset)
+ return s
+ except UnicodeError:
+ # Nope, it contains funny characters, so html-ref it
+ a = []
+ for c in s:
+ o = ord(c)
+ if o > 127:
+ a.append('&#%3d;' % o)
+ else:
+ a.append(c)
+ # Join characters together and coerce to byte string
+ return str(EMPTYSTRING.join(a))