views:

19

answers:

1

For the past 10 hours I've been trying to accomplish this:

Translation of my blocking httpclient using standard lib... Into a twisted nonblocking/async version of it.

10 hours later... scoring through their APIs-- it appears no one has EVER needed to do be able to do that. Nice framework, but seems ...a bit overwhelming to just set a socket to a different interface.

Can any python gurus shed some light on this and/or send me in the right direction? or any docs that I could have missed? THANKS!

A: 

Well, it doesn't look like you've missed anything. client.getPage doesn't directly support setting the bind address. I'm just guessing here but I would suspect it's one of those cases where it just never occured to the original developer that someone would want to specify the bind address.

Even though there isn't built-in support for doing this, it should be pretty easy to do. The way you specify binding addresses for outgoing connections in twisted is by passing the bind address to the reactor.connectXXX() functions. Fortunately, the code for getPage() is really simple. I'd suggest three things:

  1. Copy the code for getPage() and it's associated helper function into your project
  2. Modify them to pass through the bind address
  3. Create a patch to fix this oversight and send it to the Twisted folks :)
Rakis
inside of _makeGetterFactory() theres reactor.connectTCP(), I added bindAddress to it and it appears to be working. getPage() is a simple helper function, yea, but what really confused me was that I thought I was able to just send it some overloaded contextFactory or something :/ Thanks for your quick reply, Rakis. I guess it would be well worth learning all this and make a habit of it-- even though it feels like I don't NEED all the features entirely, but since I'm creating a rather big high performance network app... I just hope its as flexible and extendable as Twisted says it is.
Dmitry
Any books or decent documentation covering advanced Twisted (other than the bland API) that you would personally recommend, Rakis?
Dmitry
There's an O'Reilly book on Twisted that's pretty good, however, it's geared more for an intermediate/overview level rather than advanced. The existing docs are rather terse but fairly comprehensive for most common case operations. I've found though that when doing something unusual, I'm often better served by just digging through the Twisted source rather than looking for explicit documentation. It's written by many extremely talented individuals and aside from gaining what I went looking for, I never fail to learn a new trick or two to add to my toolbox ;-)
Rakis
;) Great tip, thanks buddy.
Dmitry