From 46f480dfaa6286ff8950af817de1c35910b37e16 Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Sun, 4 Nov 2007 18:10:21 -0500
Subject: Target Mailman onto the Storm <http://storm.canonical.com> Python
 ORM.  This enables a few interesting things:

1. It makes it easier to do our "pillars of storage" idea, where list data and
   messages could live in one database, but user information live in a
   separate database.

2. It reduces the number of moving parts.  SQLAlchemy and Elixir can both go
   away in favor of just one database layer.

3. No more Unicode/string mush hell.  Somewhere along the way the upgrade to
   SQLAlchemy 0.4 and Elixir 0.4 made the strings coming out the database
   sometimes Unicode and sometimes 8-bit.  This was totally unpredictable.
   Storm asserts that if a property is declared Unicode, it comes in and goes
   out as Unicode.

4. 'flush' is gone.

One cost of this is that Storm does not yet currently support schema
generation.  So I cheat by dumping the trunk's SQLite schema and using that as
a starting place for the Storm-based schema.  I hope that Storm will
eventually address this.

Other related changes include:

- SQLALCHEMY_ENGINE_URL is renamed to DEFAULT_DATABASE_URL.  This may still
  get changed.

Things I still want to fix:

- Ickyness with clearing the databases.
- Really implement multiple stores with better management of the Store
  instances.
- Fix all the circular import nasties.
---
 Mailman/database/model/mailman.sql | 206 +++++++++++++++++++++++++++++++++++++
 1 file changed, 206 insertions(+)
 create mode 100644 Mailman/database/model/mailman.sql

(limited to 'Mailman/database/model/mailman.sql')

