[Twisted-Python] twisted.net refactoring
![](https://secure.gravatar.com/avatar/faeb19fbb879e56c1be4a300cfd80ec8.jpg?s=120&d=mm&r=g)
Hi! I've started to work on refactoring twisted.net for minimal dependancies. Currently, in the vein of "research project", what interests me is how layering of protocols in an event-oriented framework can be accomplished. Please have a look at http://moshez.org/protocols.tgz I've written tests for all the protocol handlers I wrote, and I'd be happy to work with anyone who wants to write tests for the irc client and telnet server. Basically, the idea is to turn low-level events (basically just handleData) into high level events (like handleRequest, for HTTP, at the other end of the spectrum). The idea is to reflect the layering of protocols (and only the layering of protocols -- read on) in the classes. So, inheritance happens when the spec references another spec -- e.g., XML-RPC is defined to be over HTTP, so it would be correct to have class XMLRPCHandler(HTTPHandler): def handleRequest(self, command, selector, version, request): ...parse request into Python tuple... result = self.handleMethod(params) ....return HTTP response... But, on the other hand, HTTP does not say anything about TCP/IP, so HTTP should *not* be layered above any transport. This allows us to use SSL, SOCKS or files just as well. One big advantage I'm interested in is testability -- see the examples already there to get my point -- you can bombard your handler hard-coded strings and watch for the answers. -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
This is definitely the direction I want twisted.net to be going in. Thank you for implmenting it (as well as the additional protocols!). Have you started making the requisite changes in net.py as well? On Monday 16 April 2001 16:07, you wrote:
-- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph
![](https://secure.gravatar.com/avatar/faeb19fbb879e56c1be4a300cfd80ec8.jpg?s=120&d=mm&r=g)
On Tue, 17 Apr 2001, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:
Not yet. I'm not *exactly* sure of the design of net.py itself -- it's a bit too big for me to digest it right now. Twisted.net is not the only one that needs to be changed though -- .web, .irc and .telnet should also be modified to take advantage of it. I'm starting to think I want to change my original direction a bit -- just have protocols as twisted.protocols package, think of it as a library that bridges a level mismatch in event-based protocol handling -- that is, transforms low-level events (got chunk of data) into semantic events (got an e-mail message). Then we can port .net and friends over one by one when we have the chance. IOW .net should specialize in things that call .handleData and and supply .write, and .protocols should specialize in providing mixins that supply .handleData and .write -- and never the twain shall meet, except in high-level things like twisted.web or twisted.irc which use .net *and* .protocols to provide useful services. Well, actually, the interface should be enhanced to .goodBye() -- this is a method .net's should provide and .protocol's use to signal the remote end requested a shutdown. Oh, and .welcome() which the .net's should call .net and .protcols should be considered seperate packages that are not allowed to have any dependancy on any part of twisted. So here is a summary - .protocol -- has .welcome() and .handleData method, will call .write() and .goodBye() methods. - .net -- has .write() and .goodBye() methods, will call .welcome() on connecting and .handleData() when the transport layer has data. -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org
![](https://secure.gravatar.com/avatar/e1554622707bedd9202884900430b838.jpg?s=120&d=mm&r=g)
This is definitely the direction I want twisted.net to be going in. Thank you for implmenting it (as well as the additional protocols!). Have you started making the requisite changes in net.py as well? On Monday 16 April 2001 16:07, you wrote:
-- ______ __ __ _____ _ _ | ____ | \_/ |_____] |_____| |_____| |_____ | | | | @ t w i s t e d m a t r i x . c o m http://twistedmatrix.com/users/glyph
![](https://secure.gravatar.com/avatar/faeb19fbb879e56c1be4a300cfd80ec8.jpg?s=120&d=mm&r=g)
On Tue, 17 Apr 2001, Glyph Lefkowitz <glyph@twistedmatrix.com> wrote:
Not yet. I'm not *exactly* sure of the design of net.py itself -- it's a bit too big for me to digest it right now. Twisted.net is not the only one that needs to be changed though -- .web, .irc and .telnet should also be modified to take advantage of it. I'm starting to think I want to change my original direction a bit -- just have protocols as twisted.protocols package, think of it as a library that bridges a level mismatch in event-based protocol handling -- that is, transforms low-level events (got chunk of data) into semantic events (got an e-mail message). Then we can port .net and friends over one by one when we have the chance. IOW .net should specialize in things that call .handleData and and supply .write, and .protocols should specialize in providing mixins that supply .handleData and .write -- and never the twain shall meet, except in high-level things like twisted.web or twisted.irc which use .net *and* .protocols to provide useful services. Well, actually, the interface should be enhanced to .goodBye() -- this is a method .net's should provide and .protocol's use to signal the remote end requested a shutdown. Oh, and .welcome() which the .net's should call .net and .protcols should be considered seperate packages that are not allowed to have any dependancy on any part of twisted. So here is a summary - .protocol -- has .welcome() and .handleData method, will call .write() and .goodBye() methods. - .net -- has .write() and .goodBye() methods, will call .welcome() on connecting and .handleData() when the transport layer has data. -- "I'll be ex-DPL soon anyway so I'm |LUKE: Is Perl better than Python? looking for someplace else to grab power."|YODA: No...no... no. Quicker, -- Wichert Akkerman (on debian-private)| easier, more seductive. For public key, finger moshez@debian.org |http://www.{python,debian,gnu}.org
participants (2)
-
Glyph Lefkowitz
-
Moshe Zadka