From 84bd61aac16513f30b4ac0cd933c891a9f52c848 Mon Sep 17 00:00:00 2001 From: Stuart Gathman <stuart@gathman.org> Date: Thu, 4 Jun 2009 21:47:34 +0000 Subject: [PATCH] Wrap @noreply callbacks to return NOREPLY only when so negotiated. --- Milter/__init__.py | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/Milter/__init__.py b/Milter/__init__.py index fbd1d2b..f0406da 100755 --- a/Milter/__init__.py +++ b/Milter/__init__.py @@ -46,11 +46,15 @@ def nocallback(func): def noreply(func): try: - func.milter_protocol = OPTIONAL_CALLBACKS[func.__name__][0] + nr_mask = func.milter_protocol = OPTIONAL_CALLBACKS[func.__name__][0] except KeyErro: raise ValueError( '@noreply applied to non-optional method: '+func.__name__) - return func + def wrapper(self,*args): + rc = func(self,*args) + if self._protocol & nr_mask: return NOREPLY + return rc + return wrapper class DisabledAction(RuntimeError): pass @@ -64,6 +68,7 @@ class Base(object): def _setctx(self,ctx): self._ctx = ctx self._actions = CURR_ACTS # all actions enabled by default + self._protocol = 0 # no protocol options by default if ctx: ctx.setpriv(self) def log(self,*msg): pass @@ -89,7 +94,7 @@ class Base(object): def abort(self): return CONTINUE def close(self): return CONTINUE - # Return mask of SMFIP_N.. protocol bits to clear for this class + # Return mask of SMFIP_N.. protocol option bits to clear for this class @classmethod def protocol_mask(klass): try: @@ -109,7 +114,8 @@ class Base(object): def negotiate(self,opts): try: self._actions,p,f1,f2 = opts - opts[1] = p & ~self.protocol_mask() & ~P_RCPT_REJ & ~P_HDR_LEADSPC + opts[1] = self._protocol = \ + p & ~self.protocol_mask() & ~P_RCPT_REJ & ~P_HDR_LEADSPC opts[2] = 0 opts[3] = 0 self.log("Negotiated:",opts) -- GitLab