diff --git a/Mailman/database/model/mailman.sql b/Mailman/database/model/mailman.sql
new file mode 100644
index 000000000..3dabad8c6
--- /dev/null
+++ b/Mailman/database/model/mailman.sql
@@ -0,0 +1,206 @@
+CREATE TABLE _request (
+	id INTEGER NOT NULL, 
+	"key" TEXT, 
+	type TEXT, 
+	data_hash TEXT, 
+	mailing_list_id INTEGER, 
+	PRIMARY KEY (id), 
+	 CONSTRAINT _request_mailing_list_id_fk FOREIGN KEY(mailing_list_id) REFERENCES mailinglist (id)
+);
+CREATE TABLE address (
+	id INTEGER NOT NULL, 
+	address TEXT, 
+	_original TEXT, 
+	real_name TEXT, 
+	verified_on TIMESTAMP, 
+	registered_on TIMESTAMP, 
+	user_id INTEGER, 
+	preferences_id INTEGER, 
+	PRIMARY KEY (id), 
+	 CONSTRAINT address_user_id_fk FOREIGN KEY(user_id) REFERENCES user (id), 
+	 CONSTRAINT address_preferences_id_fk FOREIGN KEY(preferences_id) REFERENCES preferences (id)
+);
+CREATE TABLE language (
+	id INTEGER NOT NULL, 
+	code TEXT, 
+	PRIMARY KEY (id)
+);
+CREATE TABLE mailinglist (
+	id INTEGER NOT NULL, 
+	list_name TEXT, 
+	host_name TEXT, 
+	created_at TIMESTAMP, 
+	web_page_url TEXT, 
+	admin_member_chunksize INTEGER, 
+	hold_and_cmd_autoresponses BLOB, 
+	next_request_id INTEGER, 
+	next_digest_number INTEGER, 
+	admin_responses BLOB, 
+	postings_responses BLOB, 
+	request_responses BLOB, 
+	digest_last_sent_at NUMERIC(10, 2), 
+	one_last_digest BLOB, 
+	volume INTEGER, 
+	last_post_time TIMESTAMP, 
+	accept_these_nonmembers BLOB, 
+	acceptable_aliases BLOB, 
+	admin_immed_notify BOOLEAN, 
+	admin_notify_mchanges BOOLEAN, 
+	administrivia BOOLEAN, 
+	advertised BOOLEAN, 
+	anonymous_list BOOLEAN, 
+	archive BOOLEAN, 
+	archive_private BOOLEAN, 
+	archive_volume_frequency INTEGER, 
+	autorespond_admin BOOLEAN, 
+	autorespond_postings BOOLEAN, 
+	autorespond_requests INTEGER, 
+	autoresponse_admin_text TEXT, 
+	autoresponse_graceperiod TEXT, 
+	autoresponse_postings_text TEXT, 
+	autoresponse_request_text TEXT, 
+	ban_list BLOB, 
+	bounce_info_stale_after TEXT, 
+	bounce_matching_headers TEXT, 
+	bounce_notify_owner_on_disable BOOLEAN, 
+	bounce_notify_owner_on_removal BOOLEAN, 
+	bounce_processing BOOLEAN, 
+	bounce_score_threshold INTEGER, 
+	bounce_unrecognized_goes_to_list_owner BOOLEAN, 
+	bounce_you_are_disabled_warnings INTEGER, 
+	bounce_you_are_disabled_warnings_interval TEXT, 
+	collapse_alternatives BOOLEAN, 
+	convert_html_to_plaintext BOOLEAN, 
+	default_member_moderation BOOLEAN, 
+	description TEXT, 
+	digest_footer TEXT, 
+	digest_header TEXT, 
+	digest_is_default BOOLEAN, 
+	digest_send_periodic BOOLEAN, 
+	digest_size_threshold INTEGER, 
+	digest_volume_frequency INTEGER, 
+	digestable BOOLEAN, 
+	discard_these_nonmembers BLOB, 
+	emergency BOOLEAN, 
+	encode_ascii_prefixes BOOLEAN, 
+	filter_action INTEGER, 
+	filter_content BOOLEAN, 
+	filter_filename_extensions BLOB, 
+	filter_mime_types BLOB, 
+	first_strip_reply_to BOOLEAN, 
+	forward_auto_discards BOOLEAN, 
+	gateway_to_mail BOOLEAN, 
+	gateway_to_news BOOLEAN, 
+	generic_nonmember_action INTEGER, 
+	goodbye_msg TEXT, 
+	header_filter_rules BLOB, 
+	hold_these_nonmembers BLOB, 
+	include_list_post_header BOOLEAN, 
+	include_rfc2369_headers BOOLEAN, 
+	info TEXT, 
+	linked_newsgroup TEXT, 
+	max_days_to_hold INTEGER, 
+	max_message_size INTEGER, 
+	max_num_recipients INTEGER, 
+	member_moderation_action BOOLEAN, 
+	member_moderation_notice TEXT, 
+	mime_is_default_digest BOOLEAN, 
+	moderator_password TEXT, 
+	msg_footer TEXT, 
+	msg_header TEXT, 
+	new_member_options INTEGER, 
+	news_moderation TEXT, 
+	news_prefix_subject_too BOOLEAN, 
+	nntp_host TEXT, 
+	nondigestable BOOLEAN, 
+	nonmember_rejection_notice TEXT, 
+	obscure_addresses BOOLEAN, 
+	pass_filename_extensions BLOB, 
+	pass_mime_types BLOB, 
+	personalize TEXT, 
+	post_id INTEGER, 
+	preferred_language TEXT, 
+	private_roster BOOLEAN, 
+	real_name TEXT, 
+	reject_these_nonmembers BLOB, 
+	reply_goes_to_list TEXT, 
+	reply_to_address TEXT, 
+	require_explicit_destination BOOLEAN, 
+	respond_to_post_requests BOOLEAN, 
+	scrub_nondigest BOOLEAN, 
+	send_goodbye_msg BOOLEAN, 
+	send_reminders BOOLEAN, 
+	send_welcome_msg BOOLEAN, 
+	subject_prefix TEXT, 
+	subscribe_auto_approval BLOB, 
+	subscribe_policy INTEGER, 
+	topics BLOB, 
+	topics_bodylines_limit INTEGER, 
+	topics_enabled BOOLEAN, 
+	unsubscribe_policy INTEGER, 
+	welcome_msg TEXT, 
+	PRIMARY KEY (id)
+);
+CREATE TABLE member (
+	id INTEGER NOT NULL, 
+	role TEXT, 
+	mailing_list TEXT, 
+	address_id INTEGER, 
+	preferences_id INTEGER, 
+	PRIMARY KEY (id), 
+	 CONSTRAINT member_address_id_fk FOREIGN KEY(address_id) REFERENCES address (id), 
+	 CONSTRAINT member_preferences_id_fk FOREIGN KEY(preferences_id) REFERENCES preferences (id)
+);
+CREATE TABLE message (
+	id INTEGER NOT NULL, 
+	hash TEXT, 
+	path TEXT, 
+	message_id TEXT, 
+	PRIMARY KEY (id)
+);
+CREATE TABLE pended (
+	id INTEGER NOT NULL, 
+	token TEXT, 
+	expiration_date TIMESTAMP, 
+	PRIMARY KEY (id)
+);
+CREATE TABLE pendedkeyvalue (
+	id INTEGER NOT NULL, 
+	"key" TEXT, 
+	value TEXT, 
+	pended_id INTEGER, 
+	PRIMARY KEY (id), 
+	 CONSTRAINT pendedkeyvalue_pended_id_fk FOREIGN KEY(pended_id) REFERENCES pended (id)
+);
+CREATE TABLE preferences (
+	id INTEGER NOT NULL, 
+	acknowledge_posts BOOLEAN, 
+	hide_address BOOLEAN, 
+	preferred_language TEXT, 
+	receive_list_copy BOOLEAN, 
+	receive_own_postings BOOLEAN, 
+	delivery_mode TEXT, 
+	delivery_status TEXT, 
+	PRIMARY KEY (id)
+);
+CREATE TABLE user (
+	id INTEGER NOT NULL, 
+	real_name TEXT, 
+	password TEXT, 
+	preferences_id INTEGER, 
+	PRIMARY KEY (id), 
+	 CONSTRAINT user_preferences_id_fk FOREIGN KEY(preferences_id) REFERENCES preferences (id)
+);
+CREATE TABLE version (
+	id INTEGER NOT NULL, 
+	component TEXT, 
+	version INTEGER, 
+	PRIMARY KEY (id)
+);
+CREATE INDEX ix__request_mailing_list_id ON _request (mailing_list_id);
+CREATE INDEX ix_address_preferences_id ON address (preferences_id);
+CREATE INDEX ix_address_user_id ON address (user_id);
+CREATE INDEX ix_member_address_id ON member (address_id);
+CREATE INDEX ix_member_preferences_id ON member (preferences_id);
+CREATE INDEX ix_pendedkeyvalue_pended_id ON pendedkeyvalue (pended_id);
+CREATE INDEX ix_user_preferences_id ON user (preferences_id);
-- 
cgit v1.2.3-70-g09d2


