Newbie: trying to twist my head around twisted (and python)
Jan Bakuwel
jan.bakuwel at int.greenpeace.org
Fri Oct 13 12:44:35 EDT 2006
Jean-Paul Calderone wrote:
> The return value of eomReceived is used to determine whether to signal to
> the SMTP client whether the message has been accepted. Regardless of your
> application logic, if you are taking responsibility for the message, you
> should return a successful result. If all of your processing is
> synchronous,
> then you simply need to return twisted.internet.defer.succeed(None) at the
> end of the function. If you have asynchronous processing to do (it does
> not
> appear as though you do), you will need to return a Deferred which only
> fires
> once that processing has been completed.
There's still a bit of mystery in here for me...
I'll be taking responsibility for the message in my code... but perhaps
my code encounters a non resolvable error (such as disc full). In that
case I would like to be able to signal a failure instead of success.
Would the following code do the job "properly"?
def eomReceived(self):
# message is complete, store it
self.lines.append('') # add a trailing newline
messageData = '\n'.join(self.lines)
emailMessage = message_from_string(messageData)
try:
processEmail(emailMessage)
return defer.succeed(None)
except:
return defer.fail
#end eomReceived
thanks,
Jan
More information about the Python-list
mailing list