diff options
| author | Barry Warsaw | 2009-08-26 22:44:22 -0400 |
|---|---|---|
| committer | Barry Warsaw | 2009-08-26 22:44:22 -0400 |
| commit | ca84b1a8852a86464184586441c3d0fd66c879b1 (patch) | |
| tree | 7088ae3181faf51790cddf81c643b71cca1a9cf3 /src | |
| parent | f14553a78083909b31e37a7454258e9ad367e0ae (diff) | |
| download | mailman-ca84b1a8852a86464184586441c3d0fd66c879b1.tar.gz mailman-ca84b1a8852a86464184586441c3d0fd66c879b1.tar.zst mailman-ca84b1a8852a86464184586441c3d0fd66c879b1.zip | |
Diffstat (limited to 'src')
| -rw-r--r-- | src/mailman/app/moderator.py | 14 | ||||
| -rw-r--r-- | src/mailman/app/registrar.py | 8 | ||||
| -rw-r--r-- | src/mailman/bin/checkdbs.py | 4 | ||||
| -rw-r--r-- | src/mailman/chains/hold.py | 4 | ||||
| -rw-r--r-- | src/mailman/config/configure.zcml | 10 | ||||
| -rw-r--r-- | src/mailman/database/__init__.py | 4 | ||||
| -rw-r--r-- | src/mailman/database/requests.py | 10 | ||||
| -rw-r--r-- | src/mailman/docs/chains.txt | 11 | ||||
| -rw-r--r-- | src/mailman/docs/pending.txt | 5 | ||||
| -rw-r--r-- | src/mailman/docs/registration.txt | 5 | ||||
| -rw-r--r-- | src/mailman/docs/requests.txt | 6 | ||||
| -rw-r--r-- | src/mailman/interfaces/database.py | 3 | ||||
| -rw-r--r-- | src/mailman/rules/docs/emergency.txt | 6 |
13 files changed, 53 insertions, 37 deletions
diff --git a/src/mailman/app/moderator.py b/src/mailman/app/moderator.py index 4c5a6b784..1a09567e7 100644 --- a/src/mailman/app/moderator.py +++ b/src/mailman/app/moderator.py @@ -46,7 +46,7 @@ from mailman.email.message import UserNotification from mailman.interfaces.action import Action from mailman.interfaces.member import AlreadySubscribedError, DeliveryMode from mailman.interfaces.messages import IMessageStore -from mailman.interfaces.requests import RequestType +from mailman.interfaces.requests import IRequests, RequestType _ = i18n._ @@ -96,7 +96,7 @@ def hold_message(mlist, msg, msgdata=None, reason=None): msgdata['_mod_reason'] = reason msgdata['_mod_hold_date'] = datetime.now().isoformat() # Now hold this request. We'll use the message_id as the key. - requestsdb = config.db.requests.get_list_requests(mlist) + requestsdb = getUtility(IRequests).get_list_requests(mlist) request_id = requestsdb.hold_request( RequestType.held_message, message_id, msgdata) return request_id @@ -106,7 +106,7 @@ def hold_message(mlist, msg, msgdata=None, reason=None): def handle_message(mlist, id, action, comment=None, preserve=False, forward=None): message_store = getUtility(IMessageStore) - requestdb = config.db.requests.get_list_requests(mlist) + requestdb = getUtility(IRequests).get_list_requests(mlist) key, msgdata = requestdb.get_request(id) # Handle the action. rejection = None @@ -200,7 +200,7 @@ def hold_subscription(mlist, address, realname, password, mode, language): delivery_mode=str(mode), language=language) # Now hold this request. We'll use the address as the key. - requestsdb = config.db.requests.get_list_requests(mlist) + requestsdb = getUtility(IRequests).get_list_requests(mlist) request_id = requestsdb.hold_request( RequestType.subscription, address, data) vlog.info('%s: held subscription request from %s', @@ -226,7 +226,7 @@ def hold_subscription(mlist, address, realname, password, mode, language): def handle_subscription(mlist, id, action, comment=None): - requestdb = config.db.requests.get_list_requests(mlist) + requestdb = getUtility(IRequests).get_list_requests(mlist) if action is Action.defer: # Nothing to do. return @@ -272,7 +272,7 @@ def handle_subscription(mlist, id, action, comment=None): def hold_unsubscription(mlist, address): data = dict(address=address) - requestsdb = config.db.requests.get_list_requests(mlist) + requestsdb = getUtility(IRequests).get_list_requests(mlist) request_id = requestsdb.hold_request( RequestType.unsubscription, address, data) vlog.info('%s: held unsubscription request from %s', @@ -298,7 +298,7 @@ def hold_unsubscription(mlist, address): def handle_unsubscription(mlist, id, action, comment=None): - requestdb = config.db.requests.get_list_requests(mlist) + requestdb = getUtility(IRequests).get_list_requests(mlist) key, data = requestdb.get_request(id) address = data['address'] if action is Action.defer: diff --git a/src/mailman/app/registrar.py b/src/mailman/app/registrar.py index e623fa031..9fc9b8bac 100644 --- a/src/mailman/app/registrar.py +++ b/src/mailman/app/registrar.py @@ -38,7 +38,7 @@ from mailman.i18n import _ from mailman.interfaces.domain import IDomain from mailman.interfaces.listmanager import IListManager from mailman.interfaces.member import MemberRole -from mailman.interfaces.pending import IPendable +from mailman.interfaces.pending import IPendable, IPendings from mailman.interfaces.registrar import IRegistrar from mailman.interfaces.usermanager import IUserManager @@ -68,7 +68,7 @@ class Registrar: real_name=real_name) if mlist is not None: pendable['list_name'] = mlist.fqdn_listname - token = config.db.pendings.add(pendable) + token = getUtility(IPendings).add(pendable) # Set up some local variables for translation interpolation. domain = IDomain(self._context) domain_name = _(domain.email_host) @@ -89,7 +89,7 @@ class Registrar: def confirm(self, token): """See `IUserRegistrar`.""" # For convenience - pendable = config.db.pendings.confirm(token) + pendable = getUtility(IPendings).confirm(token) if pendable is None: return False missing = object() @@ -146,4 +146,4 @@ class Registrar: def discard(self, token): # Throw the record away. - config.db.pendings.confirm(token) + getUtility(IPendings).confirm(token) diff --git a/src/mailman/bin/checkdbs.py b/src/mailman/bin/checkdbs.py index c9789287b..fd116522e 100644 --- a/src/mailman/bin/checkdbs.py +++ b/src/mailman/bin/checkdbs.py @@ -20,6 +20,7 @@ import time import optparse from email.Charset import Charset +from zope.component import getUtility from mailman import MailList from mailman import Utils @@ -27,6 +28,7 @@ from mailman import i18n from mailman.app.requests import handle_request from mailman.configuration import config from mailman.email.message import UserNotification +from mailman.interfaces.requests import IRequests from mailman.version import MAILMAN_VERSION _ = i18n._ @@ -159,7 +161,7 @@ def main(): # The list must be locked in order to open the requests database mlist = MailList.MailList(name) try: - count = config.db.requests.get_list_requests(mlist).count + count = getUtility(IRequests).get_list_requests(mlist).count # While we're at it, let's evict yesterday's autoresponse data midnight_today = midnight() evictions = [] diff --git a/src/mailman/chains/hold.py b/src/mailman/chains/hold.py index 943e4455f..b4b510d3b 100644 --- a/src/mailman/chains/hold.py +++ b/src/mailman/chains/hold.py @@ -41,7 +41,7 @@ from mailman.chains.base import TerminalChainBase from mailman.config import config from mailman.email.message import UserNotification from mailman.interfaces.autorespond import IAutoResponseSet, Response -from mailman.interfaces.pending import IPendable +from mailman.interfaces.pending import IPendable, IPendings from mailman.interfaces.usermanager import IUserManager @@ -142,7 +142,7 @@ class HoldChain(TerminalChainBase): # message. pendable = HeldMessagePendable(type=HeldMessagePendable.PEND_KEY, id=request_id) - token = config.db.pendings.add(pendable) + token = getUtility(IPendings).add(pendable) # Get the language to send the response in. If the sender is a # member, then send it in the member's language, otherwise send it in # the mailing list's preferred language. diff --git a/src/mailman/config/configure.zcml b/src/mailman/config/configure.zcml index 71ddd55c0..325a61f10 100644 --- a/src/mailman/config/configure.zcml +++ b/src/mailman/config/configure.zcml @@ -46,4 +46,14 @@ provides="mailman.interfaces.messages.IMessageStore" /> + <utility + factory="mailman.database.pending.Pendings" + provides="mailman.interfaces.pending.IPendings" + /> + + <utility + factory="mailman.database.requests.Requests" + provides="mailman.interfaces.requests.IRequests" + /> + </configure> diff --git a/src/mailman/database/__init__.py b/src/mailman/database/__init__.py index 7dcd3875f..6e1ae46bb 100644 --- a/src/mailman/database/__init__.py +++ b/src/mailman/database/__init__.py @@ -54,8 +54,6 @@ class StockDatabase: def __init__(self): self.url = None - self.pendings = None - self.requests = None self._store = None def initialize(self, debug=None): @@ -64,8 +62,6 @@ class StockDatabase: # the database at the same time. with Lock(os.path.join(config.LOCK_DIR, 'dbcreate.lck')): self._create(debug) - self.pendings = Pendings() - self.requests = Requests() def begin(self): """See `IDatabase`.""" diff --git a/src/mailman/database/requests.py b/src/mailman/database/requests.py index 249feb6b6..538b97adb 100644 --- a/src/mailman/database/requests.py +++ b/src/mailman/database/requests.py @@ -27,12 +27,13 @@ __all__ = [ from datetime import timedelta from storm.locals import * +from zope.component import getUtility from zope.interface import implements from mailman.config import config from mailman.database.model import Model from mailman.database.types import Enum -from mailman.interfaces.pending import IPendable +from mailman.interfaces.pending import IPendable, IPendings from mailman.interfaces.requests import IListRequests, IRequests, RequestType @@ -84,7 +85,7 @@ class ListRequests: # lock this down more later. pendable = DataPendable() pendable.update(data) - token = config.db.pendings.add(pendable, timedelta(days=5000)) + token = getUtility(IPendings).add(pendable, timedelta(days=5000)) data_hash = token request = _Request(key, request_type, self.mailing_list, data_hash) config.db.store.add(request) @@ -96,7 +97,8 @@ class ListRequests: return None if result.data_hash is None: return result.key, result.data_hash - pendable = config.db.pendings.confirm(result.data_hash, expunge=False) + pendable = getUtility(IPendings).confirm( + result.data_hash, expunge=False) data = dict() data.update(pendable) return result.key, data @@ -106,7 +108,7 @@ class ListRequests: if request is None: raise KeyError(request_id) # Throw away the pended data. - config.db.pendings.confirm(request.data_hash) + getUtility(IPendings).confirm(request.data_hash) config.db.store.remove(request) diff --git a/src/mailman/docs/chains.txt b/src/mailman/docs/chains.txt index bd3a37893..4154d983a 100644 --- a/src/mailman/docs/chains.txt +++ b/src/mailman/docs/chains.txt @@ -227,14 +227,19 @@ first item is a type code and the second item is a message id. ... cookie = mo.group('cookie') ... break >>> assert cookie is not None, 'No confirmation token found' - >>> data = config.db.pendings.confirm(cookie) + + >>> from mailman.interfaces.pending import IPendings + >>> from zope.component import getUtility + + >>> data = getUtility(IPendings).confirm(cookie) >>> sorted(data.items()) [(u'id', ...), (u'type', u'held message')] The message itself is held in the message store. - >>> rkey, rdata = config.db.requests.get_list_requests(mlist).get_request( - ... data['id']) + >>> from mailman.interfaces.requests import IRequests + >>> list_requests = getUtility(IRequests).get_list_requests(mlist) + >>> rkey, rdata = list_requests.get_request(data['id']) >>> from mailman.interfaces.messages import IMessageStore >>> from zope.component import getUtility diff --git a/src/mailman/docs/pending.txt b/src/mailman/docs/pending.txt index 5d7706bf6..bc6d3c470 100644 --- a/src/mailman/docs/pending.txt +++ b/src/mailman/docs/pending.txt @@ -13,9 +13,8 @@ In order to pend an event, you first need a pending database, which is available by adapting the list manager. >>> from mailman.interfaces.pending import IPendings - >>> pendingdb = config.db.pendings - >>> verifyObject(IPendings, pendingdb) - True + >>> from zope.component import getUtility + >>> pendingdb = getUtility(IPendings) The pending database can add any IPendable to the database, returning a token that can be used in urls and such. diff --git a/src/mailman/docs/registration.txt b/src/mailman/docs/registration.txt index de9c29cb4..09cc790ea 100644 --- a/src/mailman/docs/registration.txt +++ b/src/mailman/docs/registration.txt @@ -101,7 +101,10 @@ There should be no records in the user manager for this address yet. But this address is waiting for confirmation. - >>> pendingdb = config.db.pendings + >>> from mailman.interfaces.pending import IPendings + >>> from zope.component import getUtility + >>> pendingdb = getUtility(IPendings) + >>> sorted(pendingdb.confirm(token, expunge=False).items()) [(u'address', u'aperson@example.com'), (u'real_name', u'Anne Person'), diff --git a/src/mailman/docs/requests.txt b/src/mailman/docs/requests.txt index a38c0585a..0113e2274 100644 --- a/src/mailman/docs/requests.txt +++ b/src/mailman/docs/requests.txt @@ -36,11 +36,11 @@ A set of requests are always related to a particular mailing list, so given a mailing list you need to get its requests object. >>> from mailman.interfaces.requests import IListRequests, IRequests + >>> from zope.component import getUtility >>> from zope.interface.verify import verifyObject - >>> verifyObject(IRequests, config.db.requests) - True + >>> mlist = create_list('test@example.com') - >>> requests = config.db.requests.get_list_requests(mlist) + >>> requests = getUtility(IRequests).get_list_requests(mlist) >>> verifyObject(IListRequests, requests) True >>> requests.mailing_list diff --git a/src/mailman/interfaces/database.py b/src/mailman/interfaces/database.py index 19f1d95f0..dd4294d4f 100644 --- a/src/mailman/interfaces/database.py +++ b/src/mailman/interfaces/database.py @@ -83,6 +83,3 @@ class IDatabase(Interface): def abort(): """Abort the current transaction.""" - - pendings = Attribute( - """The IPending instance provided by the database layer.""") diff --git a/src/mailman/rules/docs/emergency.txt b/src/mailman/rules/docs/emergency.txt index 26f10365f..4ee3e8e74 100644 --- a/src/mailman/rules/docs/emergency.txt +++ b/src/mailman/rules/docs/emergency.txt @@ -30,6 +30,8 @@ pending requests. >>> virginq = config.switchboards['virgin'] >>> from mailman.interfaces.messages import IMessageStore + >>> from mailman.interfaces.pending import IPendings + >>> from mailman.interfaces.requests import IRequests >>> from zope.component import getUtility >>> message_store = getUtility(IMessageStore) @@ -49,8 +51,8 @@ pending requests. ... cookie = mo.group('cookie') ... break ... assert cookie is not None, 'No confirmation token found' - ... data = config.db.pendings.confirm(cookie) - ... requestdb = config.db.requests.get_list_requests(mlist) + ... data = getUtility(IPendings).confirm(cookie) + ... requestdb = getUtility(IRequests).get_list_requests(mlist) ... rkey, rdata = requestdb.get_request(data['id']) ... return message_store.get_message_by_id( ... rdata['_mod_message_id']) |
