diff options
Diffstat (limited to 'mailman/database')
| -rw-r--r-- | mailman/database/__init__.py | 8 | ||||
| -rw-r--r-- | mailman/database/address.py | 8 | ||||
| -rw-r--r-- | mailman/database/language.py | 10 | ||||
| -rw-r--r-- | mailman/database/listmanager.py | 8 | ||||
| -rw-r--r-- | mailman/database/mailinglist.py | 39 | ||||
| -rw-r--r-- | mailman/database/member.py | 6 | ||||
| -rw-r--r-- | mailman/database/message.py | 5 | ||||
| -rw-r--r-- | mailman/database/messagestore.py | 14 | ||||
| -rw-r--r-- | mailman/database/model.py | 2 | ||||
| -rw-r--r-- | mailman/database/pending.py | 8 | ||||
| -rw-r--r-- | mailman/database/preferences.py | 12 | ||||
| -rw-r--r-- | mailman/database/requests.py | 2 | ||||
| -rw-r--r-- | mailman/database/roster.py | 14 | ||||
| -rw-r--r-- | mailman/database/transaction.py | 2 | ||||
| -rw-r--r-- | mailman/database/types.py | 13 | ||||
| -rw-r--r-- | mailman/database/user.py | 8 | ||||
| -rw-r--r-- | mailman/database/usermanager.py | 6 | ||||
| -rw-r--r-- | mailman/database/version.py | 4 |
18 files changed, 129 insertions, 40 deletions
diff --git a/mailman/database/__init__.py b/mailman/database/__init__.py index 4c2a60e5d..8b7f584c2 100644 --- a/mailman/database/__init__.py +++ b/mailman/database/__init__.py @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'StockDatabase', @@ -27,7 +29,6 @@ from locknix.lockfile import Lock from lazr.config import as_boolean from pkg_resources import resource_string from storm.locals import create_database, Store -from string import Template from urlparse import urlparse from zope.interface import implements @@ -41,6 +42,7 @@ from mailman.database.requests import Requests from mailman.database.usermanager import UserManager from mailman.database.version import Version from mailman.interfaces.database import IDatabase, SchemaVersionMismatchError +from mailman.utilities.string import expand log = logging.getLogger('mailman.config') @@ -86,7 +88,7 @@ class StockDatabase: def _create(self, debug): # Calculate the engine url. - url = Template(config.database.url).safe_substitute(config.paths) + url = expand(config.database.url, config.paths) log.debug('Database url: %s', url) # XXX By design of SQLite, database file creation does not honor # umask. See their ticket #1193: @@ -123,7 +125,7 @@ class StockDatabase: v = store.find(Version, component=u'schema').one() if not v: # Database has not yet been initialized - v = Version(component=u'schema', + v = Version(component='schema', version=mailman.version.DATABASE_SCHEMA_VERSION) store.add(v) elif v.version <> mailman.version.DATABASE_SCHEMA_VERSION: diff --git a/mailman/database/address.py b/mailman/database/address.py index f9740deaf..528d3af51 100644 --- a/mailman/database/address.py +++ b/mailman/database/address.py @@ -15,6 +15,10 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for addresses.""" + +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Address', @@ -64,10 +68,10 @@ class Address(Model): verified = ('verified' if self.verified_on else 'not verified') address_str = str(self) if self._original is None: - return '<Address: %s [%s] at %#x>' % ( + return '<Address: {0} [{1}] at {2:#x}>'.format( address_str, verified, id(self)) else: - return '<Address: %s [%s] key: %s at %#x>' % ( + return '<Address: {0} [{1}] key: {2} at {3:#x}>'.format( address_str, verified, self.address, id(self)) def subscribe(self, mailing_list, role): diff --git a/mailman/database/language.py b/mailman/database/language.py index 192c9a142..8adc5c4a5 100644 --- a/mailman/database/language.py +++ b/mailman/database/language.py @@ -15,6 +15,16 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for languages.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'Language', + ] + + from storm.locals import * from zope.interface import implements diff --git a/mailman/database/listmanager.py b/mailman/database/listmanager.py index 0a80a773e..346580eb9 100644 --- a/mailman/database/listmanager.py +++ b/mailman/database/listmanager.py @@ -17,6 +17,14 @@ """A mailing list manager.""" +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'ListManager', + ] + + import datetime from zope.interface import implements diff --git a/mailman/database/mailinglist.py b/mailman/database/mailinglist.py index 56caea296..fb45afe96 100644 --- a/mailman/database/mailinglist.py +++ b/mailman/database/mailinglist.py @@ -15,6 +15,16 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for mailing lists.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'MailingList', + ] + + import os import string @@ -28,6 +38,7 @@ from mailman.database import roster from mailman.database.model import Model from mailman.database.types import Enum from mailman.interfaces.mailinglist import IMailingList, Personalization +from mailman.utilities.string import expand SPACE = ' ' @@ -220,42 +231,42 @@ class MailingList(Model): @property def no_reply_address(self): - return '%s@%s' % (config.mailman.noreply_address, self.host_name) + return '{0}@{1}'.format(config.mailman.noreply_address, self.host_name) @property def owner_address(self): - return '%s-owner@%s' % (self.list_name, self.host_name) + return '{0}-owner@{1}'.format(self.list_name, self.host_name) @property def request_address(self): - return '%s-request@%s' % (self.list_name, self.host_name) + return '{0}-request@{1}'.format(self.list_name, self.host_name) @property def bounces_address(self): - return '%s-bounces@%s' % (self.list_name, self.host_name) + return '{0}-bounces@{1}'.format(self.list_name, self.host_name) @property def join_address(self): - return '%s-join@%s' % (self.list_name, self.host_name) + return '{0}-join@{1}'.format(self.list_name, self.host_name) @property def leave_address(self): - return '%s-leave@%s' % (self.list_name, self.host_name) + return '{0}-leave@{1}'.format(self.list_name, self.host_name) @property def subscribe_address(self): - return '%s-subscribe@%s' % (self.list_name, self.host_name) + return '{0}-subscribe@{1}'.format(self.list_name, self.host_name) @property def unsubscribe_address(self): - return '%s-unsubscribe@%s' % (self.list_name, self.host_name) + return '{0}-unsubscribe@{1}'.format(self.list_name, self.host_name) def confirm_address(self, cookie): - template = string.Template(config.mta.verp_confirm_format) - local_part = template.safe_substitute( - address = '%s-confirm' % self.list_name, - cookie = cookie) - return '%s@%s' % (local_part, self.host_name) + local_part = expand(config.mta.verp_confirm_format, dict( + address = '{0}-confirm'.format(self.list_name), + cookie = cookie)) + return '{0}@{1}'.format(local_part, self.host_name) def __repr__(self): - return '<mailing list "%s" at %#x>' % (self.fqdn_listname, id(self)) + return '<mailing list "{0}" at {1:#x}>'.format( + self.fqdn_listname, id(self)) diff --git a/mailman/database/member.py b/mailman/database/member.py index 66d215e4d..22bf042f6 100644 --- a/mailman/database/member.py +++ b/mailman/database/member.py @@ -15,6 +15,10 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for members.""" + +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Member', @@ -51,7 +55,7 @@ class Member(Model): self.is_moderated = False def __repr__(self): - return '<Member: %s on %s as %s>' % ( + return '<Member: {0} on {1} as {2}>'.format( self.address, self.mailing_list, self.role) def _lookup(self, preference): diff --git a/mailman/database/message.py b/mailman/database/message.py index c7ec6bcf6..e77e11429 100644 --- a/mailman/database/message.py +++ b/mailman/database/message.py @@ -15,6 +15,11 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for messages.""" + + +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Message', diff --git a/mailman/database/messagestore.py b/mailman/database/messagestore.py index 38c353172..d16fc93c4 100644 --- a/mailman/database/messagestore.py +++ b/mailman/database/messagestore.py @@ -15,6 +15,11 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for message stores.""" + + +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'MessageStore', @@ -54,8 +59,9 @@ class MessageStore: existing = config.db.store.find(Message, Message.message_id == message_id).one() if existing is not None: - raise ValueError('Message ID already exists in message store: %s', - message_id) + raise ValueError( + 'Message ID already exists in message store: {0}'.format( + message_id)) shaobj = hashlib.sha1(message_id) hash32 = base64.b32encode(shaobj.digest()) del message['X-Message-ID-Hash'] @@ -86,8 +92,8 @@ class MessageStore: # -1 says to use the highest protocol available. pickle.dump(message, fp, -1) break - except IOError, e: - if e.errno <> errno.ENOENT: + except IOError as error: + if error.errno <> errno.ENOENT: raise os.makedirs(os.path.dirname(path)) return hash32 diff --git a/mailman/database/model.py b/mailman/database/model.py index 9a83002bd..85fa033c7 100644 --- a/mailman/database/model.py +++ b/mailman/database/model.py @@ -17,6 +17,8 @@ """Base class for all database classes.""" +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Model', diff --git a/mailman/database/pending.py b/mailman/database/pending.py index dc82085a2..75555b976 100644 --- a/mailman/database/pending.py +++ b/mailman/database/pending.py @@ -17,6 +17,8 @@ """Implementations of the IPendable and IPending interfaces.""" +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Pended', @@ -122,8 +124,8 @@ class Pendings: value = u'__builtin__.bool\1%s' % value elif type(value) is list: # We expect this to be a list of strings. - value = u'mailman.database.pending.unpack_list\1%s' % ( - '\2'.join(value)) + value = ('mailman.database.pending.unpack_list\1' + + '\2'.join(value)) keyval = PendedKeyValue(key=key, value=value) pending.key_values.add(keyval) config.db.store.add(pending) @@ -135,7 +137,7 @@ class Pendings: if pendings.count() == 0: return None assert pendings.count() == 1, ( - 'Unexpected token count: %d' % pendings.count()) + 'Unexpected token count: {0}'.format(pendings.count())) pending = pendings[0] pendable = UnpendedPendable() # Find all PendedKeyValue entries that are associated with the pending diff --git a/mailman/database/preferences.py b/mailman/database/preferences.py index 244a1d2a7..f3ee55673 100644 --- a/mailman/database/preferences.py +++ b/mailman/database/preferences.py @@ -15,6 +15,16 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for preferences.""" + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type +__all__ = [ + 'Preferences', + ] + + from storm.locals import * from zope.interface import implements @@ -37,4 +47,4 @@ class Preferences(Model): delivery_status = Enum() def __repr__(self): - return '<Preferences object at %#x>' % id(self) + return '<Preferences object at {0:#x}>'.format(id(self)) diff --git a/mailman/database/requests.py b/mailman/database/requests.py index 812c5a0ab..249feb6b6 100644 --- a/mailman/database/requests.py +++ b/mailman/database/requests.py @@ -17,6 +17,8 @@ """Implementations of the IRequests and IListRequests interfaces.""" +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Requests', diff --git a/mailman/database/roster.py b/mailman/database/roster.py index fcebfb7f0..fc0a24c7d 100644 --- a/mailman/database/roster.py +++ b/mailman/database/roster.py @@ -22,6 +22,8 @@ the ones that fit a particular role. These are used as the member, owner, moderator, and administrator roster filters. """ +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'AdministratorRoster', @@ -100,8 +102,9 @@ class AbstractRoster: elif results.count() == 1: return results[0] else: - raise AssertionError('Too many matching member results: %s' % - results.count()) + raise AssertionError( + 'Too many matching member results: {0}'.format( + results.count())) @@ -160,7 +163,7 @@ class AdministratorRoster(AbstractRoster): return results[0] else: raise AssertionError( - 'Too many matching member results: %s' % results) + 'Too many matching member results: {0}'.format(results)) @@ -262,5 +265,6 @@ class Memberships: elif results.count() == 1: return results[0] else: - raise AssertionError('Too many matching member results: %s' % - results.count()) + raise AssertionError( + 'Too many matching member results: {0}'.format( + results.count())) diff --git a/mailman/database/transaction.py b/mailman/database/transaction.py index 4663f6110..d42562389 100644 --- a/mailman/database/transaction.py +++ b/mailman/database/transaction.py @@ -17,6 +17,8 @@ """Transactional support.""" +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'txn', diff --git a/mailman/database/types.py b/mailman/database/types.py index 17719c941..2f901fe49 100644 --- a/mailman/database/types.py +++ b/mailman/database/types.py @@ -15,6 +15,12 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Storm type conversions.""" + + +from __future__ import absolute_import, unicode_literals + +__metaclass__ = type __all__ = [ 'Enum', ] @@ -46,9 +52,10 @@ class _EnumVariable(Variable): return None if not to_db: return value - return '%s.%s:%d' % (value.enumclass.__module__, - value.enumclass.__name__, - int(value)) + return '{0}.{1}:{2}'.format( + value.enumclass.__module__, + value.enumclass.__name__, + int(value)) class Enum(SimpleProperty): diff --git a/mailman/database/user.py b/mailman/database/user.py index ec428f0a2..23701686b 100644 --- a/mailman/database/user.py +++ b/mailman/database/user.py @@ -15,6 +15,10 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model for users.""" + +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'User', @@ -48,7 +52,7 @@ class User(Model): preferences = Reference(preferences_id, 'Preferences.id') def __repr__(self): - return '<User "%s" at %#x>' % (self.real_name, id(self)) + return '<User "{0}" at {1:#x}>'.format(self.real_name, id(self)) def link(self, address): """See `IUser`.""" @@ -76,7 +80,7 @@ class User(Model): addrobj = config.db.store.find(Address, address=address).one() if addrobj is None: if real_name is None: - real_name = u'' + real_name = '' addrobj = Address(address=address, real_name=real_name) addrobj.preferences = Preferences() # Link the address to the user if it is not already linked. diff --git a/mailman/database/usermanager.py b/mailman/database/usermanager.py index c30c40d12..3b0c8b534 100644 --- a/mailman/database/usermanager.py +++ b/mailman/database/usermanager.py @@ -17,6 +17,8 @@ """A user manager.""" +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'UserManager', @@ -38,7 +40,7 @@ class UserManager(object): def create_user(self, address=None, real_name=None): user = User() - user.real_name = (u'' if real_name is None else real_name) + user.real_name = ('' if real_name is None else real_name) if address: addrobj = Address(address, user.real_name) addrobj.preferences = Preferences() @@ -71,7 +73,7 @@ class UserManager(object): raise ExistingAddressError(found.original_address) assert addresses.count() == 0, 'Unexpected results' if real_name is None: - real_name = u'' + real_name = '' # It's okay not to lower case the 'address' argument because the # constructor will do the right thing. address = Address(address, real_name) diff --git a/mailman/database/version.py b/mailman/database/version.py index 519c5438c..d15065395 100644 --- a/mailman/database/version.py +++ b/mailman/database/version.py @@ -15,6 +15,10 @@ # You should have received a copy of the GNU General Public License along with # GNU Mailman. If not, see <http://www.gnu.org/licenses/>. +"""Model class for version numbers.""" + +from __future__ import absolute_import, unicode_literals + __metaclass__ = type __all__ = [ 'Version', |