From 58b8ca1c929c5bc0ea1b36fb5e6e683a8830e963 Mon Sep 17 00:00:00 2001
From: Barry Warsaw
Date: Sat, 10 Nov 2007 13:14:51 -0500
Subject: All the simple test fixes are now in, and while there are still some
 failing tests, we're making very good progress.  Just the tough ones are
 left.  This change did modify the the schema a bit, for better naming and
 typing. E.g. 'type' -> 'request_type' and using a RawStr for a hash type.

---
 Mailman/database/listmanager.py    |  5 ++++-
 Mailman/database/messagestore.py   | 29 ++++++++++++++++++++--------
 Mailman/database/model/mailman.sql |  2 +-
 Mailman/database/model/message.py  | 15 +++++++++++----
 Mailman/database/model/pending.py  |  2 +-
 Mailman/database/model/requests.py | 39 ++++++++++++++++----------------------
 Mailman/docs/hold.txt              | 11 +++++------
 Mailman/docs/lifecycle.txt         |  8 ++++----
 Mailman/docs/listmanager.txt       | 26 ++++++++++++-------------
 Mailman/docs/message.txt           |  2 +-
 Mailman/docs/messagestore.txt      |  2 +-
 Mailman/docs/nntp.txt              | 12 ++++++------
 Mailman/docs/outgoing.txt          | 19 +++++++++++++++----
 Mailman/docs/requests.txt          | 13 ++++++-------
 Mailman/docs/runner.txt            |  3 +--
 Mailman/docs/switchboard.txt       |  8 +++-----
 16 files changed, 109 insertions(+), 87 deletions(-)

(limited to 'Mailman/database/model/mailman.sql')

diff --git a/Mailman/database/listmanager.py b/Mailman/database/listmanager.py
index eb1ce6ba2..48e7fe62c 100644
--- a/Mailman/database/listmanager.py
+++ b/Mailman/database/listmanager.py
@@ -43,6 +43,7 @@ class ListManager(object):
             raise Errors.MMListAlreadyExistsError(fqdn_listname)
         mlist = MailingList(fqdn_listname)
         mlist.created_at = datetime.datetime.now()
+        config.db.store.add(mlist)
         return mlist
 
     def delete(self, mlist):
@@ -69,5 +70,7 @@ class ListManager(object):
 
     @property
     def names(self):
-        for mlist in MailingList.query.filter_by().all():
+        # Avoid circular imports.
+        from Mailman.database.model import MailingList
+        for mlist in config.db.store.find(MailingList):
             yield fqdn_listname(mlist.list_name, mlist.host_name)
diff --git a/Mailman/database/messagestore.py b/Mailman/database/messagestore.py
index 87f2fc828..7c90918ac 100644
--- a/Mailman/database/messagestore.py
+++ b/Mailman/database/messagestore.py
@@ -68,10 +68,9 @@ class MessageStore:
         # providing a unique serial number, but to get this information, we
         # have to use a straight insert instead of relying on Elixir to create
         # the object.
-        result = Message.table.insert().execute(
-            hash=hash32, path=relpath, message_id=message_id)
+        row = Message(hash=hash32, path=relpath, message_id=message_id)
         # Add the additional header.
