diff options
Diffstat (limited to 'src/mailman/rest')
| -rw-r--r-- | src/mailman/rest/addresses.py | 6 | ||||
| -rw-r--r-- | src/mailman/rest/configuration.py | 26 | ||||
| -rw-r--r-- | src/mailman/rest/docs/helpers.rst | 5 | ||||
| -rw-r--r-- | src/mailman/rest/domains.py | 10 | ||||
| -rw-r--r-- | src/mailman/rest/lists.py | 6 | ||||
| -rw-r--r-- | src/mailman/rest/members.py | 12 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_addresses.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_domains.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_lists.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_membership.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_moderation.py | 3 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_preferences.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_root.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/tests/test_users.py | 5 | ||||
| -rw-r--r-- | src/mailman/rest/users.py | 12 | ||||
| -rw-r--r-- | src/mailman/rest/validator.py | 2 |
16 files changed, 59 insertions, 52 deletions
diff --git a/src/mailman/rest/addresses.py b/src/mailman/rest/addresses.py index fa3d099b6..7923d8bf9 100644 --- a/src/mailman/rest/addresses.py +++ b/src/mailman/rest/addresses.py @@ -27,6 +27,8 @@ __all__ = [ ] +import six + from operator import attrgetter from zope.component import getUtility @@ -186,8 +188,8 @@ class UserAddresses(_AddressBase): not_found(response) return user_manager = getUtility(IUserManager) - validator = Validator(email=unicode, - display_name=unicode, + validator = Validator(email=six.text_type, + display_name=six.text_type, _optional=('display_name',)) try: address = user_manager.create_address(**validator(request)) diff --git a/src/mailman/rest/configuration.py b/src/mailman/rest/configuration.py index b432268c7..6ea78f90e 100644 --- a/src/mailman/rest/configuration.py +++ b/src/mailman/rest/configuration.py @@ -25,6 +25,8 @@ __all__ = [ ] +import six + from lazr.config import as_boolean, as_timedelta from mailman.config import config from mailman.core.errors import ( @@ -61,7 +63,7 @@ class AcceptableAliases(GetterSetter): alias_set = IAcceptableAliasSet(mlist) alias_set.clear() for alias in value: - alias_set.add(unicode(alias)) + alias_set.add(alias.decode('utf-8')) @@ -71,13 +73,13 @@ class AcceptableAliases(GetterSetter): def pipeline_validator(pipeline_name): """Convert the pipeline name to a string, but only if it's known.""" if pipeline_name in config.pipelines: - return unicode(pipeline_name) + return pipeline_name.decode('utf-8') raise ValueError('Unknown pipeline: {}'.format(pipeline_name)) def list_of_unicode(values): """Turn a list of things into a list of unicodes.""" - return [unicode(value) for value in values] + return [value.decode('utf-8') for value in values] @@ -106,9 +108,9 @@ ATTRIBUTES = dict( autorespond_postings=GetterSetter(enum_validator(ResponseAction)), autorespond_requests=GetterSetter(enum_validator(ResponseAction)), autoresponse_grace_period=GetterSetter(as_timedelta), - autoresponse_owner_text=GetterSetter(unicode), - autoresponse_postings_text=GetterSetter(unicode), - autoresponse_request_text=GetterSetter(unicode), + autoresponse_owner_text=GetterSetter(six.text_type), + autoresponse_postings_text=GetterSetter(six.text_type), + autoresponse_request_text=GetterSetter(six.text_type), archive_policy=GetterSetter(enum_validator(ArchivePolicy)), bounces_address=GetterSetter(None), collapse_alternatives=GetterSetter(as_boolean), @@ -116,7 +118,7 @@ ATTRIBUTES = dict( created_at=GetterSetter(None), default_member_action=GetterSetter(enum_validator(Action)), default_nonmember_action=GetterSetter(enum_validator(Action)), - description=GetterSetter(unicode), + description=GetterSetter(six.text_type), digest_last_sent_at=GetterSetter(None), digest_size_threshold=GetterSetter(float), filter_content=GetterSetter(as_boolean), @@ -135,21 +137,21 @@ ATTRIBUTES = dict( post_id=GetterSetter(None), posting_address=GetterSetter(None), posting_pipeline=GetterSetter(pipeline_validator), - display_name=GetterSetter(unicode), + display_name=GetterSetter(six.text_type), reply_goes_to_list=GetterSetter(enum_validator(ReplyToMunging)), - reply_to_address=GetterSetter(unicode), + reply_to_address=GetterSetter(six.text_type), request_address=GetterSetter(None), scheme=GetterSetter(None), send_welcome_message=GetterSetter(as_boolean), - subject_prefix=GetterSetter(unicode), + subject_prefix=GetterSetter(six.text_type), volume=GetterSetter(None), web_host=GetterSetter(None), - welcome_message_uri=GetterSetter(unicode), + welcome_message_uri=GetterSetter(six.text_type), ) VALIDATORS = ATTRIBUTES.copy() -for attribute, gettersetter in VALIDATORS.items(): +for attribute, gettersetter in list(VALIDATORS.items()): if gettersetter.decoder is None: del VALIDATORS[attribute] diff --git a/src/mailman/rest/docs/helpers.rst b/src/mailman/rest/docs/helpers.rst index 5bcf5cad4..2dd65bbb8 100644 --- a/src/mailman/rest/docs/helpers.rst +++ b/src/mailman/rest/docs/helpers.rst @@ -69,8 +69,9 @@ Another helper unpacks ``POST`` and ``PUT`` request variables, validating and converting their values. :: + >>> import six >>> from mailman.rest.validator import Validator - >>> validator = Validator(one=int, two=unicode, three=bool) + >>> validator = Validator(one=int, two=six.text_type, three=bool) >>> class FakeRequest: ... params = None @@ -119,7 +120,7 @@ Extra keys are also not allowed. However, if optional keys are missing, it's okay. :: - >>> validator = Validator(one=int, two=unicode, three=bool, + >>> validator = Validator(one=int, two=six.text_type, three=bool, ... four=int, five=int, ... _optional=('four', 'five')) diff --git a/src/mailman/rest/domains.py b/src/mailman/rest/domains.py index 5d36dcab9..bd221abeb 100644 --- a/src/mailman/rest/domains.py +++ b/src/mailman/rest/domains.py @@ -26,6 +26,8 @@ __all__ = [ ] +import six + from mailman.interfaces.domain import ( BadDomainSpecificationError, IDomainManager) from mailman.rest.helpers import ( @@ -99,10 +101,10 @@ class AllDomains(_DomainBase): """Create a new domain.""" domain_manager = getUtility(IDomainManager) try: - validator = Validator(mail_host=unicode, - description=unicode, - base_url=unicode, - contact_address=unicode, + validator = Validator(mail_host=six.text_type, + description=six.text_type, + base_url=six.text_type, + contact_address=six.text_type, _optional=('description', 'base_url', 'contact_address')) domain = domain_manager.add(**validator(request)) diff --git a/src/mailman/rest/lists.py b/src/mailman/rest/lists.py index 580b6e898..feaa96323 100644 --- a/src/mailman/rest/lists.py +++ b/src/mailman/rest/lists.py @@ -30,6 +30,8 @@ __all__ = [ ] +import six + from lazr.config import as_boolean from operator import attrgetter from zope.component import getUtility @@ -204,8 +206,8 @@ class AllLists(_ListBase): def on_post(self, request, response): """Create a new mailing list.""" try: - validator = Validator(fqdn_listname=unicode, - style_name=unicode, + validator = Validator(fqdn_listname=six.text_type, + style_name=six.text_type, _optional=('style_name',)) mlist = create_list(**validator(request)) except ListAlreadyExistsError: diff --git a/src/mailman/rest/members.py b/src/mailman/rest/members.py index 4d1c87b73..b63f65658 100644 --- a/src/mailman/rest/members.py +++ b/src/mailman/rest/members.py @@ -28,6 +28,8 @@ __all__ = [ ] +import six + from uuid import UUID from operator import attrgetter from zope.component import getUtility @@ -176,7 +178,7 @@ class AMember(_MemberBase): return try: values = Validator( - address=unicode, + address=six.text_type, delivery_mode=enum_validator(DeliveryMode), _optional=('address', 'delivery_mode'))(request) except ValueError as error: @@ -207,9 +209,9 @@ class AllMembers(_MemberBase): service = getUtility(ISubscriptionService) try: validator = Validator( - list_id=unicode, + list_id=six.text_type, subscriber=subscriber_validator, - display_name=unicode, + display_name=six.text_type, delivery_mode=enum_validator(DeliveryMode), role=enum_validator(MemberRole), _optional=('delivery_mode', 'display_name', 'role')) @@ -256,8 +258,8 @@ class FindMembers(_MemberBase): """Find a member""" service = getUtility(ISubscriptionService) validator = Validator( - list_id=unicode, - subscriber=unicode, + list_id=six.text_type, + subscriber=six.text_type, role=enum_validator(MemberRole), _optional=('list_id', 'subscriber', 'role')) try: diff --git a/src/mailman/rest/tests/test_addresses.py b/src/mailman/rest/tests/test_addresses.py index f4aeb3013..29e09355e 100644 --- a/src/mailman/rest/tests/test_addresses.py +++ b/src/mailman/rest/tests/test_addresses.py @@ -27,15 +27,14 @@ __all__ = [ import unittest -from urllib2 import HTTPError -from zope.component import getUtility - from mailman.app.lifecycle import create_list from mailman.database.transaction import transaction from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer from mailman.utilities.datetime import now +from six.moves.urllib_error import HTTPError +from zope.component import getUtility diff --git a/src/mailman/rest/tests/test_domains.py b/src/mailman/rest/tests/test_domains.py index 44cf11ef3..48f9c4fe3 100644 --- a/src/mailman/rest/tests/test_domains.py +++ b/src/mailman/rest/tests/test_domains.py @@ -27,14 +27,13 @@ __all__ = [ import unittest -from urllib2 import HTTPError -from zope.component import getUtility - from mailman.app.lifecycle import create_list from mailman.database.transaction import transaction from mailman.interfaces.listmanager import IListManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer +from six.moves.urllib_error import HTTPError +from zope.component import getUtility diff --git a/src/mailman/rest/tests/test_lists.py b/src/mailman/rest/tests/test_lists.py index ba6f6ea59..e8cc54d4b 100644 --- a/src/mailman/rest/tests/test_lists.py +++ b/src/mailman/rest/tests/test_lists.py @@ -30,14 +30,13 @@ __all__ = [ import unittest -from urllib2 import HTTPError -from zope.component import getUtility - from mailman.app.lifecycle import create_list from mailman.database.transaction import transaction from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer +from six.moves.urllib_error import HTTPError +from zope.component import getUtility diff --git a/src/mailman/rest/tests/test_membership.py b/src/mailman/rest/tests/test_membership.py index 3c7d0520b..6b40fbb01 100644 --- a/src/mailman/rest/tests/test_membership.py +++ b/src/mailman/rest/tests/test_membership.py @@ -28,9 +28,6 @@ __all__ = [ import unittest -from urllib2 import HTTPError -from zope.component import getUtility - from mailman.app.lifecycle import create_list from mailman.config import config from mailman.database.transaction import transaction @@ -41,6 +38,8 @@ from mailman.testing.helpers import ( from mailman.runners.incoming import IncomingRunner from mailman.testing.layers import ConfigLayer, RESTLayer from mailman.utilities.datetime import now +from six.moves.urllib_error import HTTPError +from zope.component import getUtility diff --git a/src/mailman/rest/tests/test_moderation.py b/src/mailman/rest/tests/test_moderation.py index c0ec4755a..0e2528b0f 100644 --- a/src/mailman/rest/tests/test_moderation.py +++ b/src/mailman/rest/tests/test_moderation.py @@ -26,8 +26,6 @@ __all__ = [ import unittest -from urllib2 import HTTPError - from mailman.app.lifecycle import create_list from mailman.app.moderator import hold_message, hold_subscription from mailman.config import config @@ -36,6 +34,7 @@ from mailman.interfaces.member import DeliveryMode from mailman.testing.helpers import ( call_api, specialized_message_from_string as mfs) from mailman.testing.layers import RESTLayer +from six.moves.urllib_error import HTTPError diff --git a/src/mailman/rest/tests/test_preferences.py b/src/mailman/rest/tests/test_preferences.py index 91a066cff..06e0b035b 100644 --- a/src/mailman/rest/tests/test_preferences.py +++ b/src/mailman/rest/tests/test_preferences.py @@ -32,7 +32,7 @@ from mailman.database.transaction import transaction from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer -from urllib2 import HTTPError +from six.moves.urllib_error import HTTPError from zope.component import getUtility diff --git a/src/mailman/rest/tests/test_root.py b/src/mailman/rest/tests/test_root.py index d4d25ede0..c5787bcb1 100644 --- a/src/mailman/rest/tests/test_root.py +++ b/src/mailman/rest/tests/test_root.py @@ -35,7 +35,7 @@ from mailman.config import config from mailman.core.system import system from mailman.testing.helpers import call_api from mailman.testing.layers import RESTLayer -from urllib2 import HTTPError +from six.moves.urllib_error import HTTPError diff --git a/src/mailman/rest/tests/test_users.py b/src/mailman/rest/tests/test_users.py index 10cc724a3..1936fdc68 100644 --- a/src/mailman/rest/tests/test_users.py +++ b/src/mailman/rest/tests/test_users.py @@ -30,15 +30,14 @@ __all__ = [ import os import unittest -from urllib2 import HTTPError -from zope.component import getUtility - from mailman.app.lifecycle import create_list from mailman.config import config from mailman.database.transaction import transaction from mailman.interfaces.usermanager import IUserManager from mailman.testing.helpers import call_api, configuration from mailman.testing.layers import RESTLayer +from six.moves.urllib_error import HTTPError +from zope.component import getUtility diff --git a/src/mailman/rest/users.py b/src/mailman/rest/users.py index cfea36cfa..7e6e70c5a 100644 --- a/src/mailman/rest/users.py +++ b/src/mailman/rest/users.py @@ -27,6 +27,8 @@ __all__ = [ ] +import six + from passlib.utils import generate_password as generate from uuid import UUID from zope.component import getUtility @@ -58,7 +60,7 @@ class PasswordEncrypterGetterSetter(GetterSetter): ATTRIBUTES = dict( - display_name=GetterSetter(unicode), + display_name=GetterSetter(six.text_type), cleartext_password=PasswordEncrypterGetterSetter(), ) @@ -105,9 +107,9 @@ class AllUsers(_UserBase): def on_post(self, request, response): """Create a new user.""" try: - validator = Validator(email=unicode, - display_name=unicode, - password=unicode, + validator = Validator(email=six.text_type, + display_name=six.text_type, + password=six.text_type, _optional=('display_name', 'password')) arguments = validator(request) except ValueError as error: @@ -253,7 +255,7 @@ class Login: # We do not want to encrypt the plaintext password given in the POST # data. That would hash the password, but we need to have the # plaintext in order to pass into passlib. - validator = Validator(cleartext_password=GetterSetter(unicode)) + validator = Validator(cleartext_password=GetterSetter(six.text_type)) try: values = validator(request) except ValueError as error: diff --git a/src/mailman/rest/validator.py b/src/mailman/rest/validator.py index cbcc5f652..74a8c0be4 100644 --- a/src/mailman/rest/validator.py +++ b/src/mailman/rest/validator.py @@ -62,7 +62,7 @@ def subscriber_validator(subscriber): try: return UUID(int=int(subscriber)) except ValueError: - return unicode(subscriber) + return subscriber.decode('utf-8') def language_validator(code): |
