pycurl-devs/pycurl — pull request #18 by crass (2013-08-15 19:44:01+00:00)
Title: Pass resolved (address, port) to opensocket callback.

This change brings pycurl closer to supporting all the functionality of libcurl. An example of how this extra information can be used is to create sockets to proxies based on the ultimate address being connected to.

The relevant libcurl docs: http://curl.haxx.se/libcurl/c/curl_easy_setopt.html#CURLOPTOPENSOCKETFUNCTION

I created two implementations, the current one returning the address as a string in its dotted decimal form, and the other returning the address as a byte string of its binary form. The current one, I believe is more pythonic and easier to work with. However, the later does not rely on pycurl to understand and be able to create a string representation of the address, which may be an issue of non-IPv4/6 addresses.

Also, both implementations are not strictly backward compatible for existing python programs using this callback because the callback is assumed to accept 4 arguments. The current implementation could get around this by calling the callback with 4 arguments, then check for a TypeError with a message that the function takes 3 arguments, and finally call the function without the 4th address argument. I don't particularly like this option though because it seems a little hackish and brittle to parse/search the error string, which (I don't know) could be different for different languages. It doesn't seem unreasonable to require existing uses to add a 4th parameter or *args to the callback.

Comments welcome.