cffi_utils/sowrapper.py
def __openlib(self):
        '''
        Actual (lazy) dlopen() only when an attribute is accessed
        '''
        if self.__getattribute__('_libloaded'):
            return
        libpath_list = self.__get_libres()
        for p in libpath_list:
            try:
                libres = resource_filename(self._module_name, p)
                self.lib = self.ffi.dlopen(libres)
                return
            except:
                continue
        # Try self._libpath if nothing in libpath_list worked - will work
        # only if self._module_name is set
        try:
            libres = resource_filename(self._module_name, self._libpath)
            self.lib = self.ffi.dlopen(libres)
        except:
            # If self._module_name is in sys.modules, try self._libpath
            # in the same dir as sys.modules[self._module_name].__file__
            # This is allows get_lib_ffi_shared to work in REPL
            try:
                # We set _libloaded to indicate all options have been tried
                self._libloaded = True

                libdir = ''
                if self._module_name is not None:
                    mod = sys.modules.get(self._module_name, None)
                    if mod is not None:
                        libdir = os.path.dirname(mod.__file__) or os.getcwd()

                libres = os.path.join(libdir, self._libpath)
                self.lib = self.ffi.dlopen(libres)
            except:
                return None
def __openlib(self):
        '''
        Actual (lazy) dlopen() only when an attribute is accessed
        '''
        if self.__getattribute__('_libloaded'):
            return
        libpath_list = self.__get_libres()
        for p in libpath_list:
            try:
                libres = resource_filename(self._module_name, p)
                self.lib = self.ffi.dlopen(libres)
                return
            except:
                continue
        # Try self._libpath if nothing in libpath_list worked - will work
        # only if self._module_name is set
        try:
            libres = resource_filename(self._module_name, self._libpath)
            self.lib = self.ffi.dlopen(libres)
        except:
            # If self._module_name is in sys.modules, try self._libpath
            # in the same dir as sys.modules[self._module_name].__file__
            # This is allows get_lib_ffi_shared to work in REPL
            try:
                # We set _libloaded to indicate all options have been tried
                self._libloaded = True

                libdir = ''
                if self._module_name is not None:
                    mod = sys.modules.get(self._module_name, None)
                    if mod is not None:
                        libdir = os.path.dirname(mod.__file__) or os.getcwd()

                libres = os.path.join(libdir, self._libpath)
                self.lib = self.ffi.dlopen(libres)
            except:
                return None
Actual (lazy) dlopen() only when an attribute is accessed