summaryrefslogtreecommitdiff
path: root/src/mailman/rest/configuration.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/mailman/rest/configuration.py')
-rw-r--r--src/mailman/rest/configuration.py61
1 files changed, 32 insertions, 29 deletions
diff --git a/src/mailman/rest/configuration.py b/src/mailman/rest/configuration.py
index db0918703..b432268c7 100644
--- a/src/mailman/rest/configuration.py
+++ b/src/mailman/rest/configuration.py
@@ -26,8 +26,6 @@ __all__ = [
from lazr.config import as_boolean, as_timedelta
-from restish import http, resource
-
from mailman.config import config
from mailman.core.errors import (
ReadOnlyPATCHRequestError, UnknownPATCHRequestError)
@@ -35,7 +33,8 @@ from mailman.interfaces.action import Action
from mailman.interfaces.archiver import ArchivePolicy
from mailman.interfaces.autorespond import ResponseAction
from mailman.interfaces.mailinglist import IAcceptableAliasSet, ReplyToMunging
-from mailman.rest.helpers import GetterSetter, PATCH, etag, no_content
+from mailman.rest.helpers import (
+ GetterSetter, bad_request, etag, no_content, okay)
from mailman.rest.validator import PatchValidator, Validator, enum_validator
@@ -46,7 +45,7 @@ class AcceptableAliases(GetterSetter):
def get(self, mlist, attribute):
"""Return the mailing list's acceptable aliases."""
assert attribute == 'acceptable_aliases', (
- 'Unexpected attribute: {0}'.format(attribute))
+ 'Unexpected attribute: {}'.format(attribute))
aliases = IAcceptableAliasSet(mlist)
return sorted(aliases.aliases)
@@ -58,7 +57,7 @@ class AcceptableAliases(GetterSetter):
ignored.
"""
assert attribute == 'acceptable_aliases', (
- 'Unexpected attribute: {0}'.format(attribute))
+ 'Unexpected attribute: {}'.format(attribute))
alias_set = IAcceptableAliasSet(mlist)
alias_set.clear()
for alias in value:
@@ -73,7 +72,7 @@ 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)
- raise ValueError('Unknown pipeline: {0}'.format(pipeline_name))
+ raise ValueError('Unknown pipeline: {}'.format(pipeline_name))
def list_of_unicode(values):
@@ -156,15 +155,14 @@ for attribute, gettersetter in VALIDATORS.items():
-class ListConfiguration(resource.Resource):
+class ListConfiguration:
"""A mailing list configuration resource."""
def __init__(self, mailing_list, attribute):
self._mlist = mailing_list
self._attribute = attribute
- @resource.GET()
- def get_configuration(self, request):
+ def on_get(self, request, response):
"""Get a mailing list configuration."""
resource = {}
if self._attribute is None:
@@ -173,16 +171,16 @@ class ListConfiguration(resource.Resource):
value = ATTRIBUTES[attribute].get(self._mlist, attribute)
resource[attribute] = value
elif self._attribute not in ATTRIBUTES:
- return http.bad_request(
- [], b'Unknown attribute: {0}'.format(self._attribute))
+ bad_request(
+ response, b'Unknown attribute: {}'.format(self._attribute))
+ return
else:
attribute = self._attribute
value = ATTRIBUTES[attribute].get(self._mlist, attribute)
resource[attribute] = value
- return http.ok([], etag(resource))
+ okay(response, etag(resource))
- @resource.PUT()
- def put_configuration(self, request):
+ def on_put(self, request, response):
"""Set a mailing list configuration."""
attribute = self._attribute
if attribute is None:
@@ -190,34 +188,39 @@ class ListConfiguration(resource.Resource):
try:
validator.update(self._mlist, request)
except ValueError as error:
- return http.bad_request([], str(error))
+ bad_request(response, str(error))
+ return
elif attribute not in ATTRIBUTES:
- return http.bad_request(
- [], b'Unknown attribute: {0}'.format(attribute))
+ bad_request(response, b'Unknown attribute: {}'.format(attribute))
+ return
elif ATTRIBUTES[attribute].decoder is None:
- return http.bad_request(
- [], b'Read-only attribute: {0}'.format(attribute))
+ bad_request(
+ response, b'Read-only attribute: {}'.format(attribute))
+ return
else:
validator = Validator(**{attribute: VALIDATORS[attribute]})
try:
validator.update(self._mlist, request)
except ValueError as error:
- return http.bad_request([], str(error))
- return no_content()
+ bad_request(response, str(error))
+ return
+ no_content(response)
- @PATCH()
- def patch_configuration(self, request):
+ def on_patch(self, request, response):
"""Patch the configuration (i.e. partial update)."""
try:
validator = PatchValidator(request, ATTRIBUTES)
except UnknownPATCHRequestError as error:
- return http.bad_request(
- [], b'Unknown attribute: {0}'.format(error.attribute))
+ bad_request(
+ response, b'Unknown attribute: {}'.format(error.attribute))
+ return
except ReadOnlyPATCHRequestError as error:
- return http.bad_request(
- [], b'Read-only attribute: {0}'.format(error.attribute))
+ bad_request(
+ response, b'Read-only attribute: {}'.format(error.attribute))
+ return
try:
validator.update(self._mlist, request)
except ValueError as error:
- return http.bad_request([], str(error))
- return no_content()
+ bad_request(response, str(error))
+ else:
+ no_content(response)