summaryrefslogtreecommitdiffstats
path: root/Lib/urllib.py
diff options
context:
space:
mode:
authorRonald Oussoren <ronaldoussoren@mac.com>2008-05-18 20:09:54 (GMT)
committerRonald Oussoren <ronaldoussoren@mac.com>2008-05-18 20:09:54 (GMT)
commit099646f29a7521318fd8a9753ee4522769488122 (patch)
treee194df5f24797fbb09511614bd04cdced023d93d /Lib/urllib.py
parent8632cc2573eec74d610d18ae978e349dcc778154 (diff)
downloadcpython-099646f29a7521318fd8a9753ee4522769488122.zip
cpython-099646f29a7521318fd8a9753ee4522769488122.tar.gz
cpython-099646f29a7521318fd8a9753ee4522769488122.tar.bz2
MacOSX: ctypes annotation in implementation of getproxies_macosx_sysconf
getproxies_macosx_sysconf uses ctypes to call SystemConfiguration APIs. This checkin adds ctypes annotation to specify the right argument types for the API's that are used. This is needed to be able to use urllib on a 64-bit system, without annotations you'd get a hard crash.
Diffstat (limited to 'Lib/urllib.py')
-rw-r--r--Lib/urllib.py23
1 files changed, 22 insertions, 1 deletions
diff --git a/Lib/urllib.py b/Lib/urllib.py
index f84ac28..bf5fc97 100644
--- a/Lib/urllib.py
+++ b/Lib/urllib.py
@@ -1321,6 +1321,24 @@ def proxy_bypass_environment(host):
if sys.platform == 'darwin':
+
+ def _CFSetup(sc):
+ 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
+ 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
+
def _CStringFromCFString(sc, value):
from ctypes import create_string_buffer
length = sc.CFStringGetLength(value) + 1
@@ -1357,6 +1375,7 @@ if sys.platform == 'darwin':
return (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8) | parts[3]
sc = cdll.LoadLibrary(find_library("SystemConfiguration"))
+ _CFSetup(sc)
hostIP = None
@@ -1369,6 +1388,8 @@ if sys.platform == 'darwin':
proxyDict = sc.SCDynamicStoreCopyProxies(None)
+ if proxyDict is None:
+ return False
try:
# Check for simple host names:
@@ -1422,11 +1443,11 @@ if sys.platform == 'darwin':
from ctypes.util import find_library
sc = cdll.LoadLibrary(find_library("SystemConfiguration"))
+ _CFSetup(sc)
if not sc:
return {}
-
kSCPropNetProxiesHTTPEnable = sc.CFStringCreateWithCString(0, "HTTPEnable", 0)
kSCPropNetProxiesHTTPProxy = sc.CFStringCreateWithCString(0, "HTTPProxy", 0)
kSCPropNetProxiesHTTPPort = sc.CFStringCreateWithCString(0, "HTTPPort", 0)