[PEAK] Interfacing Peak with Twisted

John Landahl john at landahl.org
Wed Mar 16 07:16:48 EST 2005


Tiago Cogumbreiro wrote:
...
> I wanted to test the Peak framework and interface it with Twisted. One
> problem I had was that the wiki page[1] @ devcenter has a file for
> download with 0 byte length. There might be something wrong with it.
> Does someone have it so I can have a glance? The exercise I want to do
> is to extend the bulletins[2] example and add it i) a ZoDB storage ii)
> a xmlrpc frontend (using twisted) and possibly a nevow frontend too.

With PEAK's EventDriven class, using PEAK and Twisted together is very 
simple.  The attached program uses the Example class from Twisted's 
XMLRPC docs [1] within a simple App class derived from EventDriven.  You 
can run it with something like the following:

   PYTHONPATH=. peak import:twisted1.App

The example client code works exactly the same:

   >>> import xmlrpclib
   >>> s = xmlrpclib.Server('http://localhost:7080/')
   >>> s.echo("lala")
   'lala'
   >>> s.add(1, 2)
   3

Note how the Twisted reactor is obtained in the App class, and how the 
__onStart method tells the reactor to listen with the given server 
object and port number.  Using every other Twisted service follows from 
this example, so it should be about as simple to setup a Twisted web 
server for use with Nevow.

- John

[1] http://tinyurl.com/6wl5r
-------------- next part --------------
A non-text attachment was scrubbed...
Name: twisted1.py
Type: application/x-python
Size: 705 bytes
Desc: not available
Url : http://www.eby-sarna.com/pipermail/peak/attachments/20050316/9269cd97/twisted1.bin


More information about the PEAK mailing list