summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorBarry Warsaw2009-04-02 18:43:19 -0500
committerBarry Warsaw2009-04-02 18:43:19 -0500
commitea96bbebd8594a70f534aacdab949a63bf800b22 (patch)
treeb96f61bb18bda058c333aaea75bb5440b1321c95 /src
parenta77c795249a018106076f421a051be54faaaa980 (diff)
downloadmailman-ea96bbebd8594a70f534aacdab949a63bf800b22.tar.gz
mailman-ea96bbebd8594a70f534aacdab949a63bf800b22.tar.zst
mailman-ea96bbebd8594a70f534aacdab949a63bf800b22.zip
Diffstat (limited to 'src')
-rw-r--r--src/mailman/rest/publication.py98
-rw-r--r--src/mailman/rest/root.py3
2 files changed, 98 insertions, 3 deletions
diff --git a/src/mailman/rest/publication.py b/src/mailman/rest/publication.py
index b1f960b62..b5fac2318 100644
--- a/src/mailman/rest/publication.py
+++ b/src/mailman/rest/publication.py
@@ -21,12 +21,106 @@ from __future__ import absolute_import, unicode_literals
__metaclass__ = type
__all__ = [
+ 'AdminWebServicePublication',
]
+import traceback
+
from lazr.restful.publisher import WebServicePublicationMixin
+from zope.component import getUtility, queryMultiAdapter
+from zope.interface import implements
+from zope.publisher.interfaces import IPublication, IPublishTraverse, NotFound
+from zope.publisher.publish import mapply
+from zope.security.checker import ProxyFactory
+from zope.security.management import endInteraction, newInteraction
+
+
+
+class Publication:
+ """Very simple implementation of `IPublication`.
+
+ The object pass to the constructor is returned by getApplication().
+ """
+ implements(IPublication)
+
+ def __init__(self, application):
+ """Create the test publication.
+
+ The object at which traversal should start is passed as parameter.
+ """
+ self.application = application
+
+ def beforeTraversal(self, request):
+ """Sets the request as the current interaction.
+
+ (It also ends any previous interaction, that's convenient when
+ tests don't go through the whole request.)
+ """
+ endInteraction()
+ newInteraction(request)
+
+ def getApplication(self, request):
+ """Returns the application passed to the constructor."""
+ return self.application
+
+ def callTraversalHooks(self, request, ob):
+ """Does nothing."""
+
+ def traverseName(self, request, ob, name):
+ """Traverse by looking at an `IPublishTraverse` adapter.
+
+ The object is security wrapped.
+ """
+ # XXX flacoste 2009/03/06 bug=338831. This is copied from
+ # zope.app.publication.publicationtraverse.PublicationTraverse.
+ # This should really live in zope.publisher, we are copying because
+ # we don't want to depend on zope.app stuff.
+ # Namespace support was dropped.
+ if name == '.':
+ return ob
+
+ if IPublishTraverse.providedBy(ob):
+ ob2 = ob.publishTraverse(request, name)
+ else:
+ # self is marker.
+ adapter = queryMultiAdapter(
+ (ob, request), IPublishTraverse, default=self)
+ if adapter is not self:
+ ob2 = adapter.publishTraverse(request, name)
+ else:
+ raise NotFound(ob, name, request)
+
+ return ProxyFactory(ob2)
+
+ def afterTraversal(self, request, ob):
+ """Does nothing."""
+
+ def callObject(self, request, ob):
+ """Call the object, returning the result."""
+ return mapply(ob, request.getPositionalArguments(), request)
+
+ def afterCall(self, request, ob):
+ """Does nothing."""
+
+ def handleException(self, object, request, exc_info, retry_allowed=1):
+ """Prints the exception."""
+ # Reproduce the behavior of ZopePublication by looking up a view
+ # for this exception.
+ exception = exc_info[1]
+ view = queryMultiAdapter((exception, request), name='index.html')
+ if view is not None:
+ exc_info = None
+ request.response.reset()
+ request.response.setResult(view())
+ else:
+ traceback.print_exception(*exc_info)
+
+ def endRequest(self, request, ob):
+ """Ends the interaction."""
+ endInteraction()
-class AdminWebServiceTestPublication(WebServicePublicationMixin, TestPublication):
- """Test publication that mixes in the necessary web service stuff."""
+class AdminWebServicePublication(WebServicePublicationMixin, Publication):
+ """A publication that mixes in the necessary web service stuff."""
diff --git a/src/mailman/rest/root.py b/src/mailman/rest/root.py
index c050ebc1c..a38371770 100644
--- a/src/mailman/rest/root.py
+++ b/src/mailman/rest/root.py
@@ -35,7 +35,6 @@ from zope.traversing.browser.interfaces import IAbsoluteURL
from mailman.config import config
from mailman.core.system import system
from mailman.interfaces.rest import IHasGet
-from mailman.rest.configuration import AdminWebServiceConfiguration
@@ -60,6 +59,8 @@ class AdminWebServiceRootAbsoluteURL:
def __init__(self, context, request):
"""Initialize with respect to a context and request."""
+ # Avoid circular imports.
+ from mailman.rest.configuration import AdminWebServiceConfiguration
self.webservice_config = AdminWebServiceConfiguration()
self.version = webservice_config.service_version_uri_prefix
self.schema = ('https' if self.webservice_config.use_https else 'http')