summaryrefslogtreecommitdiff
path: root/src/mailman/model/bounce.py
diff options
context:
space:
mode:
authorBarry Warsaw2012-04-22 17:33:33 -0400
committerBarry Warsaw2012-04-22 17:33:33 -0400
commit4488631dff02731ff03f2fef01ee27bbd944812b (patch)
treea4064e30019764ffac7f5d65893b49779cb6918b /src/mailman/model/bounce.py
parent7da6bb2bdba138877e53a70d224b253af14c65bc (diff)
parentcd3bab07fe2de591fee0dd27e9d47076a7e7db0f (diff)
downloadmailman-4488631dff02731ff03f2fef01ee27bbd944812b.tar.gz
mailman-4488631dff02731ff03f2fef01ee27bbd944812b.tar.zst
mailman-4488631dff02731ff03f2fef01ee27bbd944812b.zip
Several non-functional improvements to the code base.
Reduce the explicit use of the config.db global by introducing two new helpers: - A new transaction() context manager which will commit the transaction on successful exit, otherwise it will abort the transaction - A new dbconnection decorator which calls the decorated method with the Storm store object as the first argument (after self). This can be used instead of config.db.store. By reducing the explicit use of this global, we have a better chance of refactoring it away in the future. Still TODO: runner.py and lmtp.py. Be explicit about the `store` attribute on the IDatabase interface. More consistent use of __future__ imports. Remove an obsolete command line script.
Diffstat (limited to 'src/mailman/model/bounce.py')
-rw-r--r--src/mailman/model/bounce.py20
1 files changed, 11 insertions, 9 deletions
diff --git a/src/mailman/model/bounce.py b/src/mailman/model/bounce.py
index 8c55e3d16..b957a2243 100644
--- a/src/mailman/model/bounce.py
+++ b/src/mailman/model/bounce.py
@@ -17,7 +17,7 @@
"""Bounce support."""
-from __future__ import absolute_import, unicode_literals
+from __future__ import absolute_import, print_function, unicode_literals
__metaclass__ = type
__all__ = [
@@ -29,8 +29,8 @@ __all__ = [
from storm.locals import Bool, Int, DateTime, Unicode
from zope.interface import implements
-from mailman.config import config
from mailman.database.model import Model
+from mailman.database.transaction import dbconnection
from mailman.database.types import Enum
from mailman.interfaces.bounce import (
BounceContext, IBounceEvent, IBounceProcessor)
@@ -62,21 +62,23 @@ class BounceEvent(Model):
class BounceProcessor:
implements(IBounceProcessor)
- def register(self, mlist, email, msg, where=None):
+ @dbconnection
+ def register(self, store, mlist, email, msg, where=None):
"""See `IBounceProcessor`."""
event = BounceEvent(mlist.fqdn_listname, email, msg, where)
- config.db.store.add(event)
+ store.add(event)
return event
@property
- def events(self):
+ @dbconnection
+ def events(self, store):
"""See `IBounceProcessor`."""
- for event in config.db.store.find(BounceEvent):
+ for event in store.find(BounceEvent):
yield event
@property
- def unprocessed(self):
+ @dbconnection
+ def unprocessed(self, store):
"""See `IBounceProcessor`."""
- for event in config.db.store.find(BounceEvent,
- BounceEvent.processed == False):
+ for event in store.find(BounceEvent, BounceEvent.processed == False):
yield event