Hi Ronald,

Will this work (see attached)?

~ Daniel

def getproxies_internetconfig():
    """Return a dictionary of scheme -> proxy server URL mappings.

    By convention the mac uses Internet Config to store
    proxies.  An HTTP proxy, for instance, is stored under
    the HttpProxy key.

    """
    from ctypes import cdll, byref, c_void_p, c_int, c_long, create_string_buffer
    from ctypes.util import find_library

    ic = cdll.LoadLibrary(find_library("Internet_Config"))
    if not ic:
        return {}

    proxies = {}
    icReadOnlyPerm = 1
    icinst = c_void_p(None)
    attr = c_int(0)
    ic.ICStart(byref(icinst), 0)
    ic.ICBegin(icinst, icReadOnlyPerm)
    try:
        # HTTP:
        bsize = c_long(255)
        buff = create_string_buffer(255)
        error = ic.ICGetPref(icinst, "\x0cUseHTTPProxy", byref(attr), byref(buff), byref(bsize))
        useHTTPProxy = not error and ord(buff[0])
        if useHTTPProxy:
            bsize = c_long(255)
            error = ic.ICGetPref(icinst, "\rHTTPProxyHost", byref(attr), byref(buff), byref(bsize))
            if not error and bsize.value > 0:
                # not sure why there's an extra character on the beginning of buff
                proxies["http"] = "http://"; + buff.value[1:bsize.value]

        # FTP: XXXX To be done.
        # Gopher: XXXX To be done.
    finally:
        ic.ICEnd(icinst)
        ic.ICStop(icinst)

    return proxies



On Apr 11, 2008, at 2:05 AM, Ronald Oussoren wrote:
Folks,

The removal of the Carbon bindings shouldn't impact the functionality of the rest of the standard library. This means we need to do some work though, because urllib relies on the Carbon bindings to get the current proxy settings.

The best way to fix that (IMO of course) is to write a small C extension that uses the Carbon API's to fetch that data into a dictionary. All code for that is present in the Python source tree, but in Python instead of in C. Hence writing the extension should be easy enough.

Is anyone game for writing this extension?

Ronald


_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

_______________________________________________
Pythonmac-SIG maillist  -  Pythonmac-SIG@python.org
http://mail.python.org/mailman/listinfo/pythonmac-sig

Reply via email to