summaryrefslogtreecommitdiff
path: root/src/mailman/model/domain.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-22 16:34:15 -0400
committerBarry Warsaw2012-04-22 16:34:15 -0400
commitaa12d1c5a4544e7005a6a93e2fff6e130b30e8b6 (patch)
tree133091548bacfb926f179845c17350c3c8aa1104 /src/mailman/model/domain.py
parentc95c06c080eded049e2f7516d61f579661dfb1c0 (diff)
downloadmailman-aa12d1c5a4544e7005a6a93e2fff6e130b30e8b6.tar.gz
mailman-aa12d1c5a4544e7005a6a93e2fff6e130b30e8b6.tar.zst
mailman-aa12d1c5a4544e7005a6a93e2fff6e130b30e8b6.zip
- Module modernatizations (print function).
- Convert direct use of config.db global to use the @dbconnection decorator.
Diffstat (limited to 'src/mailman/model/domain.py')
-rw-r--r--src/mailman/model/domain.py40
1 files changed, 24 insertions, 16 deletions
diff --git a/src/mailman/model/domain.py b/src/mailman/model/domain.py
index 49c935740..e93335328 100644
--- a/src/mailman/model/domain.py
+++ b/src/mailman/model/domain.py
@@ -17,7 +17,7 @@
"""Domains."""
-from __future__ import unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -31,8 +31,8 @@ from storm.locals import Int, Unicode
from zope.event import notify
from zope.interface import implements
-from mailman.config import config
from mailman.database.model import Model
+from mailman.database.transaction import dbconnection
from mailman.interfaces.domain import (
BadDomainSpecificationError, DomainCreatedEvent, DomainCreatingEvent,
DomainDeletedEvent, DomainDeletingEvent, IDomain, IDomainManager)
@@ -90,9 +90,10 @@ class Domain(Model):
return urlparse(self.base_url).scheme
@property
- def mailing_lists(self):
+ @dbconnection
+ def mailing_lists(self, store):
"""See `IDomain`."""
- mailing_lists = config.db.store.find(
+ mailing_lists = store.find(
MailingList,
MailingList.mail_host == self.mail_host)
for mlist in mailing_lists:
@@ -119,7 +120,9 @@ class DomainManager:
implements(IDomainManager)
- def add(self, mail_host,
+ @dbconnection
+ def add(self, store,
+ mail_host,
description=None,
base_url=None,
contact_address=None):
@@ -131,20 +134,22 @@ class DomainManager:
'Duplicate email host: %s' % mail_host)
notify(DomainCreatingEvent(mail_host))
domain = Domain(mail_host, description, base_url, contact_address)
- config.db.store.add(domain)
+ store.add(domain)
notify(DomainCreatedEvent(domain))
return domain
- def remove(self, mail_host):
+ @dbconnection
+ def remove(self, store, mail_host):
domain = self[mail_host]
notify(DomainDeletingEvent(domain))
- config.db.store.remove(domain)
+ store.remove(domain)
notify(DomainDeletedEvent(mail_host))
return domain
- def get(self, mail_host, default=None):
+ @dbconnection
+ def get(self, store, mail_host, default=None):
"""See `IDomainManager`."""
- domains = config.db.store.find(Domain, mail_host=mail_host)
+ domains = store.find(Domain, mail_host=mail_host)
if domains.count() < 1:
return default
assert domains.count() == 1, (
@@ -159,14 +164,17 @@ class DomainManager:
raise KeyError(mail_host)
return domain
- def __len__(self):
- return config.db.store.find(Domain).count()
+ @dbconnection
+ def __len__(self, store):
+ return store.find(Domain).count()
- def __iter__(self):
+ @dbconnection
+ def __iter__(self, store):
"""See `IDomainManager`."""
- for domain in config.db.store.find(Domain):
+ for domain in store.find(Domain):
yield domain
- def __contains__(self, mail_host):
+ @dbconnection
+ def __contains__(self, store, mail_host):
"""See `IDomainManager`."""
- return config.db.store.find(Domain, mail_host=mail_host).count() > 0
+ return store.find(Domain, mail_host=mail_host).count() > 0