-        seqno = result.last_inserted_ids()[0]
+        seqno = row.id
         del message['X-List-Sequence-Number']
         message['X-List-Sequence-Number'] = str(seqno)
         # Now calculate the full file system path.
@@ -97,11 +96,21 @@ class MessageStore:
             return pickle.load(fp)
 
     def get_messages_by_message_id(self, message_id):
-        for msgrow in Message.query.filter_by(message_id=message_id):
+        # Avoid circular imports.
+        from Mailman.database.model.message import Message
+        for msgrow in config.db.store.find(Message, message_id=message_id):
             yield self._msgobj(msgrow)
 
     def get_messages_by_hash(self, hash):
-        for msgrow in Message.query.filter_by(hash=hash):
+        # Avoid circular imports.
+        from Mailman.database.model.message import Message
+        # It's possible the hash came from a message header, in which case it
+        # will be a Unicode.  However when coming from source code, it will
+        # always be an 8-string.  Coerce to the latter if necessary; it must
+        # be US-ASCII.
+        if isinstance(hash, unicode):
+            hash = hash.encode('ascii')
+        for msgrow in config.db.store.find(Message, hash=hash):
             yield self._msgobj(msgrow)
 
     def _getmsg(self, global_id):
@@ -110,7 +119,9 @@ class MessageStore:
             seqno = int(seqno)
         except ValueError:
             return None
-        messages = Message.query.filter_by(id=seqno)
+        # Avoid circular imports.
+        from Mailman.database.model.message import Message
+        messages = config.db.store.find(Message, id=seqno)
         if messages.count() == 0:
             return None
         assert messages.count() == 1, 'Multiple id matches'
@@ -126,11 +137,13 @@ class MessageStore:
 
     @property
     def messages(self):
-        for msgrow in Message.query.filter_by().all():
+        # Avoid circular imports.
+        from Mailman.database.model.message import Message
+        for msgrow in config.db.store.find(Message):
             yield self._msgobj(msgrow)
 
     def delete_message(self, global_id):
         msgrow = self._getmsg(global_id)
         if msgrow is None:
             raise KeyError(global_id)
-        msgrow.delete()
+        config.db.store.remove(msgrow)
diff --git a/Mailman/database/model/mailman.sql b/Mailman/database/model/mailman.sql
index 3dabad8c6..a20b1b118 100644
--- a/Mailman/database/model/mailman.sql
+++ b/Mailman/database/model/mailman.sql
@@ -1,7 +1,7 @@
 CREATE TABLE _request (
 	id INTEGER NOT NULL, 
 	"key" TEXT, 
-	type TEXT, 
+	request_type TEXT, 
 	data_hash TEXT, 
 	mailing_list_id INTEGER, 
 	PRIMARY KEY (id), 
diff --git a/Mailman/database/model/message.py b/Mailman/database/model/message.py
index 7a6d7371a..c4ea4a636 100644
--- a/Mailman/database/model/message.py
+++ b/Mailman/database/model/message.py
@@ -18,6 +18,7 @@
 from storm.locals import *
 from zope.interface import implements
 
+from Mailman.configuration import config
 from Mailman.database import Model
 from Mailman.interfaces import IMessage
 
@@ -28,8 +29,14 @@ class Message(Model):
 
     implements(IMessage)
 
-    id = Int(primary=True)
-    hash = Unicode()
-    path = Unicode()
-    # This is a Messge-ID field representation, not a database row id.
+    id = Int(primary=True, default=AutoReload)
     message_id = Unicode()
+    hash = RawStr()
+    path = RawStr()
+    # This is a Messge-ID field representation, not a database row id.
+
+    def __init__(self, message_id, hash, path):
+        self.message_id = message_id
+        self.hash = hash
+        self.path = path
+        config.db.store.add(self)
diff --git a/Mailman/database/model/pending.py b/Mailman/database/model/pending.py
index 970e3c16e..be180d7f2 100644
--- a/Mailman/database/model/pending.py
+++ b/Mailman/database/model/pending.py
@@ -110,7 +110,7 @@ class Pendings(object):
         return token
 
     def confirm(self, token, expunge=True):
-        pendings = Pended.query.filter_by(token=token)
+        pendings = config.db.store.find(Pended, token=token)
         if pendings.count() == 0:
             return None
         assert pendings.count() == 1, (
diff --git a/Mailman/database/model/requests.py b/Mailman/database/model/requests.py
index 5e92e70b2..0817388e3 100644
--- a/Mailman/database/model/requests.py
+++ b/Mailman/database/model/requests.py
@@ -53,7 +53,7 @@ class ListRequests:
     def count_of(self, request_type):
         return config.db.store.find(
             _Request,
-            mailing_list=self.mailing_list, type=request_type).count()
+            mailing_list=self.mailing_list, request_type=request_type).count()
 
     @property
     def held_requests(self):
@@ -65,7 +65,7 @@ class ListRequests:
     def of_type(self, request_type):
         results = config.db.store.find(
             _Request,
-            mailing_list=self.mailing_list, type=request_type)
+            mailing_list=self.mailing_list, request_type=request_type)
         for request in results:
             yield request
 
