1 # Copyright (C) 2008-2023 by the Free Software Foundation, Inc.
3 # This file is part of GNU Mailman.
5 # GNU Mailman is free software: you can redistribute it and/or modify it under
6 # the terms of the GNU General Public License as published by the Free
7 # Software Foundation, either version 3 of the License, or (at your option)
10 # GNU Mailman is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 # FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 # You should have received a copy of the GNU General Public License along with
16 # GNU Mailman. If not, see <https://www.gnu.org/licenses/>.
18 """Interface for describing pipelines."""
20 from mailman
.core
.i18n
import _
, format_reasons
21 from public
import public
22 from zope
.interface
import Attribute
, Interface
28 # These are thrown but they aren't exceptions so don't inherit from
29 # mailman.interfaces.errors.MailmanError. Python requires that they inherit
32 class DiscardMessage(BaseException
):
33 """The message can be discarded with no further action"""
35 def __init__(self
, message
=None):
36 self
.message
= message
43 class RejectMessage(BaseException
):
44 """The message will be bounced back to the sender"""
46 def __init__(self
, message
=None, reasons
=None, substitutions
=None):
47 self
.message
= message
48 self
.reasons
= reasons
49 self
.substitutions
= ({} if substitutions
is None else substitutions
)
52 if self
.message
is None:
53 return _('[No details are available]')
54 reasons
= (_('[No reasons given]')
55 if self
.reasons
is None
56 else NL
.join(format_reasons(self
.reasons
)))
57 substitutions
= self
.substitutions
.copy()
58 substitutions
['reasons'] = reasons
59 return _(self
.message
, substitutions
)
63 class IPipeline(Interface
):
64 """A pipeline of handlers."""
66 name
= Attribute('Pipeline name; must be unique.')
67 description
= Attribute('A brief description of this pipeline.')
70 """Iterate over all the handlers in this pipeline."""