From d2860ab30d94a814d8bfc2d3f36f0ffba5f65d27 Mon Sep 17 00:00:00 2001 From: Zuzu-Typ Date: Thu, 19 Dec 2019 19:00:33 +0100 Subject: [PATCH] Fixed library loader --- pyogg/library_loader.py | 24 ++++++++++++------------ pyogg/ogg.py | 9 +++++---- 2 files changed, 17 insertions(+), 16 deletions(-) diff --git a/pyogg/library_loader.py b/pyogg/library_loader.py index 4217ad7..642c887 100644 --- a/pyogg/library_loader.py +++ b/pyogg/library_loader.py @@ -1,4 +1,5 @@ import ctypes +import ctypes.util import os import sys import platform @@ -30,7 +31,7 @@ class ExternalLibraryError(Exception): class ExternalLibrary: @staticmethod - def load(name, paths = None, tests=[]): + def load(name, paths = None, tests = []): if name in _loaded_libraries: return _loaded_libraries[name] if sys.platform == "win32": @@ -43,23 +44,23 @@ def load(name, paths = None, tests=[]): return lib @staticmethod - def load_other(name, paths = None, tests=[]): + def load_other(name, paths = None, tests = []): os.environ["PATH"] += ";" + ";".join((os.getcwd(), _here)) if paths: os.environ["PATH"] += ";" + ";".join(paths) for style in _other_styles: - for name in (name.upper(), name.lower()): - candidate = style.format(name) - library = ctypes.util.find_library(candidate) + candidate = style.format(name) + library = ctypes.util.find_library(candidate) + if library: try: lib = ctypes.CDLL(library) - if all(run_tests(lib,tests)): + if tests and all(run_tests(lib, tests)): return lib except: pass @staticmethod - def load_windows(name, paths = None, tests=[]): + def load_windows(name, paths = None, tests = []): os.environ["PATH"] += ";" + ";".join((os.getcwd(), _here)) if paths: os.environ["PATH"] += ";" + ";".join(paths) @@ -69,15 +70,14 @@ def load_windows(name, paths = None, tests=[]): library = ctypes.util.find_library(candidate) if library: try: - lib = ctypes.CDLL(candidate) - if all(run_tests(lib,tests)): + lib = ctypes.CDLL(library) + if tests and all(run_tests(lib, tests)): return lib - else: - not_supported.append(candidate) + not_supported.append(library) except WindowsError: pass except OSError: - not_supported.append(candidate) + not_supported.append(library) if not_supported: diff --git a/pyogg/ogg.py b/pyogg/ogg.py index 7264774..1dc14e4 100644 --- a/pyogg/ogg.py +++ b/pyogg/ogg.py @@ -49,6 +49,11 @@ def get_raw_libname(name): for x in "0123456789._- ":name=name.replace(x,"") return name +if sys.version_info.major > 2: + to_char_p = lambda s: s.encode('utf-8') +else: + to_char_p = lambda s: s + __here = os.getcwd() libogg = None @@ -66,10 +71,6 @@ def get_raw_libname(name): PYOGG_OGG_AVAIL = False if PYOGG_OGG_AVAIL: - if sys.version_info.major > 2: - to_char_p = lambda s: s.encode('utf-8') - else: - to_char_p = lambda s: s # ctypes c_ubyte_p = POINTER(c_ubyte)