@@ -83,25 +83,12 @@ class ListRequests:
             pendable.update(data)
             token = config.db.pendings.add(pendable, timedelta(days=5000))
             data_hash = token
-        # XXX This would be a good other way to do it, but it causes the
-        # select_by()'s in .count and .held_requests() to fail, even with
-        # flush()'s.
-##         result = _Request.table.insert().execute(
-##             key=key, type=request_type,
-##             mailing_list=self.mailing_list,
-##             data_hash=data_hash)
-##         row_id = result.last_inserted_ids()[0]
-##         return row_id
-        result = _Request(key=key, type=request_type,
-                          mailing_list=self.mailing_list,
-                          data_hash=data_hash)
-        # XXX We need a handle on last_inserted_ids() instead of requiring a
-        # flush of the database to get a valid id.
-        config.db.flush()
-        return result.id
+        request = _Request(key, request_type, self.mailing_list, data_hash)
+        config.db.store.add(request)
+        return request.id
 
     def get_request(self, request_id):
-        result = _Request.get(request_id)
+        result = config.db.store.get(_Request, request_id)
         if result is None:
             return None
         if result.data_hash is None:
@@ -132,10 +119,16 @@ class Requests:
 class _Request(Model):
     """Table for mailing list hold requests."""
 
-    id = Int(primary=True)
+    id = Int(primary=True, default=AutoReload)
     key = Unicode()
-    type = Enum()
-    data_hash = Unicode()
+    request_type = Enum()
+    data_hash = RawStr()
 
     mailing_list_id = Int()
-    mailing_list = Reference(mailing_list_id, 'MailingList')
+    mailing_list = Reference(mailing_list_id, 'MailingList.id')
+
+    def __init__(self, key, request_type, mailing_list, data_hash):
+        self.key = key
+        self.request_type = request_type
+        self.mailing_list = mailing_list
+        self.data_hash = data_hash
diff --git a/Mailman/docs/hold.txt b/Mailman/docs/hold.txt
index 9dae760d8..33c542d31 100644
--- a/Mailman/docs/hold.txt
+++ b/Mailman/docs/hold.txt
@@ -10,12 +10,12 @@ are held when they meet any of a number of criteria.
     >>> from Mailman.Handlers.Hold import process
     >>> from Mailman.queue import Switchboard
     >>> from Mailman.configuration import config
-    >>> mlist = config.db.list_manager.create('_xtest@example.com')
-    >>> mlist.preferred_language = 'en'
-    >>> mlist.real_name = '_XTest'
+    >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
+    >>> mlist.preferred_language = u'en'
+    >>> mlist.real_name = u'_XTest'
     >>> # XXX This will almost certainly change once we've worked out the web
     >>> # space layout for mailing lists now.
-    >>> mlist.web_page_url = 'http://lists.example.com/'
+    >>> mlist.web_page_url = u'http://lists.example.com/'
 
 Here's a helper function used when we don't care about what's in the virgin
 queue or in the pending database.
@@ -41,7 +41,6 @@ Short circuiting
 If the message metadata indicates that the message is pre-approved, then the
 handler returns immediately.
 
