summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mailman/rest/addresses.py19
-rw-r--r--src/mailman/rest/helpers.py11
-rw-r--r--src/mailman/rest/wsgiapp.py4
3 files changed, 17 insertions, 17 deletions
diff --git a/src/mailman/rest/addresses.py b/src/mailman/rest/addresses.py
index 6e9eb8872..d42a66aa7 100644
--- a/src/mailman/rest/addresses.py
+++ b/src/mailman/rest/addresses.py
@@ -37,8 +37,7 @@ from mailman.interfaces.address import (
ExistingAddressError, InvalidEmailAddressError)
from mailman.interfaces.usermanager import IUserManager
from mailman.rest.helpers import (
- BadRequest, CollectionMixin, NotFound, child, etag, path_not_found,
- path_to)
+ BadRequest, CollectionMixin, NotFound, child, etag, path_to)
from mailman.rest.members import MemberCollection
from mailman.rest.preferences import Preferences
from mailman.rest.validator import Validator
@@ -115,7 +114,8 @@ class AnAddress(_AddressBase):
def on_get(self, request, response):
"""Return a single address."""
if self._address is None:
- path_not_found(request, response)
+ falcon.responders.path_not_found(
+ request, response, b'404 Not Found')
else:
response.status = falcon.HTTP_200
response.body = self._resource_as_json(self._address)
@@ -178,7 +178,8 @@ class UserAddresses(_AddressBase):
def on_get(self, request, response):
"""/addresses"""
if self._user is None:
- path_not_found(request, response)
+ falcon.responders.path_not_found(
+ request, response, b'404 Not Found')
else:
response.status = falcon.HTTP_200
resource = self._make_collection(request)
@@ -190,7 +191,7 @@ class UserAddresses(_AddressBase):
Add a new address to the user record.
"""
if self._user is None:
- path_not_found(request, response)
+ falcon.responders.path_not_found(request, response)
return
user_manager = getUtility(IUserManager)
validator = Validator(email=unicode,
@@ -199,11 +200,13 @@ class UserAddresses(_AddressBase):
try:
address = user_manager.create_address(**validator(request))
except ValueError as error:
- return http.bad_request([], str(error))
+ falcon.responders.bad_request(request, response, body=str(error))
except InvalidEmailAddressError:
- return http.bad_request([], b'Invalid email address')
+ falcon.responders.bad_request(
+ request, response, body=b'Invalid email address')
except ExistingAddressError:
- return http.bad_request([], b'Address already exists')
+ falcon.responders.bad_request(
+ request, response, body=b'Address already exists')
else:
# Link the address to the current user and return it.
address.user = self._user
diff --git a/src/mailman/rest/helpers.py b/src/mailman/rest/helpers.py
index af7392f5a..5b51bc436 100644
--- a/src/mailman/rest/helpers.py
+++ b/src/mailman/rest/helpers.py
@@ -324,9 +324,12 @@ class ChildError:
def __init__(self, status):
self._status = status
- def on_get(self, request, response):
+ def _oops(self, request, response):
raise falcon.HTTPError(self._status, None)
+ on_get = _oops
+ on_post = _oops
+
class BadRequest(ChildError):
def __init__(self):
@@ -336,9 +339,3 @@ class BadRequest(ChildError):
class NotFound(ChildError):
def __init__(self):
super(NotFound, self).__init__(falcon.HTTP_404)
-
-
-def path_not_found(request, response, **kws):
- # Like falcon.responders.path_not_found() but sets the body.
- response.status = falcon.HTTP_404
- response.body = b'404 Not Found'
diff --git a/src/mailman/rest/wsgiapp.py b/src/mailman/rest/wsgiapp.py
index 3bd77bbcc..24ba6db3b 100644
--- a/src/mailman/rest/wsgiapp.py
+++ b/src/mailman/rest/wsgiapp.py
@@ -26,6 +26,7 @@ __all__ = [
]
+import falcon
import logging
from falcon import API
@@ -36,7 +37,6 @@ from wsgiref.simple_server import make_server as wsgi_server
from mailman.config import config
from mailman.database.transaction import transactional
-from mailman.rest.helpers import path_not_found
from mailman.rest.root import Root
@@ -111,7 +111,7 @@ class RootedAPI(API):
else:
# None of the attributes matched this path component, so the
# response is a 404.
- return path_not_found, {}, None
+ return falcon.responders.path_not_found, {}, None