[Twisted-Python] Basic twisted question
Hi, I'm new to twisted and I have some problems on understandins some basic concepts on building applications upon the twisted framework. The examples in Fettig's book brought me on the right track I think but I'm not sure. So I would like to ask you for some hints and advices. I try to build a small IMAP client which shoul be able so do some very basic operations lke mailboxlisting and fetch some images. Nothing more for the first. Based on Fettig's IMAP examples I did the following: For each operation I want to do I wrote a own protocol. I started with a basic protocol which simply connects to the server. Then in the next step I wrote the protocol which lists the users mailbox. This protocol is inheritated from the first exentend this with the methods to list the mailbox. As you can see I planned to build some kind of inhertance tree for the protcols. Continuing this way I would end up with many small protocols doing one single task, and I'm not sure If this is a good approach. Do you have any comments on this? If it is not clear to you what I meant I can provide some code of course. At the moment this things is pretty small :) best regards Torsten
Torsten Irländer wrote:
Continuing this way I would end up with many small protocols doing one single task, and I'm not sure If this is a good approach.
It sounds like you'd need to switch between those protocols while beeing connected if you want to be able to do several operations, this is not the way to use twisted protocol classes - of course it's ok to work with inheritance, but for one protocol, like IMAP, you'll want one protocol class that does all operations (inherited or else). The http protocol class in twisted for example is responsible for GET, POST, HEAD and all other Request types, and is not split up into different classes for each of these cases. Mind that the protocol usually will, once instatiated from the Factory, stay till the end of that connection, serving subsequent requests, and it'd be of great overhead and hard to implement to exchange it each time another operation is requested. So, one class/leaf of your inheritance tree will have to be able to do all the operations of the protocol you implement. A different use case would be switching from one protocol to another, juice is a protocol that supports this explicitly, you can establish the connection using juice and then switch to a protocol of your choice, fex after authentication is done, but each, juice and the other protocol will be responsible for the whole set of their operations. hth, Johann
On Sat, Jul 29, 2006 at 07:04:39PM +0200, Johann Borck wrote:
Torsten Irländer wrote:
Continuing this way I would end up with many small protocols doing one single task, and I'm not sure If this is a good approach.
It sounds like you'd need to switch between those protocols while beeing connected if you want to be able to do several operations, this is not the way to use twisted protocol classes - of course it's ok to work with inheritance, but for one protocol, like IMAP, you'll want one protocol class that does all operations (inherited or else).
I agree with you. One single protocol class which handles all operations might be the better way. I think my problem is a very basic one and the examples I saw so far all did the following: Build the factory client class wich instanciates the protocol. Within this protcol class all steps to do a single task are more or less automatic. That means that it is triggered by an eventhandler function and then in a series of deferreds and callbacks the task is solved. I.e selecting a Mailbox. This way it is clear to me how to implement a protocol which does one single task, but I'm missing a way how to implement more than one action. I think my problem is that don't know who to start an action in the protocol class which is not triggered by an eventhandler like the "serverGreeting" method in the IMAP examples.
Mind that the protocol usually will, once instatiated from the Factory, stay till the end of that connection, serving subsequent requests,
Yes that is what I want :) But at the moment I connect and disconned to the server for each operation which is indeed a bad way! But as described above it seems that I have some basic problems in understandinding how to do this :( best regards Torsten
participants (2)
-
Johann Borck
-
Torsten Irländer