For the past 10 hours I've been trying to accomplish this:
Translation of my blocking 开发者_JAVA百科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!
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:
- Copy the code for
getPage()
and it's associated helper function into your project - Modify them to pass through the bind address
- Create a patch to fix this oversight and send it to the Twisted folks :)
精彩评论