diff options
| author | Barry Warsaw | 2009-07-10 21:55:26 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2009-07-10 21:55:26 -0400 |
| commit | ac3af23142c9b2417759f90837d68e15866b6793 (patch) | |
| tree | 8c40fb498d2835750eef6277312b20568340b8c1 /src/mailman/rest | |
| parent | c01da236a31f104b3752351ae93956f87b79d821 (diff) | |
| download | mailman-ac3af23142c9b2417759f90837d68e15866b6793.tar.gz mailman-ac3af23142c9b2417759f90837d68e15866b6793.tar.zst mailman-ac3af23142c9b2417759f90837d68e15866b6793.zip | |
Clean a few more lints.
Add get_mailing_lists() which is used just for the web interface. Because of
a bug in lazr.restful, this cannot be a generator.
Similar change in IDomainSet.
Instrument IListManager to be vended through the api.
The REST server must be run in a separate process since SQLite does not like
objects created in one thread to be used in another thread. Note that this
breaks the domain.txt test, but domains really need to be in the database
anyway.
Diffstat (limited to 'src/mailman/rest')
| -rw-r--r-- | src/mailman/rest/adapters.py | 3 | ||||
| -rw-r--r-- | src/mailman/rest/configure.zcml | 3 | ||||
| -rw-r--r-- | src/mailman/rest/docs/lists.txt | 12 | ||||
| -rw-r--r-- | src/mailman/rest/publication.py | 2 | ||||
| -rw-r--r-- | src/mailman/rest/testing/__init__.py | 0 | ||||
| -rw-r--r-- | src/mailman/rest/testing/server.py | 63 | ||||
| -rw-r--r-- | src/mailman/rest/urls.py | 6 | ||||
| -rw-r--r-- | src/mailman/rest/webservice.py | 3 |
8 files changed, 27 insertions, 65 deletions
diff --git a/src/mailman/rest/adapters.py b/src/mailman/rest/adapters.py index b74028eaa..d5ae01498 100644 --- a/src/mailman/rest/adapters.py +++ b/src/mailman/rest/adapters.py @@ -43,8 +43,9 @@ class DomainSet: def __init__(self, config): self._config = config - def __iter__(self): + def get_domains(self): """See `IDomainSet`.""" + # lazr.restful will not allow this to be a generator. domains = self._config.domains return [domains[domain] for domain in sorted(domains)] diff --git a/src/mailman/rest/configure.zcml b/src/mailman/rest/configure.zcml index 5d0a7c08f..164bbd445 100644 --- a/src/mailman/rest/configure.zcml +++ b/src/mailman/rest/configure.zcml @@ -8,8 +8,9 @@ <include package="lazr.restful" file="meta.zcml"/> <include package="lazr.restful" file="configure.zcml"/> - <webservice:register module="mailman.interfaces.system" /> <webservice:register module="mailman.interfaces.domain" /> + <webservice:register module="mailman.interfaces.listmanager" /> + <webservice:register module="mailman.interfaces.system" /> <adapter for="mailman.config.config.IConfiguration" diff --git a/src/mailman/rest/docs/lists.txt b/src/mailman/rest/docs/lists.txt new file mode 100644 index 000000000..5cdf05639 --- /dev/null +++ b/src/mailman/rest/docs/lists.txt @@ -0,0 +1,12 @@ +============= +Mailing lists +============= + +The REST API can be queried for the set of known mailing lists. There is a +top level collection that can return all the mailing lists. There aren't any +yet though. + + >>> dump_json('http://localhost:8001/3.0/lists') + resource_type_link: https://localhost:8001/3.0/#mailing_lists + start: None + total_size: 0 diff --git a/src/mailman/rest/publication.py b/src/mailman/rest/publication.py index a50976102..1b0e1ee00 100644 --- a/src/mailman/rest/publication.py +++ b/src/mailman/rest/publication.py @@ -41,6 +41,7 @@ from mailman.interfaces.rest import IResolvePathNames class Publication: """Very simple implementation of `IPublication`.""" + implements(IPublication) def __init__(self, application): @@ -94,6 +95,7 @@ class Publication: def endRequest(self, request, ob): """Ends the interaction.""" + config.db.commit() endInteraction() diff --git a/src/mailman/rest/testing/__init__.py b/src/mailman/rest/testing/__init__.py deleted file mode 100644 index e69de29bb..000000000 --- a/src/mailman/rest/testing/__init__.py +++ /dev/null diff --git a/src/mailman/rest/testing/server.py b/src/mailman/rest/testing/server.py deleted file mode 100644 index c4fe2f1ec..000000000 --- a/src/mailman/rest/testing/server.py +++ /dev/null @@ -1,63 +0,0 @@ -# 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/>. - -"""A testable REST server.""" - -from __future__ import absolute_import, unicode_literals - -__metaclass__ = type -__all__ = [ - 'TestableServer', - ] - - -import logging -import threading - -from urllib2 import urlopen - -from mailman.rest.webservice import make_server - - -log = logging.getLogger('mailman.http') - - - -class TestableServer: - """A REST server which polls for the stop action.""" - - def __init__(self): - self.server = make_server() - self.event = threading.Event() - self.thread = threading.Thread(target=self.loop) - self.thread.daemon = True - - def start(self): - """Start the server.""" - self.thread.start() - - def stop(self): - """Stop the server by firing the event.""" - self.event.set() - # Fire off one more request so the handle_request() will exit. - fp = urlopen('http://localhost:8001/3.0/system') - fp.close() - self.thread.join() - - def loop(self): - while not self.event.is_set(): - self.server.handle_request() diff --git a/src/mailman/rest/urls.py b/src/mailman/rest/urls.py index fe12a6ed8..38f676c7f 100644 --- a/src/mailman/rest/urls.py +++ b/src/mailman/rest/urls.py @@ -26,6 +26,8 @@ __all__ = [ ] +import logging + from zope.component import adapts from zope.interface import implements, Interface from zope.traversing.browser.interfaces import IAbsoluteURL @@ -35,6 +37,8 @@ from mailman.core.system import system from mailman.rest.configuration import AdminWebServiceConfiguration from mailman.rest.webservice import AdminWebServiceApplication +log = logging.getLogger('mailman.http') + class BasicURLMapper: @@ -72,11 +76,13 @@ class FallbackURLMapper(BasicURLMapper): :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', + #config.db.list_manager: 'lists', } return urls[ob] diff --git a/src/mailman/rest/webservice.py b/src/mailman/rest/webservice.py index a76ad3863..0469e442b 100644 --- a/src/mailman/rest/webservice.py +++ b/src/mailman/rest/webservice.py @@ -49,6 +49,7 @@ log = logging.getLogger('mailman.http') +# pylint: disable-msg: W0232 class AdminWebServiceRequest(WebServiceRequestTraversal, BrowserRequest): """A request for the admin REST interface.""" @@ -81,9 +82,11 @@ class AdminWebServiceApplication: def get(self, name): """Maps root names to resources.""" + log.debug('Getting top level name: %s', name) top_level = dict( system=system, domains=IDomainSet(config), + lists=config.db.list_manager, ) return top_level.get(name) |
