~barry/mailman/lp1423756

« back to all changes in this revision

Viewing changes to src/mailman/rest/lists.py

  • Committer: Barry Warsaw
  • Date: 2015-01-05 01:20:33 UTC
  • mfrom: (7264.4.66 py3)
  • Revision ID: barry@list.org-20150105012033-zdrw9c2odhpf22fz
Merge the Python 3 branch.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 
18
18
"""REST for mailing lists."""
19
19
 
20
 
from __future__ import absolute_import, print_function, unicode_literals
21
 
 
22
 
__metaclass__ = type
23
20
__all__ = [
24
21
    'AList',
25
22
    'AllLists',
30
27
    ]
31
28
 
32
29
 
 
30
import six
 
31
 
33
32
from lazr.config import as_boolean
34
 
from operator import attrgetter
35
 
from zope.component import getUtility
36
 
 
37
33
from mailman.app.lifecycle import create_list, remove_list
38
34
from mailman.config import config
39
35
from mailman.interfaces.domain import BadDomainSpecificationError
50
46
from mailman.rest.members import AMember, MemberCollection
51
47
from mailman.rest.moderation import HeldMessages, SubscriptionRequests
52
48
from mailman.rest.validator import Validator
 
49
from operator import attrgetter
 
50
from zope.component import getUtility
53
51
 
54
52
 
55
53
 
204
202
    def on_post(self, request, response):
205
203
        """Create a new mailing list."""
206
204
        try:
207
 
            validator = Validator(fqdn_listname=unicode,
208
 
                                  style_name=unicode,
 
205
            validator = Validator(fqdn_listname=six.text_type,
 
206
                                  style_name=six.text_type,
209
207
                                  _optional=('style_name',))
210
208
            mlist = create_list(**validator(request))
211
209
        except ListAlreadyExistsError:
212
210
            bad_request(response, b'Mailing list exists')
213
211
        except BadDomainSpecificationError as error:
214
 
            bad_request(
215
 
                response,
216
 
                b'Domain does not exist: {0}'.format(error.domain))
 
212
            reason = 'Domain does not exist: {}'.format(error.domain)
 
213
            bad_request(response, reason.encode('utf-8'))
217
214
        except ValueError as error:
218
215
            bad_request(response, str(error))
219
216
        else:
273
270
        # attribute will contain the (bytes) name of the archiver that is
274
271
        # getting a new status.  value will be the representation of the new
275
272
        # boolean status.
276
 
        archiver = self._archiver_set.get(attribute.decode('utf-8'))
 
273
        archiver = self._archiver_set.get(attribute)
277
274
        if archiver is None:
278
275
            raise ValueError('No such archiver: {}'.format(attribute))
279
276
        archiver.is_enabled = as_boolean(value)