Python and Twisted - was Re: Favored Language for Network Enabled Apps.
Michael L Torrie
torriem at chem.byu.edu
Tue Oct 30 12:55:37 MDT 2007
> Michael L Torrie wrote:
>> For developing some kind of tcp/ip server/client system, Python wins,
>> hands down. Twisted for networking, or django for a web frontend (or
>> Turbo Gears. Whatever). A simple, asynchronous, event-driven server
>> complete with a custom protocol can be created with about 10-20 lines of
> As an up-and-coming python hacker, I've been intrigued by what I've read
> about twisted. Does anyone here have experience with it? Can you
> recommend it / advise against it for writing network servers in python?
Twisted has a very steep learning curve. Incredibly steep. Plus
Twisted is a good example of where duck typing can be a real problem.
For example, trying to analyze someone's existing Twisted app can be
very difficult. To even figure out their simple LDAP proxy demo, I had
to run it in a debugger to see just how control was moving through the
program and what the various callback parameters were. Things are
complicated because callback parameters are often marshalled ahead of
time in a closure. Plus the theory of callbacks (deferreds) takes some
thinking to wrap one's head around.
BUT, once you do grasp Twisted, it because a very powerful and quick way
to prototype all kinds of network services. For example I just
installed some new Sharp copiers that have LDAP integration built in.
But here were three problems. First their LDAP bind DNs were not
RFC-compliant (thank MS for promoting this kind of crap), and second we
didn't want everyone in our LDAP database to be able to use the copier.
So enter Twisted. Second, we didn't want all users in LDAP to work on
the copier and third, Sharp used a really silly search filter when
searching for e-mail addresses that made it impossible, for example, to
search for last names.
In just a few lines of code I was able to make an LDAP proxy server that
rewrote the BindDN to have a proper dn, and also to make sure that only
certain user types could access the copier. I also intercepted search
requests and fixed the filter.
If anyone cares, I've attached it as an example for the record. Much of
the logic is contained in the ldaptor proxy class that I am building off
of. It took me may hour before I figured out what the
self._whenConnected() method call was doing. Then I figured out that it
was a very creative way of dealing with the fact that the client may
send multiple requests to the proxy before the proxy has managed to
establish a connection to the real server.
Assistant CSR, System Administrator
Chemistry and Biochemistry Department
Brigham Young University
Provo, UT 84602
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 4706 bytes
Desc: not available
Url : http://plug.org/pipermail/plug/attachments/20071030/6286f878/attachment.py
More information about the PLUG