1# Copyright (C) 2008-2020 by the Free Software Foundation, Inc. 2# 3# This file is part of GNU Mailman. 4# 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. 9# 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. 14# 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/>. 17 18"""Interface for describing pipelines.""" 19 20from mailman.core.i18n import _, format_reasons 21from public import public 22from zope.interface import Attribute, Interface 23 24 25NL = '\n' 26 27 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 32class DiscardMessage(BaseException): 33 """The message can be discarded with no further action""" 34 35 def __init__(self, message=None): 36 self.message = message 37 38 def __str__(self): 39 return self.message 40 41 42@public 43class RejectMessage(BaseException): 44 """The message will be bounced back to the sender""" 45 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) 50 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) 60 61 62@public 63class IPipeline(Interface): 64 """A pipeline of handlers.""" 65 66 name = Attribute('Pipeline name; must be unique.') 67 description = Attribute('A brief description of this pipeline.') 68 69 def __iter__(): 70 """Iterate over all the handlers in this pipeline.""" 71