diff options
| author | Aurélien Bompard | 2013-10-21 16:00:59 +0200 |
|---|---|---|
| committer | Aurélien Bompard | 2013-10-21 16:00:59 +0200 |
| commit | a2687bb2f937410a5e16185745e315e94fa03d9e (patch) | |
| tree | d45bb8032a5dfbc44e2d4fc28ba751ea5a888447 /src | |
| parent | e3f8ad0d49104964ab14a9dfd0d60253d7d808c3 (diff) | |
| download | mailman-a2687bb2f937410a5e16185745e315e94fa03d9e.tar.gz mailman-a2687bb2f937410a5e16185745e315e94fa03d9e.tar.zst mailman-a2687bb2f937410a5e16185745e315e94fa03d9e.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/templates.py | 2 | ||||
| -rw-r--r-- | src/mailman/app/tests/test_templates.py | 11 | ||||
| -rw-r--r-- | src/mailman/utilities/tests/test_import.py | 21 |
3 files changed, 31 insertions, 3 deletions
diff --git a/src/mailman/app/templates.py b/src/mailman/app/templates.py index 707e7c256..f6b26811c 100644 --- a/src/mailman/app/templates.py +++ b/src/mailman/app/templates.py @@ -103,4 +103,4 @@ class TemplateLoader: def get(self, uri): """See `ITemplateLoader`.""" with closing(urllib2.urlopen(uri)) as fp: - return fp.read() + return unicode(fp.read(), "utf-8") diff --git a/src/mailman/app/tests/test_templates.py b/src/mailman/app/tests/test_templates.py index 77a0eb381..634d00907 100644 --- a/src/mailman/app/tests/test_templates.py +++ b/src/mailman/app/tests/test_templates.py @@ -126,3 +126,14 @@ class TestTemplateLoader(unittest.TestCase): with self.assertRaises(urllib2.URLError) as cm: self._loader.get('mailman:///missing@example.com/en/foo/demo.txt') self.assertEqual(cm.exception.reason, 'No such file') + + def test_non_ascii(self): + # mailman://demo.txt with non-ascii content + test_text = b'\xe4\xb8\xad' + path = os.path.join(self.var_dir, 'templates', 'site', 'it') + os.makedirs(path) + with open(os.path.join(path, 'demo.txt'), 'w') as fp: + print(test_text, end='', file=fp) + content = self._loader.get('mailman:///it/demo.txt') + self.assertTrue(isinstance(content, unicode)) + self.assertEqual(content, test_text.decode("utf-8")) diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py index bf757ba4b..f3e01c1a6 100644 --- a/src/mailman/utilities/tests/test_import.py +++ b/src/mailman/utilities/tests/test_import.py @@ -25,11 +25,13 @@ __all__ = [ ] +import os import cPickle import unittest from datetime import timedelta, datetime from traceback import format_exc +from mailman.config import config from mailman.app.lifecycle import create_list, remove_list from mailman.testing.layers import ConfigLayer from mailman.utilities.importer import import_config_pck, Import21Error @@ -515,6 +517,7 @@ class TestConvertToURI(unittest.TestCase): "Default value was not preserved for %s" % newvar) def test_unicode(self): + # non-ascii templates for oldvar in self._conf_mapping: self._pckdict[str(oldvar)] = b"Ol\xe1!" try: @@ -525,10 +528,24 @@ class TestConvertToURI(unittest.TestCase): for oldvar, newvar in self._conf_mapping.iteritems(): newattr = getattr(self._mlist, newvar) text = decorate(self._mlist, newattr) - expected = u'Ol\ufffd!'.encode("utf-8") - # we get bytestrings because the text is stored in a file + expected = u'Ol\ufffd!' self.assertEqual(text, expected) + def test_unicode_in_default(self): + # What if the default template is already in UTF-8? (like if you import twice) + footer = b'\xe4\xb8\xad $listinfo_uri' + footer_path = os.path.join(config.VAR_DIR, "templates", "lists", + "blank@example.com", "en", "footer-generic.txt") + try: + os.makedirs(os.path.dirname(footer_path)) + except OSError: + pass + with open(footer_path, "w") as footer_file: + footer_file.write(footer) + self._pckdict[b"msg_footer"] = b"NEW-VALUE" + import_config_pck(self._mlist, self._pckdict) + text = decorate(self._mlist, self._mlist.footer_uri) + self.assertEqual(text, 'NEW-VALUE') class TestRosterImport(unittest.TestCase): |
