[prev in list] [next in list] [prev in thread] [next in thread]
List: mailman-cvs
Subject: [Mailman-checkins] [Branch ~mailman-coders/mailman/3.0] Rev 6737:
From: noreply () launchpad ! net
Date: 2009-06-30 3:35:17
Message-ID: 20090630033517.16600.85530.launchpad () loganberry ! canonical ! com
[Download RAW message or body]
------------------------------------------------------------
revno: 6737
committer: Barry Warsaw <barry@list.org>
branch nick: 3.0
timestamp: Mon 2009-06-29 21:30:04 -0400
message:
More REST server updates.
* Get rid of in-Python adapter registration in favor of ZCML. Eventually, I'd
like to get rid of the ZCML.
* Set the view_permission to None, but it's still not right.
* Add IDomainSet and an adapter from Configuration to IDomainSet.
added:
src/mailman/config/configure.zcml
src/mailman/rest/adapters.py
src/mailman/rest/docs/domains.txt
modified:
src/mailman/app/registrar.py
src/mailman/config/config.py
src/mailman/config/schema.cfg
src/mailman/core/initialize.py
src/mailman/database/autorespond.py
src/mailman/database/mailinglist.py
src/mailman/interfaces/domain.py
src/mailman/rest/configuration.py
src/mailman/rest/configure.zcml
src/mailman/rest/root.py
src/mailman/rest/urls.py
src/mailman/rest/webservice.py
=== modified file 'src/mailman/app/registrar.py'
--- src/mailman/app/registrar.py 2009-02-13 03:52:18 +0000
+++ src/mailman/app/registrar.py 2009-06-30 01:30:04 +0000
@@ -22,7 +22,6 @@
__metaclass__ = type
__all__ = [
'Registrar',
- 'adapt_domain_to_registrar',
]
@@ -145,19 +144,3 @@
def discard(self, token):
# Throw the record away.
config.db.pendings.confirm(token)
-
-
-
-def adapt_domain_to_registrar(iface, obj):
- """Adapt `IDomain` to `IRegistrar`.
-
- :param iface: The interface to adapt to.
- :type iface: `zope.interface.Interface`
- :param obj: The object being adapted.
- :type obj: `IDomain`
- :return: An `IRegistrar` instance if adaptation succeeded or None if it
- didn't.
- """
- return (Registrar(obj)
- if IDomain.providedBy(obj) and iface is IRegistrar
- else None)
=== modified file 'src/mailman/config/config.py'
--- src/mailman/config/config.py 2009-05-16 15:08:46 +0000
+++ src/mailman/config/config.py 2009-06-30 01:30:04 +0000
@@ -32,6 +32,7 @@
from lazr.config import ConfigSchema, as_boolean
from pkg_resources import resource_stream
+from zope.interface import Interface, implements
from mailman import version
from mailman.core import errors
@@ -46,9 +47,16 @@
-class Configuration(object):
+class IConfiguration(Interface):
+ """Marker interface; used for adaptation in the REST API."""
+
+
+
+class Configuration:
"""The core global configuration object."""
+ implements(IConfiguration)
+
def __init__(self):
self.domains = {} # email host -> IDomain
self.switchboards = {}
=== added file 'src/mailman/config/configure.zcml'
--- src/mailman/config/configure.zcml 1970-01-01 00:00:00 +0000
+++ src/mailman/config/configure.zcml 2009-06-30 01:30:04 +0000
@@ -0,0 +1,27 @@
+<!-- -*- xml -*- -->
+<configure
+ xmlns="http://namespaces.zope.org/zope">
+
+ <include package="mailman.rest" file="configure.zcml"/>
+
+ <!-- adapters -->
+
+ <adapter
+ for="mailman.interfaces.domain.IDomain"
+ provides="mailman.interfaces.registrar.IRegistrar"
+ factory="mailman.app.registrar.Registrar"
+ />
+
+ <adapter
+ for="mailman.interfaces.mailinglist.IMailingList"
+ provides="mailman.interfaces.autorespond.IAutoResponseSet"
+ factory="mailman.database.autorespond.AutoResponseSet"
+ />
+
+ <adapter
+ for="mailman.interfaces.mailinglist.IMailingList"
+ provides="mailman.interfaces.mailinglist.IAcceptableAliasSet"
+ factory="mailman.database.mailinglist.AcceptableAliasSet"
+ />
+
+</configure>
=== modified file 'src/mailman/config/schema.cfg'
--- src/mailman/config/schema.cfg 2009-05-15 22:37:29 +0000
+++ src/mailman/config/schema.cfg 2009-06-30 01:30:04 +0000
@@ -226,7 +226,7 @@
use_https: no
# Default view permission for the admin web service.
-view_permission: zope.Public
+view_permission: None
# Whether or not to show tracebacks in an HTTP response for a request that
# raised an exception.
=== modified file 'src/mailman/core/initialize.py'
--- src/mailman/core/initialize.py 2009-05-16 15:08:46 +0000
+++ src/mailman/core/initialize.py 2009-06-30 01:30:04 +0000
@@ -38,7 +38,8 @@
import os
import sys
-from zope.interface.interface import adapter_hooks
+from pkg_resources import resource_string
+from zope.configuration import xmlconfig
from zope.interface.verify import verifyObject
import mailman.config.config
@@ -82,6 +83,7 @@
def initialize_2(debug=False):
"""Second initialization step.
+ * Pre-hook
* Rules
* Chains
* Pipelines
@@ -117,15 +119,11 @@
def initialize_3():
"""Third initialization step.
- * Adapters
+ * Zope component architecture
+ * Post-hook
"""
- from mailman.app.registrar import adapt_domain_to_registrar
- adapter_hooks.append(adapt_domain_to_registrar)
- from mailman.database.autorespond import adapt_mailing_list_to_response_set
- adapter_hooks.append(adapt_mailing_list_to_response_set)
- from mailman.database.mailinglist import (
- adapt_mailing_list_to_acceptable_alias_set)
- adapter_hooks.append(adapt_mailing_list_to_acceptable_alias_set)
+ zcml = resource_string('mailman.config', 'configure.zcml')
+ xmlconfig.string(zcml)
# Run the post-hook if there is one.
config = mailman.config.config
if config.mailman.post_hook:
=== modified file 'src/mailman/database/autorespond.py'
--- src/mailman/database/autorespond.py 2009-02-19 05:18:35 +0000
+++ src/mailman/database/autorespond.py 2009-06-30 01:30:04 +0000
@@ -23,7 +23,6 @@
__all__ = [
'AutoResponseRecord',
'AutoResponseSet',
- 'adapt_mailing_list_to_response_set',
]
@@ -92,19 +91,3 @@
AutoResponseRecord.response_type == response_type)
).order_by(Desc(AutoResponseRecord.date_sent))
return (None if results.count() == 0 else results.first())
-
-
-
-def adapt_mailing_list_to_response_set(iface, obj):
- """Adapt an `IMailingList` to an `IAutoResponseSet`.
-
- :param iface: The interface to adapt to.
- :type iface: `zope.interface.Interface`
- :param obj: The object being adapted.
- :type obj: `IMailingList`
- :return: An `IAutoResponseSet` instance if adaptation succeeded or None if
- it didn't.
- """
- return (AutoResponseSet(obj)
- if IMailingList.providedBy(obj) and iface is IAutoResponseSet
- else None)
=== modified file 'src/mailman/database/mailinglist.py'
--- src/mailman/database/mailinglist.py 2009-03-03 15:15:42 +0000
+++ src/mailman/database/mailinglist.py 2009-06-30 01:30:04 +0000
@@ -22,7 +22,6 @@
__metaclass__ = type
__all__ = [
'MailingList',
- 'adapt_mailing_list_to_acceptable_alias_set',
]
@@ -462,19 +461,3 @@
AcceptableAlias.mailing_list == self._mailing_list)
for alias in aliases:
yield alias.alias
-
-
-
-def adapt_mailing_list_to_acceptable_alias_set(iface, obj):
- """Adapt an `IMailingList` to an `IAcceptableAliasSet`.
-
- :param iface: The interface to adapt to.
- :type iface: `zope.interface.Interface`
- :param obj: The object being adapted.
- :type obj: `IMailingList`
- :return: An `IAcceptableAliasSet` instance if adaptation succeeded or None
- if it didn't.
- """
- return (AcceptableAliasSet(obj)
- if IMailingList.providedBy(obj) and iface is IAcceptableAliasSet
- else None)
=== modified file 'src/mailman/interfaces/domain.py'
--- src/mailman/interfaces/domain.py 2009-04-01 20:14:24 +0000
+++ src/mailman/interfaces/domain.py 2009-06-30 01:30:04 +0000
@@ -22,49 +22,54 @@
__metaclass__ = type
__all__ = [
'IDomain',
+ 'IDomainSet',
]
+from lazr.restful.declarations import (
+ collection_default_content, export_as_webservice_collection,
+ export_as_webservice_entry, exported)
from zope.interface import Interface, Attribute
+from zope.schema import TextLine
+
+from mailman.i18n import _
class IDomain(Interface):
"""Interface representing domains."""
- email_host = Attribute(
- """The host name for email for this domain.
-
- :type: string
- """)
-
- url_host = Attribute(
- """The host name for the web interface for this domain.
-
- :type: string
- """)
-
- base_url = Attribute(
- """The base url for the Mailman server at this domain.
-
- The base url includes the scheme and host name.
-
- :type: string
- """)
-
- description = Attribute(
- """The human readable description of the domain name.
-
- :type: string
- """)
-
- contact_address = Attribute(
- """The contact address for the human at this domain.
-
- E.g. postmaster@example.com
-
- :type: string
- """)
+ export_as_webservice_entry()
+
+ email_host = exported(TextLine(
+ title=_('Email host name'),
+ description=_('The host name for email for this domain.'),
+ ))
+
+ url_host = exported(TextLine(
+ title=_('Web host name'),
+ description=_('The host name for the web interface for this domain.')
+ ))
+
+ base_url = exported(TextLine(
+ title=_('Base URL'),
+ description=_("""\
+ The base url for the Mailman server at this domain, which includes the
+ scheme and host name."""),
+ ))
+
+ description = exported(TextLine(
+ title=_('Description'),
+ description=_('The human readable description of the domain name.'),
+ ))
+
+ contact_address = exported(TextLine(
+ title=_('Contact address'),
+ description=_("""\
+ The contact address for the human at this domain.
+
+ E.g. postmaster@example.com"""),
+ ))
def confirm_address(token=''):
"""The address used for various forms of email confirmation.
@@ -83,3 +88,14 @@
:return: The confirmation url.
:rtype: string
"""
+
+
+
+class IDomainSet(Interface):
+ """The set of all known domains."""
+
+ export_as_webservice_collection(IDomain)
+
+ @collection_default_content()
+ def __iter__():
+ """Iterate over all domains."""
=== added file 'src/mailman/rest/adapters.py'
--- src/mailman/rest/adapters.py 1970-01-01 00:00:00 +0000
+++ src/mailman/rest/adapters.py 2009-06-30 01:30:04 +0000
@@ -0,0 +1,47 @@
+# Copyright (C) 2009 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/>.
+
+"""Module stuff."""
+
+from __future__ import absolute_import, unicode_literals
+
+__metaclass__ = type
+__all__ = [
+ 'DomainSet',
+ ]
+
+
+from zope.interface import implements
+
+from mailman.interfaces.domain import IDomainSet
+
+
+
+class DomainSet:
+ """Sets of known domains."""
+
+ implements(IDomainSet)
+
+ __name__ = 'domains'
+
+ def __init__(self, config):
+ self._config = config
+
+ def __iter__(self):
+ """See `IDomainSet`."""
+ domains = self._config.domains
+ return [domains[domain] for domain in sorted(domains)]
=== modified file 'src/mailman/rest/configuration.py'
--- src/mailman/rest/configuration.py 2009-05-25 20:27:05 +0000
+++ src/mailman/rest/configuration.py 2009-06-30 01:30:04 +0000
@@ -42,6 +42,8 @@
@property
def view_permission(self):
+ if config.webservice.view_permission.lower() == 'none':
+ return None
return config.webservice.view_permission
path_override = None
=== modified file 'src/mailman/rest/configure.zcml'
--- src/mailman/rest/configure.zcml 2009-05-03 19:35:29 +0000
+++ src/mailman/rest/configure.zcml 2009-06-30 01:30:04 +0000
@@ -9,6 +9,7 @@
<include package="lazr.restful" file="configure.zcml"/>
<webservice:register module="mailman.interfaces.system" />
+ <webservice:register module="mailman.interfaces.domain" />
<adapter
for="zope.interface.Interface
@@ -17,6 +18,12 @@
factory="mailman.rest.urls.AbsoluteURLMapper"
/>
+ <adapter
+ for="mailman.config.config.IConfiguration"
+ provides="mailman.interfaces.domain.IDomainSet"
+ factory="mailman.rest.adapters.DomainSet"
+ />
+
<utility
factory="mailman.rest.configuration.AdminWebServiceConfiguration"
provides="lazr.restful.interfaces.IWebServiceConfiguration">
=== added file 'src/mailman/rest/docs/domains.txt'
--- src/mailman/rest/docs/domains.txt 1970-01-01 00:00:00 +0000
+++ src/mailman/rest/docs/domains.txt 2009-06-30 01:30:04 +0000
@@ -0,0 +1,8 @@
+=======
+Domains
+=======
+
+The REST API can be queried for the set of known domains.
+
+ >>> dump_json('http://localhost:8001/3.0/domains')
+ XXX
=== modified file 'src/mailman/rest/root.py'
--- src/mailman/rest/root.py 2009-05-02 22:07:38 +0000
+++ src/mailman/rest/root.py 2009-06-30 01:30:04 +0000
@@ -41,13 +41,6 @@
class AdminWebServiceRootResource(ServiceRootResource):
"""The root of the Mailman RESTful admin web service."""
- def get(self, name):
- """See `IHasGet`."""
- top_level = {
- 'sys': system,
- }
- return top_level.get(name)
-
class AdminWebServiceRootAbsoluteURL:
"""A basic implementation of `IAbsoluteURL` for the root object."""
=== modified file 'src/mailman/rest/urls.py'
--- src/mailman/rest/urls.py 2009-05-12 03:00:30 +0000
+++ src/mailman/rest/urls.py 2009-06-30 01:30:04 +0000
@@ -69,7 +69,8 @@
# Special cases.
if isinstance(ob, AdminWebServiceApplication):
return ''
- urls = {
- system: 'system',
- }
+ urls = dict(
+ system='system',
+ domains='domains',
+ )
return urls[ob]
=== modified file 'src/mailman/rest/webservice.py'
--- src/mailman/rest/webservice.py 2009-05-15 22:37:29 +0000
+++ src/mailman/rest/webservice.py 2009-06-30 01:30:04 +0000
@@ -35,14 +35,13 @@
from wsgiref.simple_server import WSGIServer, WSGIRequestHandler
from lazr.restful.publisher import WebServiceRequestTraversal
-from pkg_resources import resource_string
-from zope.configuration import xmlconfig
from zope.interface import implements
from zope.publisher.browser import BrowserRequest
from zope.publisher.publish import publish
from mailman.config import config
from mailman.core.system import system
+from mailman.interfaces.domain import IDomainSet
from mailman.interfaces.rest import IResolvePathNames
from mailman.rest.publication import AdminWebServicePublication
@@ -84,6 +83,7 @@
"""Maps root names to resources."""
top_level = dict(
system=system,
+ domains=IDomainSet(config),
)
return top_level.get(name)
@@ -99,8 +99,6 @@
def make_server():
"""Create the WSGI admin REST server."""
- zcml = resource_string('mailman.rest', 'configure.zcml')
- xmlconfig.string(zcml)
host = config.webservice.hostname
port = int(config.webservice.port)
server = WSGIServer((host, port), AdminWebServiceWSGIRequestHandler)
--
lp:mailman
https://code.launchpad.net/~mailman-coders/mailman/3.0
Your team Mailman Checkins is subscribed to branch lp:mailman.
To unsubscribe from this branch go to \
https://code.launchpad.net/~mailman-coders/mailman/3.0/+edit-subscription. \
_______________________________________________ Mailman-checkins mailing list
Mailman-checkins@python.org
Unsubscribe: http://mail.python.org/mailman/options/mailman-checkins/mailman-cvs%40progressive-comp.com
[prev in list] [next in list] [prev in thread] [next in thread]
Configure |
About |
News |
Add a list |
Sponsored by KoreLogic