Skip to content

Commit 0605bdd

Browse files
committed
Blackened
1 parent 84186f2 commit 0605bdd

1 file changed

Lines changed: 52 additions & 44 deletions

File tree

libloader/libloader.py

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,61 @@
55
import sys
66

77
TYPES = {
8-
'Linux': {
9-
'loader': ctypes.CDLL,
10-
'functype': ctypes.CFUNCTYPE,
11-
'prefix': 'lib',
12-
'extension': '.so'
13-
},
14-
'Darwin': {
15-
'loader': ctypes.CDLL,
16-
'functype': ctypes.CFUNCTYPE,
17-
'prefix': 'lib',
18-
'extension': '.dylib'
19-
},
8+
"Linux": {
9+
"loader": ctypes.CDLL,
10+
"functype": ctypes.CFUNCTYPE,
11+
"prefix": "lib",
12+
"extension": ".so",
13+
},
14+
"Darwin": {
15+
"loader": ctypes.CDLL,
16+
"functype": ctypes.CFUNCTYPE,
17+
"prefix": "lib",
18+
"extension": ".dylib",
19+
},
2020
}
21-
if platform.system() == 'Windows':
22-
TYPES['Windows'] = {
23-
'loader': ctypes.WinDLL,
24-
'functype': ctypes.WINFUNCTYPE,
25-
'prefix': "",
26-
'extension': '.dll'
27-
}
28-
29-
class LibraryLoadError(OSError): pass
30-
31-
def load_library(library, x86_path='.', x64_path='.', *args, **kwargs):
32-
lib = find_library_path(library, x86_path=x86_path, x64_path=x64_path)
33-
loaded = _do_load(lib, *args, **kwargs)
34-
if loaded is not None:
35-
return loaded
36-
raise LibraryLoadError('unable to load %r. Provided library path: %r' % (library, path))
21+
if platform.system() == "Windows":
22+
TYPES["Windows"] = {
23+
"loader": ctypes.WinDLL,
24+
"functype": ctypes.WINFUNCTYPE,
25+
"prefix": "",
26+
"extension": ".dll",
27+
}
28+
29+
30+
class LibraryLoadError(OSError):
31+
pass
32+
33+
34+
def load_library(library, x86_path=".", x64_path=".", *args, **kwargs):
35+
lib = find_library_path(library, x86_path=x86_path, x64_path=x64_path)
36+
loaded = _do_load(lib, *args, **kwargs)
37+
if loaded is not None:
38+
return loaded
39+
raise LibraryLoadError(
40+
"unable to load %r. Provided library path: %r" % (library, path)
41+
)
42+
3743

3844
def _do_load(file, *args, **kwargs):
39-
loader = TYPES[platform.system()]['loader']
40-
return loader(file, *args, **kwargs)
41-
42-
def find_library_path(libname, x86_path='.', x64_path='.'):
43-
libname = '%s%s' % (TYPES[platform.system()]['prefix'], libname)
44-
if platform.architecture()[0] == '64bit':
45-
path = os.path.join(x64_path, libname)
46-
else:
47-
path = os.path.join(x86_path, libname)
48-
ext = get_library_extension()
49-
path = '%s%s' % (path, ext)
50-
return os.path.abspath(path)
51-
52-
45+
loader = TYPES[platform.system()]["loader"]
46+
return loader(file, *args, **kwargs)
47+
48+
49+
def find_library_path(libname, x86_path=".", x64_path="."):
50+
libname = "%s%s" % (TYPES[platform.system()]["prefix"], libname)
51+
if platform.architecture()[0] == "64bit":
52+
path = os.path.join(x64_path, libname)
53+
else:
54+
path = os.path.join(x86_path, libname)
55+
ext = get_library_extension()
56+
path = "%s%s" % (path, ext)
57+
return os.path.abspath(path)
58+
59+
5360
def get_functype():
54-
return TYPES[platform.system()]['functype']
61+
return TYPES[platform.system()]["functype"]
62+
5563

5664
def get_library_extension():
57-
return TYPES[platform.system()]['extension']
65+
return TYPES[platform.system()]["extension"]

0 commit comments

Comments
 (0)