------------------------------------------------------------
revno: 6792
committer: Barry Warsaw <[email protected]>
branch nick: 3.0
timestamp: Wed 2009-08-26 22:29:20 -0400
message:
Replace the message_store instance on the database with an IMessageStore
utility.
modified:
src/mailman/app/moderator.py
src/mailman/config/configure.zcml
src/mailman/database/__init__.py
src/mailman/docs/chains.txt
src/mailman/docs/messagestore.txt
src/mailman/docs/requests.txt
src/mailman/interfaces/database.py
src/mailman/rules/docs/emergency.txt
src/mailman/testing/layers.py
--
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.
=== modified file 'src/mailman/app/moderator.py'
--- src/mailman/app/moderator.py 2009-07-17 02:36:06 +0000
+++ src/mailman/app/moderator.py 2009-08-27 02:29:20 +0000
@@ -33,6 +33,7 @@
from datetime import datetime
from email.utils import formataddr, formatdate, getaddresses, make_msgid
+from zope.component import getUtility
from mailman import Utils
from mailman import i18n
@@ -44,6 +45,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
@@ -84,7 +86,7 @@
msg['Message-ID'] = message_id = unicode(make_msgid())
assert isinstance(message_id, unicode), (
'Message-ID is not a unicode: %s' % message_id)
- config.db.message_store.add(msg)
+ getUtility(IMessageStore).add(msg)
# Prepare the message metadata with some extra information needed only by
# the moderation interface.
msgdata['_mod_message_id'] = message_id
@@ -103,6 +105,7 @@
def handle_message(mlist, id, action,
comment=None, preserve=False, forward=None):
+ message_store = getUtility(IMessageStore)
requestdb = config.db.requests.get_list_requests(mlist)
key, msgdata = requestdb.get_request(id)
# Handle the action.
@@ -126,7 +129,7 @@
sender, comment or _('[No reason given]'), language)
elif action is Action.accept:
# Start by getting the message from the message store.
- msg = config.db.message_store.get_message_by_id(message_id)
+ msg = message_store.get_message_by_id(message_id)
# Delete moderation-specific entries from the message metadata.
for key in msgdata.keys():
if key.startswith('_mod_'):
@@ -152,7 +155,7 @@
# Forward the message.
if forward:
# Get a copy of the original message from the message store.
- msg = config.db.message_store.get_message_by_id(message_id)
+ msg = message_store.get_message_by_id(message_id)
# It's possible the forwarding address list is a comma separated list
# of realname/address pairs.
addresses = [addr[1] for addr in getaddresses(forward)]
@@ -176,7 +179,7 @@
fmsg.send(mlist)
# Delete the message from the message store if it is not being preserved.
if not preserve:
- config.db.message_store.delete_message(message_id)
+ message_store.delete_message(message_id)
requestdb.delete_request(id)
# Log the rejection
if rejection:
=== modified file 'src/mailman/config/configure.zcml'
--- src/mailman/config/configure.zcml 2009-08-26 14:51:52 +0000
+++ src/mailman/config/configure.zcml 2009-08-27 02:29:20 +0000
@@ -41,4 +41,9 @@
provides="mailman.interfaces.usermanager.IUserManager"
/>
+ <utility
+ factory="mailman.database.messagestore.MessageStore"
+ provides="mailman.interfaces.messages.IMessageStore"
+ />
+
</configure>
=== modified file 'src/mailman/database/__init__.py'
--- src/mailman/database/__init__.py 2009-08-26 14:51:52 +0000
+++ src/mailman/database/__init__.py 2009-08-27 02:29:20 +0000
@@ -54,7 +54,6 @@
def __init__(self):
self.url = None
- self.message_store = None
self.pendings = None
self.requests = None
self._store = None
@@ -65,7 +64,6 @@
# the database at the same time.
with Lock(os.path.join(config.LOCK_DIR, 'dbcreate.lck')):
self._create(debug)
- self.message_store = MessageStore()
self.pendings = Pendings()
self.requests = Requests()
=== modified file 'src/mailman/docs/chains.txt'
--- src/mailman/docs/chains.txt 2009-07-19 02:31:45 +0000
+++ src/mailman/docs/chains.txt 2009-08-27 02:29:20 +0000
@@ -235,8 +235,12 @@
>>> rkey, rdata = config.db.requests.get_list_requests(mlist).get_request(
... data['id'])
- >>> msg = config.db.message_store.get_message_by_id(
+
+ >>> from mailman.interfaces.messages import IMessageStore
+ >>> from zope.component import getUtility
+ >>> msg = getUtility(IMessageStore).get_message_by_id(
... rdata['_mod_message_id'])
+
>>> print msg.as_string()
From: [email protected]
To: [email protected]
=== modified file 'src/mailman/docs/messagestore.txt'
--- src/mailman/docs/messagestore.txt 2009-07-17 05:16:27 +0000
+++ src/mailman/docs/messagestore.txt 2009-08-27 02:29:20 +0000
@@ -1,3 +1,4 @@
+=================
The message store
=================
@@ -7,7 +8,9 @@
object in the internet facing interface of the message store. The
X-Message-ID-Hash is the Base32 SHA1 hash of the Message-ID.
- >>> store = config.db.message_store
+ >>> from mailman.interfaces.messages import IMessageStore
+ >>> from zope.component import getUtility
+ >>> message_store = getUtility(IMessageStore)
If you try to add a message to the store which is missing the Message-ID
header, you will get an exception.
@@ -17,7 +20,7 @@
...
... This message is very important.
... """)
- >>> store.add(msg)
+ >>> message_store.add(msg)
Traceback (most recent call last):
...
ValueError: Exactly one Message-ID header required
@@ -25,7 +28,7 @@
However, if the message has a Message-ID header, it can be stored.
>>> msg['Message-ID'] = '<[email protected]>'
- >>> store.add(msg)
+ >>> message_store.add(msg)
'AGDWSNXXKCWEILKKNYTBOHRDQGOX3Y35'
>>> print msg.as_string()
Subject: An important message
@@ -37,20 +40,20 @@
Finding messages
-----------------
+================
There are several ways to find a message given either the Message-ID or
X-Message-ID-Hash headers. In either case, if no matching message is found,
None is returned.
- >>> print store.get_message_by_id('nothing')
+ >>> print message_store.get_message_by_id('nothing')
None
- >>> print store.get_message_by_hash('nothing')
+ >>> print message_store.get_message_by_hash('nothing')
None
Given an existing Message-ID, the message can be found.
- >>> message = store.get_message_by_id(msg['message-id'])
+ >>> message = message_store.get_message_by_id(msg['message-id'])
>>> print message.as_string()
Subject: An important message
Message-ID: <[email protected]>
@@ -61,7 +64,7 @@
Similarly, we can find messages by the X-Message-ID-Hash:
- >>> message = store.get_message_by_hash(msg['x-message-id-hash'])
+ >>> message = message_store.get_message_by_hash(msg['x-message-id-hash'])
>>> print message.as_string()
Subject: An important message
Message-ID: <[email protected]>
@@ -72,12 +75,12 @@
Iterating over all messages
----------------------------
+===========================
The message store provides a means to iterate over all the messages it
contains.
- >>> messages = list(store.messages)
+ >>> messages = list(message_store.messages)
>>> len(messages)
1
>>> print messages[0].as_string()
@@ -90,13 +93,13 @@
Deleting messages from the store
---------------------------------
+================================
You delete a message from the storage service by providing the Message-ID for
the message you want to delete. If you try to delete a Message-ID that isn't
in the store, you get an exception.
- >>> store.delete_message('nothing')
+ >>> message_store.delete_message('nothing')
Traceback (most recent call last):
...
LookupError: nothing
@@ -104,10 +107,10 @@
But if you delete an existing message, it really gets deleted.
>>> message_id = message['message-id']
- >>> store.delete_message(message_id)
- >>> list(store.messages)
+ >>> message_store.delete_message(message_id)
+ >>> list(message_store.messages)
[]
- >>> print store.get_message_by_id(message_id)
+ >>> print message_store.get_message_by_id(message_id)
None
- >>> print store.get_message_by_hash(message['x-message-id-hash'])
+ >>> print message_store.get_message_by_hash(message['x-message-id-hash'])
None
=== modified file 'src/mailman/docs/requests.txt'
--- src/mailman/docs/requests.txt 2009-08-26 14:51:52 +0000
+++ src/mailman/docs/requests.txt 2009-08-27 02:29:20 +0000
@@ -346,7 +346,12 @@
... """)
>>> id_4 = moderator.hold_message(mlist, msg, {}, 'Needs approval')
>>> moderator.handle_message(mlist, id_4, Action.discard)
- >>> print config.db.message_store.get_message_by_id('<12345>')
+
+ >>> from mailman.interfaces.messages import IMessageStore
+ >>> from zope.component import getUtility
+ >>> message_store = getUtility(IMessageStore)
+
+ >>> print message_store.get_message_by_id('<12345>')
None
But if we ask to preserve the message when we discard it, it will be held in
@@ -354,7 +359,7 @@
>>> id_4 = moderator.hold_message(mlist, msg, {}, 'Needs approval')
>>> moderator.handle_message(mlist, id_4, Action.discard, preserve=True)
- >>> stored_msg = config.db.message_store.get_message_by_id('<12345>')
+ >>> stored_msg = message_store.get_message_by_id('<12345>')
>>> print stored_msg.as_string()
From: [email protected]
To: [email protected]
=== modified file 'src/mailman/interfaces/database.py'
--- src/mailman/interfaces/database.py 2009-08-26 14:51:52 +0000
+++ src/mailman/interfaces/database.py 2009-08-27 02:29:20 +0000
@@ -84,8 +84,5 @@
def abort():
"""Abort the current transaction."""
- message_store = Attribute(
- """The IMessageStore instance provided by the database layer.""")
-
pendings = Attribute(
"""The IPending instance provided by the database layer.""")
=== modified file 'src/mailman/rules/docs/emergency.txt'
--- src/mailman/rules/docs/emergency.txt 2009-07-19 02:31:45 +0000
+++ src/mailman/rules/docs/emergency.txt 2009-08-27 02:29:20 +0000
@@ -29,6 +29,10 @@
>>> virginq = config.switchboards['virgin']
+ >>> from mailman.interfaces.messages import IMessageStore
+ >>> from zope.component import getUtility
+ >>> message_store = getUtility(IMessageStore)
+
>>> def get_held_message():
... import re
... qfiles = []
@@ -48,7 +52,7 @@
... data = config.db.pendings.confirm(cookie)
... requestdb = config.db.requests.get_list_requests(mlist)
... rkey, rdata = requestdb.get_request(data['id'])
- ... return config.db.message_store.get_message_by_id(
+ ... return message_store.get_message_by_id(
... rdata['_mod_message_id'])
>>> msg = get_held_message()
=== modified file 'src/mailman/testing/layers.py'
--- src/mailman/testing/layers.py 2009-07-17 02:36:06 +0000
+++ src/mailman/testing/layers.py 2009-08-27 02:29:20 +0000
@@ -38,12 +38,14 @@
from pkg_resources import resource_string
from textwrap import dedent
from urllib2 import urlopen, URLError
+from zope.component import getUtility
from mailman.config import config
from mailman.core import initialize
from mailman.core.logging import get_handler
from mailman.i18n import _
from mailman.interfaces.domain import IDomainManager
+from mailman.interfaces.messages import IMessageStore
from mailman.testing.helpers import SMTPServer, TestableMaster
from mailman.utilities.datetime import factory
from mailman.utilities.string import expand
@@ -177,8 +179,9 @@
for filename in filenames:
os.remove(os.path.join(dirpath, filename))
# Clear out messages in the message store.
- for message in config.db.message_store.messages:
- config.db.message_store.delete_message(message['message-id'])
+ message_store = getUtility(IMessageStore)
+ for message in message_store.messages:
+ message_store.delete_message(message['message-id'])
config.db.commit()
# Reset the global style manager.
config.style_manager.populate()
_______________________________________________
Mailman-checkins mailing list
[email protected]
Unsubscribe:
http://mail.python.org/mailman/options/mailman-checkins/archive%40jab.org