-    >>> from email import message_from_string
     >>> msg = message_from_string("""\
     ... From: aperson@example.com
     ...
@@ -109,7 +108,7 @@ Mailman will hold messages that have implicit destination, meaning that the
 mailing list's posting address isn't included in the explicit recipients.
 
     >>> mlist.require_explicit_destination = True
-    >>> mlist.acceptable_aliases = ''
+    >>> mlist.acceptable_aliases = u''
     >>> msg = message_from_string("""\
     ... From: aperson@example.org
     ... Subject: An implicit message
diff --git a/Mailman/docs/lifecycle.txt b/Mailman/docs/lifecycle.txt
index 1a3dfa2bf..ba9c83ef7 100644
--- a/Mailman/docs/lifecycle.txt
+++ b/Mailman/docs/lifecycle.txt
@@ -127,12 +127,12 @@ artifacts.
     >>> from Mailman import Utils
     >>> from Mailman.app.lifecycle import remove_list
     >>> remove_list(mlist_2.fqdn_listname, mlist_2, True)
-    >>> Utils.list_exists('test_2@example.com')
+    >>> Utils.list_exists(u'test_2@example.com')
     False
 
 We should now be able to completely recreate the mailing list.
 
-    >>> mlist_2a = create_list('test_2@example.com', owners)
+    >>> mlist_2a = create_list(u'test_2@example.com', owners)
     >>> sorted(addr.address for addr in mlist_2a.owners.addresses)
-    ['aperson@example.com', 'bperson@example.com',
-     'cperson@example.com', 'dperson@example.com']
+    [u'aperson@example.com', u'bperson@example.com',
+     u'cperson@example.com', u'dperson@example.com']
diff --git a/Mailman/docs/listmanager.txt b/Mailman/docs/listmanager.txt
index 220be05e6..832100aca 100644
--- a/Mailman/docs/listmanager.txt
+++ b/Mailman/docs/listmanager.txt
@@ -19,7 +19,7 @@ Creating a mailing list
 Creating the list returns the newly created IMailList object.
 
     >>> from Mailman.interfaces import IMailingList
-    >>> mlist = listmgr.create('_xtest@example.com')
+    >>> mlist = listmgr.create(u'_xtest@example.com')
     >>> IMailingList.providedBy(mlist)
     True
 
@@ -28,16 +28,16 @@ qualified listname.  This latter is what uniquely distinguishes the mailing
 list to the system.
 
     >>> mlist.list_name
-    '_xtest'
+    u'_xtest'
     >>> mlist.host_name
-    'example.com'
+    u'example.com'
     >>> mlist.fqdn_listname
-    '_xtest@example.com'
+    u'_xtest@example.com'
 
 If you try to create a mailing list with the same name as an existing list,
 you will get an exception.
 
-    >>> mlist_dup = listmgr.create('_xtest@example.com')
+    >>> mlist_dup = listmgr.create(u'_xtest@example.com')
     Traceback (most recent call last):
     ...
     MMListAlreadyExistsError: _xtest@example.com
@@ -54,9 +54,9 @@ Use the list manager to delete a mailing list.
 
 After deleting the list, you can create it again.
 
-    >>> mlist = listmgr.create('_xtest@example.com')
+    >>> mlist = listmgr.create(u'_xtest@example.com')
     >>> mlist.fqdn_listname
-    '_xtest@example.com'
+    u'_xtest@example.com'
 
 
 Retrieving a mailing list
@@ -65,13 +65,13 @@ Retrieving a mailing list
 When a mailing list exists, you can ask the list manager for it and you will
 always get the same object back.
 
-    >>> mlist_2 = listmgr.get('_xtest@example.com')
+    >>> mlist_2 = listmgr.get(u'_xtest@example.com')
     >>> mlist_2 is mlist
     True
 
 If you try to get a list that doesn't existing yet, you get None.
 
-    >>> print listmgr.get('_xtest_2@example.com')
+    >>> print listmgr.get(u'_xtest_2@example.com')
     None
 
 
@@ -81,9 +81,9 @@ Iterating over all mailing lists
 Once you've created a bunch of mailing lists, you can use the list manager to
 iterate over either the list objects, or the list names.
 
-    >>> mlist_3 = listmgr.create('_xtest_3@example.com')
-    >>> mlist_4 = listmgr.create('_xtest_4@example.com')
+    >>> mlist_3 = listmgr.create(u'_xtest_3@example.com')
+    >>> mlist_4 = listmgr.create(u'_xtest_4@example.com')
     >>> sorted(listmgr.names)
-    ['_xtest@example.com', '_xtest_3@example.com', '_xtest_4@example.com']
+    [u'_xtest@example.com', u'_xtest_3@example.com', u'_xtest_4@example.com']
     >>> sorted(m.fqdn_listname for m in listmgr.mailing_lists)
-    ['_xtest@example.com', '_xtest_3@example.com', '_xtest_4@example.com']
+    [u'_xtest@example.com', u'_xtest_3@example.com', u'_xtest_4@example.com']
diff --git a/Mailman/docs/message.txt b/Mailman/docs/message.txt
index 4f0d08ce2..8f1e9c17c 100644
--- a/Mailman/docs/message.txt
+++ b/Mailman/docs/message.txt
@@ -13,7 +13,7 @@ instance, and then calls the .send() method on this object.  This method
 requires a mailing list instance.
 
     >>> from Mailman.configuration import config
-    >>> mlist = config.db.list_manager.create('_xtest@example.com')
+    >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
     >>> mlist.preferred_language = u'en'
 
 The UserNotification constructor takes the recipient address, the sender
diff --git a/Mailman/docs/messagestore.txt b/Mailman/docs/messagestore.txt
index 516ef257b..9b44a7e59 100644
--- a/Mailman/docs/messagestore.txt
+++ b/Mailman/docs/messagestore.txt
@@ -49,7 +49,7 @@ created above.  Because Message-IDs are not guaranteed unique, looking up
 messages with that key resturns a collection.  The collection may be empty if
 there are no matches.
 
-    >>> list(store.get_messages_by_message_id('nothing'))
+    >>> list(store.get_messages_by_message_id(u'nothing'))
     []
 
 Given an existing Message-ID, all matching messages will be found.
diff --git a/Mailman/docs/nntp.txt b/Mailman/docs/nntp.txt
index f8b837388..fefddd8b2 100644
--- a/Mailman/docs/nntp.txt
+++ b/Mailman/docs/nntp.txt
@@ -8,8 +8,8 @@ NNTP is to Usenet as IP is to the web, it's more general than that.
     >>> from Mailman.Handlers.ToUsenet import process
     >>> from Mailman.queue import Switchboard
     >>> from Mailman.configuration import config
-    >>> mlist = config.db.list_manager.create('_xtest@example.com')
-    >>> mlist.preferred_language = 'en'
+    >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
+    >>> mlist.preferred_language = u'en'
     >>> switchboard = Switchboard(config.NEWSQUEUE_DIR)
 
 Gatewaying from the mailing list to the newsgroup happens through a separate
@@ -21,7 +21,7 @@ There are several situations which prevent a message from being gatewayed to
 the newsgroup.  The feature could be disabled, as is the default.
 
     >>> mlist.gateway_to_news = False
-    >>> msg = message_from_string("""\
+    >>> msg = message_from_string(u"""\
     ... Subject: An important message
     ...
     ... Something of great import.
@@ -48,8 +48,8 @@ However, other posted messages get gated to the newsgroup via the nntp queue.
 The list owner can set the linked newsgroup and the nntp host that its
 messages are gated to.
 
-    >>> mlist.linked_newsgroup = 'comp.lang.thing'
-    >>> mlist.nntp_host = 'news.example.com'
+    >>> mlist.linked_newsgroup = u'comp.lang.thing'
+    >>> mlist.nntp_host = u'news.example.com'
     >>> process(mlist, msg, {})
     >>> len(switchboard.files)
     1
@@ -63,6 +63,6 @@ messages are gated to.
     <BLANKLINE>
     >>> sorted(msgdata.items())
     [('_parsemsg', False),
-     ('listname', '_xtest@example.com'),
+     ('listname', u'_xtest@example.com'),
      ('received_time', ...),
      ('version', 3)]
diff --git a/Mailman/docs/outgoing.txt b/Mailman/docs/outgoing.txt
index 48bc287b8..ba2c6430b 100644
--- a/Mailman/docs/outgoing.txt
+++ b/Mailman/docs/outgoing.txt
@@ -12,7 +12,7 @@ headers for unambigous bounce processing.
     >>> from Mailman.Handlers.ToOutgoing import process
     >>> from Mailman.queue import Switchboard
     >>> from Mailman.configuration import config
-    >>> mlist = config.db.list_manager.create('_xtest@example.com')
+    >>> mlist = config.db.list_manager.create(u'_xtest@example.com')
     >>> switchboard = Switchboard(config.OUTQUEUE_DIR)
 
     >>> def queue_size():
@@ -56,7 +56,7 @@ additional key set: the mailing list name.
     >>> sorted(qmsgdata.items())    
     [('_parsemsg', False),
      ('bar', 2), ('foo', 1),
-     ('listname', '_xtest@example.com'),
+     ('listname', u'_xtest@example.com'),
      ('received_time', ...),
      ('verp', True), ('version', 3)]
     >>> queue_size()
@@ -66,9 +66,11 @@ If the list is set to personalize deliveries, and the global configuration
 option to VERP personalized deliveries is set, then the message will be
 VERP'd.
 
+    # Save the original value for clean up.
+    >>> verp_personalized_delivieries = config.VERP_PERSONALIZED_DELIVERIES
+    >>> config.VERP_PERSONALIZED_DELIVERIES = True
     >>> from Mailman.interfaces import Personalization
     >>> mlist.personalize = Personalization.individual
-    >>> config.VERP_PERSONALIZED_DELIVERIES = True
     >>> msgdata = dict(foo=1, bar=2)
     >>> process(mlist, msg, msgdata)
     >>> msgdata['verp']
@@ -92,8 +94,10 @@ the global configuration variable VERP_DELIVERY_INTERVAL.  This variable tells
 Mailman how often to VERP even non-personalized mailing lists.  It can be set
 to zero, which means non-personalized messages will never be VERP'd.
 
-    >>> mlist.personalize = Personalization.none
+    # Save the original value for clean up.
+    >>> verp_delivery_interval = config.VERP_DELIVERY_INTERVAL
     >>> config.VERP_DELIVERY_INTERVAL = 0
+    >>> mlist.personalize = Personalization.none
     >>> msgdata = dict(foo=1, bar=2)
     >>> process(mlist, msg, msgdata)
     >>> print msgdata.get('verp')
@@ -142,3 +146,10 @@ will be VERP'd.
     9 True
     >>> queue_size()
     10
+
+
+Clean up
+========
+
+    >>> config.VERP_PERSONALIZED_DELIVERIES = verp_personalized_delivieries
+    >>> config.VERP_DELIVERY_INTERVAL = verp_delivery_interval
diff --git a/Mailman/docs/requests.txt b/Mailman/docs/requests.txt
index febf3e430..3ef272c9e 100644
--- a/Mailman/docs/requests.txt
+++ b/Mailman/docs/requests.txt
@@ -14,7 +14,7 @@ Here is a helper function for printing out held requests.
     ...         key, data = requests.get_request(request.id)
     ...         if data is not None:
     ...             data = sorted(data.items())
-    ...         print request.id, str(request.type), key, data
+    ...         print request.id, str(request.request_type), key, data
 
 And another helper for displaying messages in the virgin queue.
 
@@ -65,10 +65,10 @@ of associated data.  The request database assigns no semantics to the held
 data, except for the request type.  Here we hold some simple bits of data.
 
     >>> from Mailman.interfaces import RequestType
-    >>> id_1 = requests.hold_request(RequestType.held_message,   'hold_1')
-    >>> id_2 = requests.hold_request(RequestType.subscription,   'hold_2')
-    >>> id_3 = requests.hold_request(RequestType.unsubscription, 'hold_3')
-    >>> id_4 = requests.hold_request(RequestType.held_message,   'hold_4')
+    >>> id_1 = requests.hold_request(RequestType.held_message,   u'hold_1')
+    >>> id_2 = requests.hold_request(RequestType.subscription,   u'hold_2')
+    >>> id_3 = requests.hold_request(RequestType.unsubscription, u'hold_3')
+    >>> id_4 = requests.hold_request(RequestType.held_message,   u'hold_4')
     >>> id_1, id_2, id_3, id_4
     (1, 2, 3, 4)
 
@@ -98,7 +98,7 @@ If we try to hold a request with a bogus type, we get an exception.
 We can hold requests with additional data.
 
     >>> data = dict(foo='yes', bar='no')
-    >>> id_5 = requests.hold_request(RequestType.held_message, 'hold_5', data)
+    >>> id_5 = requests.hold_request(RequestType.held_message, u'hold_5', data)
     >>> id_5
     5
     >>> requests.count
@@ -212,7 +212,6 @@ For this section, we need a mailing list and at least one message.
     >>> mlist = config.db.list_manager.create('alist@example.com')
     >>> mlist.preferred_language = 'en'
     >>> mlist.real_name = 'A Test List'
-    >>> from email import message_from_string
     >>> msg = message_from_string(u"""\
     ... From: aperson@example.org
     ... To: alist@example.com
diff --git a/Mailman/docs/runner.txt b/Mailman/docs/runner.txt
index 4143c36a6..5e5a88d8c 100644
--- a/Mailman/docs/runner.txt
+++ b/Mailman/docs/runner.txt
@@ -64,8 +64,7 @@ on instance variables.
     >>> sorted(runner.msgdata.items())
     [('_parsemsg', False),
      ('bar', 'no'), ('foo', 'yes'),
-     ('lang', 'en'), ('listname', '_xtest@example.com'),
+     ('lang', u'en'), ('listname', u'_xtest@example.com'),
      ('received_time', ...), ('version', 3)]
 
-
 XXX More of the Runner API should be tested.
diff --git a/Mailman/docs/switchboard.txt b/Mailman/docs/switchboard.txt
index ce8f277ed..299aba499 100644
--- a/Mailman/docs/switchboard.txt
+++ b/Mailman/docs/switchboard.txt
@@ -4,21 +4,19 @@ The switchboard
 The switchboard is subsystem that moves messages between queues.  Each
 instance of a switchboard is responsible for one queue directory.
 
-    >>> from email import message_from_string
-    >>> from Mailman.Message import Message
-    >>> from Mailman.queue import Switchboard
-    >>> msg = message_from_string("""\
+    >>> msg = message_from_string(u"""\
     ... From: aperson@example.com
     ... To: _xtest@example.com
     ...
     ... A test message.
-    ... """, Message)
+    ... """)
 
 Create a switchboard by giving its queue directory.
 
     >>> import os
     >>> from Mailman.configuration import config
     >>> queue_directory = os.path.join(config.QUEUE_DIR, 'test')
+    >>> from Mailman.queue import Switchboard
     >>> switchboard = Switchboard(queue_directory)
     >>> switchboard.queue_directory == queue_directory
     True
-- 
cgit v1.2.3-70-g09d2

