summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBarry Warsaw2008-01-01 22:37:08 -0500
committerBarry Warsaw2008-01-01 22:37:08 -0500
commit6ca002e04d647671d55ee928fe134b0e223606cb (patch)
tree16f0ace720c78d49b06d5587618a82565305c24e
parentadae635a4ca147937019fdd91aebd95a2769b9ca (diff)
downloadmailman-6ca002e04d647671d55ee928fe134b0e223606cb.tar.gz
mailman-6ca002e04d647671d55ee928fe134b0e223606cb.tar.zst
mailman-6ca002e04d647671d55ee928fe134b0e223606cb.zip
Fix the rule api once more so that while rules themselves are still classes,
they are instantiated by the IRuleSet, thus keeping the promises of the interface. The ChainJump enum is moved to interfaces/chain.py. This will be fleshed out subsequently.
-rw-r--r--Mailman/app/rules.py4
-rw-r--r--Mailman/interfaces/rules.py16
-rw-r--r--Mailman/rules/__init__.py10
-rw-r--r--Mailman/rules/docs/rules.txt5
4 files changed, 11 insertions, 24 deletions
diff --git a/Mailman/app/rules.py b/Mailman/app/rules.py
index e4c3c8c40..37f5d9af4 100644
--- a/Mailman/app/rules.py
+++ b/Mailman/app/rules.py
@@ -45,7 +45,7 @@ def process(mlist, msg, msgdata, rule_set=None):
# Now process all rules, returning the set of rules that match.
rule_matches = set()
for rule in rules:
- if rule().check(mlist, msg, msgdata):
+ if rule.check(mlist, msg, msgdata):
rule_matches.add(rule.name)
return rule_matches
@@ -60,5 +60,5 @@ def find_rule(rule_name):
for rule_set_class in get_plugins('mailman.rules'):
rule = rule_set_class().get(rule_name)
if rule is not None:
- return rule()
+ return rule
return None
diff --git a/Mailman/interfaces/rules.py b/Mailman/interfaces/rules.py
index c023acf6b..5549b8e6b 100644
--- a/Mailman/interfaces/rules.py
+++ b/Mailman/interfaces/rules.py
@@ -17,25 +17,10 @@
"""Interface describing the basics of rules."""
-from munepy import Enum
from zope.interface import Interface, Attribute
-class ChainJump(Enum):
- # Allow the next rule in the chain to be run.
- defer = 0
- # Jump to the 'accept' chain.
- accept = 1
- # Jump to the 'hold' chain.
- hold = 2
- # Jump to the 'reject' chain.
- reject = 3
- # Jump to the 'discard' chain.
- discard = 4
-
-
-
class DuplicateRuleError(Exception):
"""A rule or rule name is added to a processor more than once."""
@@ -57,7 +42,6 @@ class IRule(Interface):
:param mlist: The mailing list object.
:param msg: The message object.
:param msgdata: The message metadata.
- :return: A chain to jump to, i.e. an ChainJump enum.
"""
diff --git a/Mailman/rules/__init__.py b/Mailman/rules/__init__.py
index 2a1e2ec2b..299c9f697 100644
--- a/Mailman/rules/__init__.py
+++ b/Mailman/rules/__init__.py
@@ -56,14 +56,18 @@ class BuiltinRules:
def __getitem__(self, rule_name):
"""See `IRuleSet`."""
- return self._rules[rule_name]
+ return self._rules[rule_name]()
def get(self, rule_name, default=None):
"""See `IRuleSet`."""
- return self._rules.get(rule_name, default)
+ 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
+ yield rule()
diff --git a/Mailman/rules/docs/rules.txt b/Mailman/rules/docs/rules.txt
index 4e5db7012..b9606663c 100644
--- a/Mailman/rules/docs/rules.txt
+++ b/Mailman/rules/docs/rules.txt
@@ -13,7 +13,7 @@ only the rule processing system.
Rule sets
-=========
+---------
IRuleSet is the interface that describes a set of rules. Mailman can be
extended by plugging in additional rule sets, but it also comes with a default
@@ -32,7 +32,6 @@ You can iterator over all the rules in a rule set.
>>> rule = None
>>> for rule in rule_set.rules:
... if rule.name == 'emergency':
- ... rule = rule()
... break
>>> verifyObject(IRule, rule)
True
@@ -81,7 +80,7 @@ For example, the emergency rule just checks to see if the emergency flag is
set on the mailing list, and the message has not been pre-approved by the list
administrator.
- >>> rule = rule_set['emergency']()
+ >>> rule = rule_set['emergency']
>>> rule.name
'emergency'
>>> mlist.emergency = False