summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2014-12-16 21:35:49 -0500
committerBarry Warsaw2014-12-16 21:35:49 -0500
commit75ff7330c91c0fb5d5e77fc3c61259e20fca99e8 (patch)
tree341179e305e9a69ee873182bbb467b2668938a7e /src
parent2887baf92ba3e0a0a26c94a0fca3c5f412a7cd48 (diff)
downloadmailman-75ff7330c91c0fb5d5e77fc3c61259e20fca99e8.tar.gz
mailman-75ff7330c91c0fb5d5e77fc3c61259e20fca99e8.tar.zst
mailman-75ff7330c91c0fb5d5e77fc3c61259e20fca99e8.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/utilities/importer.py17
-rw-r--r--src/mailman/utilities/tests/test_import.py12
2 files changed, 17 insertions, 12 deletions
diff --git a/src/mailman/utilities/importer.py b/src/mailman/utilities/importer.py
index 89ed39908..c93080c91 100644
--- a/src/mailman/utilities/importer.py
+++ b/src/mailman/utilities/importer.py
@@ -27,7 +27,6 @@ __all__ = [
import os
-import six
import sys
import codecs
import datetime
@@ -72,8 +71,10 @@ def bytes_to_str(value):
return value.decode('ascii', 'replace')
-def unicode_to_string(value):
- return None if value is None else str(value)
+def str_to_bytes(value):
+ if value is None or isinstance(value, bytes):
+ return value
+ return value.encode('utf-8')
def seconds_to_delta(value):
@@ -171,7 +172,7 @@ TYPES = dict(
forward_unrecognized_bounces_to=UnrecognizedBounceDisposition,
gateway_to_mail=bool,
include_rfc2369_headers=bool,
- moderator_password=unicode_to_string,
+ moderator_password=str_to_bytes,
newsgroup_moderation=NewsgroupModeration,
nntp_prefix_subject_too=bool,
pass_extensions=list_members_to_unicode,
@@ -246,7 +247,7 @@ def import_config_pck(mlist, config_dict):
# If the mailing list has a preferred language that isn't registered
# in the configuration file, hasattr() will swallow the KeyError this
# raises and return False. Treat that attribute specially.
- if hasattr(mlist, key) or key == 'preferred_language':
+ if key == 'preferred_language' or hasattr(mlist, key):
if isinstance(value, bytes):
value = bytes_to_str(value)
# Some types require conversion.
@@ -285,9 +286,9 @@ def import_config_pck(mlist, config_dict):
ban_manager.ban(bytes_to_str(address))
# Handle acceptable aliases.
acceptable_aliases = config_dict.get('acceptable_aliases', '')
- if isinstance(acceptable_aliases, six.string_types):
- if isinstance(acceptable_aliases, bytes):
- acceptable_aliases = acceptable_aliases.decode('utf-8')
+ if isinstance(acceptable_aliases, bytes):
+ acceptable_aliases = acceptable_aliases.decode('utf-8')
+ if isinstance(acceptable_aliases, str):
acceptable_aliases = acceptable_aliases.splitlines()
alias_set = IAcceptableAliasSet(mlist)
for address in acceptable_aliases:
diff --git a/src/mailman/utilities/tests/test_import.py b/src/mailman/utilities/tests/test_import.py
index ec629a653..09d2f351c 100644
--- a/src/mailman/utilities/tests/test_import.py
+++ b/src/mailman/utilities/tests/test_import.py
@@ -180,7 +180,7 @@ class TestBasicImport(unittest.TestCase):
def test_moderator_password(self):
# mod_password -> moderator_password
- self._mlist.moderator_password = str('TESTDATA')
+ self._mlist.moderator_password = b'TESTDATA'
self._import()
self.assertEqual(self._mlist.moderator_password, None)
@@ -611,6 +611,8 @@ class TestRosterImport(unittest.TestCase):
self._usermanager = getUtility(IUserManager)
language_manager = getUtility(ILanguageManager)
for code in self._pckdict['language'].values():
+ if isinstance(code, bytes):
+ code = code.decode('utf-8')
if code not in language_manager.codes:
language_manager.add(code, 'utf-8', code)
@@ -643,8 +645,10 @@ class TestRosterImport(unittest.TestCase):
addr = '%s@example.com' % name
member = self._mlist.members.get_member(addr)
self.assertIsNotNone(member, 'Address %s was not imported' % addr)
- self.assertEqual(member.preferred_language.code,
- self._pckdict['language'][addr])
+ code = self._pckdict['language'][addr]
+ if isinstance(code, bytes):
+ code = code.decode('utf-8')
+ self.assertEqual(member.preferred_language.code, code)
def test_new_language(self):
self._pckdict['language']['anne@example.com'] = b'xx_XX'
@@ -700,7 +704,7 @@ class TestRosterImport(unittest.TestCase):
user = self._usermanager.get_user(addr)
self.assertIsNotNone(user, 'Address %s was not imported' % addr)
self.assertEqual(
- user.password, b'{plaintext}%spass' % name,
+ user.password, '{plaintext}%spass' % name,
'Password for %s was not imported' % addr)
def test_same_user(self):