Skip to content

Commit 89ef9a4

Browse files
committed
Refactor load_yajl
To reduce code duplication introduced by adding windows support in commit 117166f. List of file names is generated using a list comprehension so that the unique windows file name can be appended. Consequently, the list of file names can be iterated over and two separate cases are not needed.
1 parent 117166f commit 89ef9a4

File tree

1 file changed

+3
-8
lines changed

1 file changed

+3
-8
lines changed

yajl/yajl_common.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,14 @@ def load_yajl():
3232
:returns: The yajl shared object
3333
:raises OSError: when libyajl cannot be loaded
3434
'''
35-
for ftype in '', '.so', '.dylib':
36-
yajlso = 'libyajl%s' %(ftype)
35+
fnames = ['libyajl%s' %(t) for t in ['', '.so', '.dylib']] + ['yajl.dll']
36+
37+
for yajlso in fnames:
3738
try:
3839
return cdll.LoadLibrary(yajlso)
3940
except OSError:
4041
pass
4142

42-
yajlso = 'yajl.dll'
43-
try:
44-
return cdll.LoadLibrary(yajlso)
45-
except OSError:
46-
pass
47-
4843
raise OSError('Yajl shared object cannot be found. '
4944
'Please install Yajl and confirm it is on your shared lib path.')
5045

0 commit comments

Comments
 (0)