def _CFSetup():
sc = cdll.LoadLibrary(find_library("SystemConfiguration"))
cf = cdll.LoadLibrary(find_library("CoreFoundation"))
sctable = [
('SCDynamicStoreCopyProxies', [c_void_p], c_void_p),
]
cftable = [
('CFArrayGetCount', [c_void_p], c_int64),
('CFArrayGetValueAtIndex', [c_void_p, c_int64], c_void_p),
('CFDictionaryGetValue', [c_void_p, c_void_p], c_void_p),
('CFStringCreateWithCString', [c_void_p, c_char_p, c_int32], c_void_p),
('CFStringGetLength', [c_void_p], c_int32),
('CFStringGetCString', [c_void_p, c_char_p, c_int32, c_int32], c_int32),
('CFNumberGetValue', [c_void_p, c_int, c_void_p], c_int32),
('CFRelease', [c_void_p], None),
]
scconst = [
'kSCPropNetProxiesExceptionsList',
'kSCPropNetProxiesExcludeSimpleHostnames',
'kSCPropNetProxiesHTTPEnable',
'kSCPropNetProxiesHTTPProxy',
'kSCPropNetProxiesHTTPPort',
'kSCPropNetProxiesHTTPSEnable',
'kSCPropNetProxiesHTTPSProxy',
'kSCPropNetProxiesHTTPSPort',
'kSCPropNetProxiesFTPEnable',
'kSCPropNetProxiesFTPProxy',
'kSCPropNetProxiesFTPPort',
'kSCPropNetProxiesGopherEnable',
'kSCPropNetProxiesGopherProxy',
'kSCPropNetProxiesGopherPort',
]
class CFProxy(object):
def __init__(self):
for mod, table in [(sc, sctable), (cf, cftable)]:
for fname, argtypes, restype in table:
func = getattr(mod, fname)
func.argtypes = argtypes
func.restype = restype
setattr(self, fname, func)
for k in scconst:
v = None
try:
v = c_void_p.in_dll(sc, k)
except ValueError:
v = None
setattr(self, k, v)
return CFProxy()
评论列表
文章目录