[Twisted-Python] Learning Twisted

Jp Calderone exarkun at divmod.com
Sun May 16 18:13:55 EDT 2004

Jason Diamond wrote:

> Sorry for the length of this post but I learn best by trying to
> explain what I'm learning (even if nobody's listening). Twisted seems
> very cool but also *huge* and unlike any framework I've used before so
> I thought I'd post my first experiences with it in the hopes that I
> could be corrected where needed (and maybe even help people other new
> like me).

I'd like to repeat what Glyph said.  This is great feedback, I'd love to =

see more of it :)

> [snip]
> This is what I came up with:
> from twisted.internet import reactor, protocol
> from twisted.protocols import imap4
> class MyIMAP4Client(imap4.IMAP4Client):
>    def connectionMade(self):
>        imap4.IMAP4Client.connectionMade(self)
>        print "connectionMade"

  The above works (as you noticed ;) but isn't quite as good as hooking =

into the "serverGreeting" method, which is called after the IMAP4 server =

sends its initial message (I realize this isn't well documented).

> [snip]
> Note that this is *not* a method of the MyIMAP4Client class. But it
> worked! I got this printed to the console:
> connectionMade
> loginCallback: ([], 'OK LOGIN Ok.')
> I don't know, however, what the tuple represents. What's that empty
> list? In a perfect world, would this be explained in the IMAP4Client
> documentation? (I'm assuming that every callback would be different.)
  The callback value here is something of an implementation detail.  =

Deferreds (somewhat informally) often fall into one of two categories: =

those which will eventually be called back with an interesting value =

which is necessary for further computations, and those which will =

eventually be called back with a not-so-interesting value which only =

serves to indicate that the desired operation has completed.  login() =

falls into the second category.

> [snip]
> Am I correct in assuming that the IMAP4Client documentation needs some
> buffing up? (Maybe I can help with that.) I didn't look at any source
> code (other than in the HOWTOs) in implementing this so I think that's
> a good sign. But as I mentioned above, I'm not clear on how I know
> what the signature for my callbacks should be or what the parameters
> to those callbacks mean in some cases.

  Yep.  More documentation would be great.  The actual signature for =

callbacks is easy.  It's always a callable that takes one argument (by =

the way, this is why your code worked with both free functions and =

methods - it doesn't matter what kind of callable you use, as long as it =

takes one argument).  Further documentation about the specifics of what =

that one parameter means is definitely needed, though.

> [snip]
> Thanks for reading this far!
  Thanks for writing!


More information about the Twisted-Python mailing list