summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56>2012-04-01 12:42:29 +0000
committerdominique.leuenberger@gmail.com <dominique.leuenberger@gmail.com@c587cffe-e639-0410-9787-d7902ae8ed56>2012-04-01 12:42:29 +0000
commit1b563739127cebd23ee632da198a0df717a307b1 (patch)
treee7f40ba21f90626ee65de443e255f0ce201b5cbe
parent1d9b468db29c313d947b4454c2fb948ab2e26388 (diff)
downloadlibproxy-1b563739127cebd23ee632da198a0df717a307b1.tar.gz
Speed up importing libproxy in python.
Fixes issue 177. git-svn-id: http://libproxy.googlecode.com/svn/trunk@839 c587cffe-e639-0410-9787-d7902ae8ed56
-rw-r--r--bindings/python/libproxy.py20
-rw-r--r--libproxy/cmake/libproxy.cmk1
2 files changed, 12 insertions, 9 deletions
diff --git a/bindings/python/libproxy.py b/bindings/python/libproxy.py
index 15f0210..cb75a4d 100644
--- a/bindings/python/libproxy.py
+++ b/bindings/python/libproxy.py
@@ -25,21 +25,23 @@ import platform
import sys
+def _load(name, *versions):
+ for ver in versions:
+ try: return ctypes.cdll.LoadLibrary('lib%s.so.%s' % (name, ver))
+ except: pass
+ name_ver = ctypes.util.find_library(name)
+ if name_ver:
+ return ctypes.cdll.LoadLibrary(name_ver)
+ raise ImportError("Unable to find %s library" % name)
+
# Load C library
if platform.system() == "Windows":
_libc = ctypes.cdll.msvcrt
else:
- if not ctypes.util.find_library("c"):
- raise ImportError("Unable to import C Library!?!")
- _libc = ctypes.cdll.LoadLibrary(ctypes.util.find_library("c"))
-
+ _libc = _load("c", 6)
# Load libproxy
-if not ctypes.util.find_library("proxy"):
- raise ImportError("Unable to import libproxy!?!?")
-
-
-_libproxy = ctypes.cdll.LoadLibrary(ctypes.util.find_library("proxy"))
+_libproxy = _load("proxy", 1)
_libproxy.px_proxy_factory_get_proxies.restype = ctypes.POINTER(ctypes.c_void_p)
class ProxyFactory(object):
diff --git a/libproxy/cmake/libproxy.cmk b/libproxy/cmake/libproxy.cmk
index 80406af..d0e03e9 100644
--- a/libproxy/cmake/libproxy.cmk
+++ b/libproxy/cmake/libproxy.cmk
@@ -17,6 +17,7 @@ endif()
set_property(SOURCE ${CMAKE_CURRENT_SOURCE_DIR}/proxy.cpp
PROPERTY COMPILE_DEFINITIONS MODULEDIR="${MODULEDIR}";BUILTIN_MODULES=${BUILTIN_MODULES})
+# When changing the SOVERSION here remember to also bump the 'favorite proxy .so' in python bindings.
set_target_properties(libproxy PROPERTIES PREFIX "" VERSION 1.0.0 SOVERSION 1)
set_target_properties(libproxy PROPERTIES LINK_INTERFACE_LIBRARIES "")
install(TARGETS libproxy DESTINATION ${LIB_INSTALL_DIR})