Merge branch 'weblate-gnu-mailman-mailman' into 'master'
[mailman.git] / src / mailman / interfaces / pipeline.py
blob4050474be8930ab3fb296274123cf5f8739d864f
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)
8 # any later version.
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
13 # more details.
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
25 NL = '\n'
28 # These are thrown but they aren't exceptions so don't inherit from
29 # mailman.interfaces.errors.MailmanError. Python requires that they inherit
30 # from BaseException.
31 @public
32 class DiscardMessage(BaseException):
33 """The message can be discarded with no further action"""
35 def __init__(self, message=None):
36 self.message = message
38 def __str__(self):
39 return self.message
42 @public
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)
51 def __str__(self):
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)
62 @public
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.')
69 def __iter__():
70 """Iterate over all the handlers in this pipeline."""