summaryrefslogtreecommitdiff
path: root/Mailman/rules
diff options
context:
space:
mode:
authorBarry Warsaw2008-01-14 23:22:15 -0500
committerBarry Warsaw2008-01-14 23:22:15 -0500
commit0bf7659000d2736839919c1ac2adc99b9bcb1b46 (patch)
tree7ebc75fb36da6f5de9e8626ae5f05bc52bd81ac1 /Mailman/rules
parenta077406487020ecf8dfb7b27e931ca7eb9f5d3b2 (diff)
downloadmailman-0bf7659000d2736839919c1ac2adc99b9bcb1b46.tar.gz
mailman-0bf7659000d2736839919c1ac2adc99b9bcb1b46.tar.zst
mailman-0bf7659000d2736839919c1ac2adc99b9bcb1b46.zip
Use a more efficient way of deleting rows from a table, which coincidentally
<wink> works around the storm cache bug #178546.
Diffstat (limited to 'Mailman/rules')
-rw-r--r--Mailman/rules/__init__.py65
-rw-r--r--Mailman/rules/any.py40
2 files changed, 61 insertions, 44 deletions
diff --git a/Mailman/rules/__init__.py b/Mailman/rules/__init__.py
index 299c9f697..a78e9bd05 100644
--- a/Mailman/rules/__init__.py
+++ b/Mailman/rules/__init__.py
@@ -17,57 +17,34 @@
"""The built in rule set."""
-__all__ = ['BuiltinRules']
+__all__ = ['initialize']
__metaclass__ = type
import os
import sys
-from zope.interface import implements
-from Mailman.interfaces import DuplicateRuleError, IRule, IRuleSet
+from Mailman.interfaces import IRule
-class BuiltinRules:
- implements(IRuleSet)
+def initialize():
+ """Initialize the built-in rules.
- def __init__(self):
- """The set of all built-in rules."""
- self._rules = {}
- rule_set = set()
- # Find all rules found in all modules inside our package.
- mypackage = self.__class__.__module__
- here = os.path.dirname(sys.modules[mypackage].__file__)
- for filename in os.listdir(here):
- basename, extension = os.path.splitext(filename)
- if extension <> '.py':
- continue
- module_name = mypackage + '.' + basename
- __import__(module_name, fromlist='*')
- module = sys.modules[module_name]
- for name in module.__all__:
- rule = getattr(module, name)
- if IRule.implementedBy(rule):
- if rule.name in self._rules or rule in rule_set:
- raise DuplicateRuleError(rule.name)
- self._rules[rule.name] = rule
- rule_set.add(rule)
-
- def __getitem__(self, rule_name):
- """See `IRuleSet`."""
- return self._rules[rule_name]()
-
- def get(self, rule_name, default=None):
- """See `IRuleSet`."""
- missing = object()
- rule = self._rules.get(rule_name, missing)
- if rule is missing:
- return default
- return rule()
-
- @property
- def rules(self):
- """See `IRuleSet`."""
- for rule in self._rules.values():
- yield rule()
+ Rules are auto-discovered by searching for IRule implementations in all
+ importable modules in this subpackage.
+ """
+ # Find all rules found in all modules inside our package.
+ import Mailman.rules
+ here = os.path.dirname(Mailman.rules.__file__)
+ for filename in os.listdir(here):
+ basename, extension = os.path.splitext(filename)
+ if extension <> '.py':
+ continue
+ module_name = 'Mailman.rules.' + basename
+ __import__(module_name, fromlist='*')
+ module = sys.modules[module_name]
+ for name in module.__all__:
+ rule = getattr(module, name)
+ if IRule.implementedBy(rule):
+ yield rule
diff --git a/Mailman/rules/any.py b/Mailman/rules/any.py
new file mode 100644
index 000000000..b97ad73d2
--- /dev/null
+++ b/Mailman/rules/any.py
@@ -0,0 +1,40 @@
+# Copyright (C) 2007 by the Free Software Foundation, Inc.
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
+# USA.
+
+"""Check if any previous rules have matched."""
+
+__all__ = ['Any']
+__metaclass__ = type
+
+
+from zope.interface import implements
+
+from Mailman.i18n import _
+from Mailman.interfaces import IRule
+
+
+
+class Any:
+ """Look for any previous rule match."""
+ implements(IRule)
+
+ name = 'any'
+ description = _('Look for any previous rule hit.')
+
+ def check(self, mlist, msg, msgdata):
+ """See `IRule`."""
+ return len(msgdata.get('rules', [])) > 0