On Jan 15, 11:34 am, VanL <[email protected]> wrote: > I am writing an IMAP server using Kamaelia right now. According to the > IMAP protocol, most of the time I need to receive single lines > terminated by \r\n. Occasionally, the client declares a size and I > need to keep receiving until I have received <size> bytes. > > I have put together a BufferedReceiver that can handle these two use > cases. It defaults to being a line receiver, but I can switch the mode > back and forth by sending a BufferUntil(value) to the receiver on its > control inbox. > > I have put up the code athttp://pastebin.com/m41eaf698. Could I get > any comments on style, appropriate usage of the Kamaelia components, > whether this is the right way to go about it, etc? > > Thanks, > > Van
Sorry it took so long for someone to get back to you. I've made a bit of a modification here: http://pastebin.com/f7258f0df Here is a summary of the changes I'd suggest: 1. As far as I can tell, the loop to put messages in a separate buffer doesn't seem necessary. You can iterate over the contents of an inbox by calling self.Inbox(boxname) as I've done in your self.handle_control method. I'm sure there's a way to eliminate the inbox loop as well, but that's non-trivial with you appending to it in __init__. 2. I may be missing it somewhere, but the code as written doesn't seem to have any way to shut down. I changed it so that it will check for self.shutdown to be non-False. 3. I moved the self.handle_shutdown() call outside the while loop. This will cause it to only run when the loop is terminated (although I suppose this is more a stylistic change than anything else). For the most part though, your code seems to be doing a good job of being idiomatic and Kamaelic (I believe Michael said that this is an appropriate term). Lastly, have you looked at the DataDeChunker component (http:// www.kamaelia.org/Components/pydoc/Kamaelia.Protocol.Framing.html)? That seems to be about what you're attempting to accomplish. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "kamaelia" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/kamaelia?hl=en -~----------~----~----~----~------~----~------~--~---
