summaryrefslogtreecommitdiff
path: root/Mailman/app/rules.py
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/app/rules.py
parenta077406487020ecf8dfb7b27e931ca7eb9f5d3b2 (diff)
downloadmailman-0bf7659000d2736839919c1ac2adc99b9bcb1b46.tar.gz
mailman-0bf7659000d2736839919c1ac2adc99b9bcb1b46.tar.zst
mailman-0bf7659000d2736839919c1ac2adc99b9bcb1b46.zip
Diffstat (limited to 'Mailman/app/rules.py')
-rw-r--r--Mailman/app/rules.py49
1 files changed, 10 insertions, 39 deletions
diff --git a/Mailman/app/rules.py b/Mailman/app/rules.py
index 37f5d9af4..948ee7dd7 100644
--- a/Mailman/app/rules.py
+++ b/Mailman/app/rules.py
@@ -15,50 +15,21 @@
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
# USA.
-"""Process all rules defined by entry points."""
+"""Various rule helpers"""
__all__ = [
- 'find_rule',
- 'process',
+ 'initialize',
]
from Mailman.app.plugins import get_plugins
+from Mailman.configuration import config
-def process(mlist, msg, msgdata, rule_set=None):
- """Default rule processing plugin.
-
- Rules are processed in random order.
-
- :param msg: The message object.
- :param msgdata: The message metadata.
- :param rule_set: The name of the rules to run. None (the default) means
- to run all available rules.
- :return: A set of rule names that matched.
- """
- # Collect all rules from all rule processors.
- rules = set()
- for rule_set_class in get_plugins('mailman.rules'):
- rules |= set(rule for rule in rule_set_class().rules
- if rule_set is None or rule.name in rule_set)
- # Now process all rules, returning the set of rules that match.
- rule_matches = set()
- for rule in rules:
- if rule.check(mlist, msg, msgdata):
- rule_matches.add(rule.name)
- return rule_matches
-
-
-
-def find_rule(rule_name):
- """Find the named rule.
-
- :param rule_name: The name of the rule to find.
- :return: The named rule, or None if no such rule exists.
- """
- for rule_set_class in get_plugins('mailman.rules'):
- rule = rule_set_class().get(rule_name)
- if rule is not None:
- return rule
- return None
+def initialize():
+ """Find and register all rules in all plugins."""
+ for rule_finder in get_plugins('mailman.rules'):
+ for rule in rule_finder():
+ assert rule.name not in config.rules, (
+ 'Duplicate rule "%s" found in %s' % (rule.name, rule_finder))
+ config.rules[rule.name] = rule