From: <po...@or...> - 2003-07-14 20:08:52
|
Drew Perttula <dr...@bi...> writes: > I'm a huge fan of your dispatcher.py system; I recommend it all the time > on the #python channel. My current project has a client and server which > communicate via XMLRPC. I wanted the client to call a method deep in > the server process somewhere, and it was going to be silly to connect > all the relevant objects (from the xmlrpc server obj all the way to > the receiver obj, in a faraway module). So, within about half an hour, > I was able to make the following: > > ######## client.py ##################### > > import xmlrpclib > import dispatcher > > serv=xmlrpclib.Server('http://localhost:12345') > > # send all dispatcher signals over to the xmlrpc server > def signal_over_xmlrpc(sender="<none>",**kwds): > """send this signal to the xmlrpc server where it will get > re-raised there""" > print serv.generate_signal(kwds) > dispatcher.connect(signal_over_xmlrpc) > > ... > > dispatcher.send("hover",ang=75) > > > > ######## server.py ##################### > > > from twisted.internet import reactor > from twisted.web import xmlrpc, server > import dispatcher > > class Show(xmlrpc.XMLRPC): > def __init__(self): > ..arrange for all methods to be accessible via xmlrpc.. > > def generate_signal(self,kwds): > dispatcher.send(**kwds) > return "sent signal "+str(kwds['signal']) > > reactor.listenTCP(12345,server.Site(Show())) > reactor.run() > > ##################################### > > Hopefully I pasted all the essentials. The big catch is that all > signals, senders, and other dispatcher.send() arguments have to be XMLRPC > marshalable. NoneType is not marshalable, which is why I have the little > sender="<none>" workaround. > > I'm in a hurry to get my project working for this weekend, but someday > I may be able to refine the XMLRPC tunnel system and maybe even pack it > in a module of its own. > > My own dispatcher.py is slightly patched to log the receivers (using > the new logging module). I also noticed you pitched the module on > some Zope3 page, which I'm all for. Do you imagine hosting the module > as a distutils package someplace? I could contribute docs, examples, > and related stuff such as the XMLRPC tunnel. > > I think I'd prefer if the authoritative site wasn't the ASPN Cookbook, > as I'd like to send users of my projects to a site that says "get this, > run setup.py install" instead of a "here's something hackers like, > and you can paste it into your own file to run it" site. Of course, > stdlib acceptance would solve my problem even better. :) > > Thanks for the great work! You're welcome. Just wanted to let you know that I finally got around to setting up a SourceForge project for dispatcher. Mike Fletcher has done a ton of work to get the files in shape, write unit tests, docs, etc. We'd love to have your help as well. Just let us know how you would like to be involved. The project is here: http://sourceforge.net/projects/pydispatcher/ Be sure to sign up for the developer mailing list as well: http://lists.sourceforge.net/lists/listinfo/pydispatcher-devel -- Patrick K. O'Brien Orbtech http://www.orbtech.com/web/pobrien ----------------------------------------------- "Your source for Python programming expertise." ----------------------------------------------- |