Index: urllib.py =================================================================== --- urllib.py (revision 70705) +++ urllib.py (working copy) @@ -1325,35 +1325,35 @@ if sys.platform == 'darwin': - def _CFSetup(sc): + def _CFSetup(sc, cf): from ctypes import c_int32, c_void_p, c_char_p, c_int - sc.CFStringCreateWithCString.argtypes = [ c_void_p, c_char_p, c_int32 ] - sc.CFStringCreateWithCString.restype = c_void_p + cf.CFStringCreateWithCString.argtypes = [ c_void_p, c_char_p, c_int32 ] + cf.CFStringCreateWithCString.restype = c_void_p sc.SCDynamicStoreCopyProxies.argtypes = [ c_void_p ] sc.SCDynamicStoreCopyProxies.restype = c_void_p - sc.CFDictionaryGetValue.argtypes = [ c_void_p, c_void_p ] - sc.CFDictionaryGetValue.restype = c_void_p - sc.CFStringGetLength.argtypes = [ c_void_p ] - sc.CFStringGetLength.restype = c_int32 - sc.CFStringGetCString.argtypes = [ c_void_p, c_char_p, c_int32, c_int32 ] - sc.CFStringGetCString.restype = c_int32 - sc.CFNumberGetValue.argtypes = [ c_void_p, c_int, c_void_p ] - sc.CFNumberGetValue.restype = c_int32 - sc.CFRelease.argtypes = [ c_void_p ] - sc.CFRelease.restype = None + cf.CFDictionaryGetValue.argtypes = [ c_void_p, c_void_p ] + cf.CFDictionaryGetValue.restype = c_void_p + cf.CFStringGetLength.argtypes = [ c_void_p ] + cf.CFStringGetLength.restype = c_int32 + cf.CFStringGetCString.argtypes = [ c_void_p, c_char_p, c_int32, c_int32 ] + cf.CFStringGetCString.restype = c_int32 + cf.CFNumberGetValue.argtypes = [ c_void_p, c_int, c_void_p ] + cf.CFNumberGetValue.restype = c_int32 + cf.CFRelease.argtypes = [ c_void_p ] + cf.CFRelease.restype = None - def _CStringFromCFString(sc, value): + def _CStringFromCFString(cf, value): from ctypes import create_string_buffer - length = sc.CFStringGetLength(value) + 1 + length = cf.CFStringGetLength(value) + 1 buff = create_string_buffer(length) - sc.CFStringGetCString(value, buff, length, 0) + cf.CFStringGetCString(value, buff, length, 0) return buff.value - def _CFNumberToInt32(sc, cfnum): + def _CFNumberToInt32(cf, cfnum): from ctypes import byref, c_int val = c_int() kCFNumberSInt32Type = 3 - sc.CFNumberGetValue(cfnum, kCFNumberSInt32Type, byref(val)) + cf.CFNumberGetValue(cfnum, kCFNumberSInt32Type, byref(val)) return val.value @@ -1378,15 +1378,18 @@ return (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3] sc = cdll.LoadLibrary(find_library("SystemConfiguration")) - _CFSetup(sc) + cf = cdll.LoadLibrary(find_library("CoreFoundation")) + _CFSetup(sc, cf) hostIP = None if not sc: return False + if not cf: + return False - kSCPropNetProxiesExceptionsList = sc.CFStringCreateWithCString(0, "ExceptionsList", 0) - kSCPropNetProxiesExcludeSimpleHostnames = sc.CFStringCreateWithCString(0, + kSCPropNetProxiesExceptionsList = cf.CFStringCreateWithCString(0, "ExceptionsList", 0) + kSCPropNetProxiesExcludeSimpleHostnames = cf.CFStringCreateWithCString(0, "ExcludeSimpleHostnames", 0) @@ -1397,20 +1400,20 @@ try: # Check for simple host names: if '.' not in host: - exclude_simple = sc.CFDictionaryGetValue(proxyDict, + exclude_simple = cf.CFDictionaryGetValue(proxyDict, kSCPropNetProxiesExcludeSimpleHostnames) - if exclude_simple and _CFNumberToInt32(sc, exclude_simple): + if exclude_simple and _CFNumberToInt32(cf, exclude_simple): return True # Check the exceptions list: - exceptions = sc.CFDictionaryGetValue(proxyDict, kSCPropNetProxiesExceptionsList) + exceptions = cf.CFDictionaryGetValue(proxyDict, kSCPropNetProxiesExceptionsList) if exceptions: # Items in the list are strings like these: *.local, 169.254/16 - for index in xrange(sc.CFArrayGetCount(exceptions)): - value = sc.CFArrayGetValueAtIndex(exceptions, index) + for index in xrange(cf.CFArrayGetCount(exceptions)): + value = cf.CFArrayGetValueAtIndex(exceptions, index) if not value: continue - value = _CStringFromCFString(sc, value) + value = _CStringFromCFString(cf, value) m = re.match(r"(\d+(?:\.\d+)*)(/\d+)?", value) if m is not None: @@ -1431,8 +1434,8 @@ return False finally: - sc.CFRelease(kSCPropNetProxiesExceptionsList) - sc.CFRelease(kSCPropNetProxiesExcludeSimpleHostnames) + cf.CFRelease(kSCPropNetProxiesExceptionsList) + cf.CFRelease(kSCPropNetProxiesExcludeSimpleHostnames)