[Twisted-Python] POP3 improvements

Andrew Bennetts andrew-twisted at puzzling.org
Mon Dec 30 20:57:06 EST 2002

On Mon, Dec 30, 2002 at 01:09:52PM -0500, Abe Fettig wrote:
> (diff attached to make it easier to see what I changed)
> On Mon, 2002-12-30 at 11:48, Itamar Shtull-Trauring wrote:
> > 
> > > Currently it works like this:  When you send a command that returns a
> > > multi-line response (LIST or RETR), you pass an optional file-like
> > > object that the response should be written to.  If no file argument is
> > > supplied a StringIO is used.  When the server is finished sending the
> > > response, handle_COMMANDNAME is called, passing back the file object
> > > containing the downloaded response.
> > 
> > Instead of calling handle_COMMANDNAME, why not return a Deferred of the
> > success?
> Based on other Twisted protocol handlers I thought that the preferred
> way to handle events in protocols was to create methods that get called
> in response to events.  That way you create a class that inherits from
> POP3Client, and override the methods for events you want to handle. 
> Being able use classes and inheritance this way is one of the things I
> really like about Twisted.

It depends; if the event is in response to a request, e.g. LIST, it makes
sense to return a Deferred that will receive a list of available messages.
FTPClient works this way, and is very convenient -- an FTPClient user can
queue commands (like LIST, RETR, etc), and as the server responds, the
Deferreds will fire... and there's no confusion if you issue multiple LIST
commands in different directories, whereas a handle_LIST callback doesn't
have the same advantage.

In your case, I'd recommend Deferreds.

If you're writing a server that waits for incoming events, then a
handle_COMMANDNAME scheme would make good sense.

> Also, that's the way it was in the original POP3 module.

Well, if you're breaking backwards-compatibility (are you?), that doesn't
really matter ;)


More information about the Twisted-Python mailing list