1
# Copyright (C) 2007 by the Free Software Foundation, Inc.
3
# This program is free software; you can redistribute it and/or
4
# modify it under the terms of the GNU General Public License
5
# as published by the Free Software Foundation; either version 2
6
# of the License, or (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
18
"""Interface describing the basics of chains and links."""
20
from munepy import Enum
21
from zope.interface import Interface, Attribute
25
class LinkAction(Enum):
26
# Jump to another chain.
28
# Take a detour to another chain, returning to the original chain when
29
# completed (if no other jump occurs).
31
# Stop processing all chains.
33
# Continue processing the next link in the chain.
35
# Run a function and continue processing.
40
class IChainLink(Interface):
41
"""A link in the chain."""
43
rule = Attribute('The rule to run for this link.')
45
action = Attribute('The LinkAction to take if this rule matches.')
47
chain = Attribute('The chain to jump or detour to.')
50
"""The function to execute.
52
The function takes three arguments and returns nothing.
53
:param mlist: the IMailingList object
54
:param msg: the message being processed
55
:param msgdata: the message metadata dictionary
60
class IChain(Interface):
61
"""A chain of rules."""
63
name = Attribute('Chain name; must be unique.')
64
description = Attribute('A brief description of the chain.')
66
def get_links(mlist, msg, msgdata):
67
"""Get an `IChainIterator` for processing.
69
:param mlist: the IMailingList object
70
:param msg: the message being processed
71
:param msgdata: the message metadata dictionary
72
:return: An `IChainIterator`.
77
class IChainIterator(Interface):
78
"""An iterator over chain rules."""
81
"""Iterate over all the IChainLinks in this chain.
83
:return: an IChainLink.
88
class IMutableChain(IChain):
89
"""Like `IChain` but can be mutated."""
91
def append_link(link):
92
"""Add a new chain link to the end of this chain.
94
:param link: The chain link to add.
98
"""Delete all links in this chain."""