summaryrefslogtreecommitdiff
path: root/src/mailman/rest/urls.py
diff options
context:
space:
mode:
authorBarry Warsaw2010-02-25 20:40:44 -0500
committerBarry Warsaw2010-02-25 20:40:44 -0500
commit70dd8a96cc0e01b42737b46e30cf37b5c8fa0747 (patch)
tree4fee0c35625c78a38962aeea313ec7f76462199b /src/mailman/rest/urls.py
parentb2ae2b7795719f17cb2b6c7ed14e5b4c7c8eae47 (diff)
downloadmailman-70dd8a96cc0e01b42737b46e30cf37b5c8fa0747.tar.gz
mailman-70dd8a96cc0e01b42737b46e30cf37b5c8fa0747.tar.zst
mailman-70dd8a96cc0e01b42737b46e30cf37b5c8fa0747.zip
Diffstat (limited to 'src/mailman/rest/urls.py')
-rw-r--r--src/mailman/rest/urls.py142
1 files changed, 0 insertions, 142 deletions
diff --git a/src/mailman/rest/urls.py b/src/mailman/rest/urls.py
deleted file mode 100644
index 566696f82..000000000
--- a/src/mailman/rest/urls.py
+++ /dev/null
@@ -1,142 +0,0 @@
-# Copyright (C) 2009-2010 by the Free Software Foundation, Inc.
-#
-# This file is part of GNU Mailman.
-#
-# GNU Mailman is free software: you can redistribute it and/or modify it under
-# the terms of the GNU General Public License as published by the Free
-# Software Foundation, either version 3 of the License, or (at your option)
-# any later version.
-#
-# GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
-# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
-# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
-# more details.
-#
-# You should have received a copy of the GNU General Public License along with
-# GNU Mailman. If not, see <http://www.gnu.org/licenses/>.
-
-"""Mappers from objects to absolute URLs."""
-
-from __future__ import absolute_import, unicode_literals
-
-__metaclass__ = type
-__all__ = [
- 'DomainURLMapper',
- 'FallbackURLMapper',
- 'MailingListURLMapper',
- 'MemberURLMapper',
- ]
-
-
-import logging
-
-from zope.component import getUtility
-from zope.interface import implements
-from zope.traversing.browser.interfaces import IAbsoluteURL
-
-from mailman.config import config
-from mailman.core.system import system
-from mailman.interfaces.listmanager import IListManager
-from mailman.interfaces.membership import ISubscriptionService
-from mailman.rest.configuration import AdminWebServiceConfiguration
-from mailman.rest.webservice import AdminWebServiceApplication
-
-log = logging.getLogger('mailman.http')
-
-
-
-class BasicURLMapper:
- """Base absolute URL mapper."""
-
- implements(IAbsoluteURL)
-
- def __init__(self, context, request):
- """Initialize with respect to a context and request."""
- self.context = context
- self.request = request
- self.webservice_config = AdminWebServiceConfiguration()
- # XXX 2010-02-16 barry This kind of sucks, but I don't understand how
- # to reconcile the way we used to do things with the way lazr.restful
- # as of 0.9.18 wants to do multiversion webservices. And really, I
- # don't care because right now I don't have any need for
- # multiversioned services. lazr.restful forced me to think about it
- # though, so this just hardcodes the version part of the resource URL
- # path to the first (i.e. numbered) version.
- self.version = self.webservice_config.active_versions[0]
- self.schema = ('https' if self.webservice_config.use_https else 'http')
- self.hostname = self.webservice_config.hostname
- self.port = self.webservice_config.port
-
-
-
-class FallbackURLMapper(BasicURLMapper):
- """Generic absolute url mapper."""
-
- def __call__(self):
- """Return the semi-hard-coded URL to the service root."""
- path = self._lookup(self.context)
- return '{0.schema}://{0.hostname}:{0.port}/{0.version}/{1}'.format(
- self, path)
-
- def _lookup(self, ob):
- """Return the path component for the object.
-
- :param ob: The object we're looking for.
- :type ob: anything
- :return: The path component.
- :rtype: string
- :raises KeyError: if no path component can be found.
- """
- log.debug('generic url mapper lookup: %s', ob)
- # Special cases.
- if isinstance(ob, AdminWebServiceApplication):
- return ''
- urls = {
- system: 'system',
- getUtility(IListManager): 'lists',
- getUtility(ISubscriptionService): 'members',
- }
- return urls[ob]
-
-
-
-class TopLevelURLMapper(BasicURLMapper):
- """A simple mapper for top level objects."""
-
- implements(IAbsoluteURL)
-
- format_string = None
-
- def __call__(self):
- """Return the hard-coded URL to the resource."""
- return self.format_string.format(self)
-
-
-class DomainURLMapper(TopLevelURLMapper):
- """Mapper of `IDomains` to `IAbsoluteURL`."""
-
- format_string = (
- '{0.schema}://{0.hostname}:{0.port}/{0.version}/'
- 'domains/{0.context.email_host}')
-
-
-class MailingListURLMapper(TopLevelURLMapper):
- """Mapper of `IMailingList` to `IAbsoluteURL`."""
-
- format_string = (
- '{0.schema}://{0.hostname}:{0.port}/{0.version}/'
- 'lists/{0.context.fqdn_listname}')
-
-
-class MemberURLMapper(TopLevelURLMapper):
- """Mapper of `IMember` to `IAbsoluteURL`."""
-
- def __init__(self, context, request):
- super(MemberURLMapper, self).__init__(context, request)
- # Use a shorted version of the MemberRole string.
- enum, dot, self.role = str(self.context.role).partition('.')
-
- format_string = (
- '{0.schema}://{0.hostname}:{0.port}/{0.version}/'
- 'lists/{0.context.mailing_list}/'
- '{0.role}/{0.context.address.address}')