[Twisted-Python] POP3 improvements

Andrew Bennetts andrew-twisted at puzzling.org
Tue Dec 31 01:16:39 EST 2002

On Tue, Dec 31, 2002 at 12:47:24AM -0500, Christopher Armstrong wrote:
> The one other place where I thought this might be useful is in
> IRCClient. IRC commands often result in several messages in response
> -- something like list, or whois, for example. If we wanted to
> abstract this interface, we could have a "list" method that returned a
> Deferred that didn't trigger until *all* the list lines have been
> received.

Actually, I just realised, I fibbed about FTPClient... it does something
a little unusual, and I'm interested in opinions on this.

Say you call FTPClient.list().  You don't get a Deferred, you actually have
to pass in a Protocol *instance*, and as the data for FTPClient.list is
received, it gets passed straight to that Protocol, via dataReceived.  In
fact, the FTPClient internally makes a Factory for that connection, which
(essentially) uses that Protocol, but that's an implementation detail.  This
is a bit weird, though, because using an FTPClient involves creating
Protocols without associated Factories, and nowhere else in Twisted does

[The reason why I got confused about Deferreds in the interface, is that I
use Deferreds internally in FTPClient to manage all this.]

So this is actually another interface, possibly specific to FTP, where you
pass a Protocol instance -- this allows for progressive processing of data,
rather than all-at-once, and this feels "more Twisted" to me :)
So, to parse the results of an FTP listing, you pass in a
FTPFileListProtocol... this is useful, but there probably should be a
higher-level interface to this that returns a Deferred, for when you don't
need to do custom parsing and don't care about progressive processing (i.e.
most of the time).

> So, as an _implementation_ strategy, the "handle_FOO" methods are
> great when the mapping of message-level request to message-level
> response is 1:many, and for interfaces, Deferreds are great.

Agreed.  In FTP, there is, basically, only one response per request, so I
don't have need for handle_FOO in the FTPClient.  In POP3, I think the
situation is similar (but simpler than FTP).  For IRC, handle_FOO makes good


More information about the Twisted-Python mailing list