Skip to content

Commit

Permalink
don't except OSError, close #15
Browse files Browse the repository at this point in the history
We should give the user the option to catch OSError (libdiscid not
found) and ImportError (python-discid not found) separately.
  • Loading branch information
JonnyJD committed Mar 9, 2013
1 parent 35ed421 commit 2626879
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 6 deletions.
7 changes: 2 additions & 5 deletions discid.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
feed it with some type of TOC and extract the generated information.
Importing this module will open libdiscid at the same time
and will raise :exc:`ImportError` when libdiscid is not found.
and will raise :exc:`OSError` when libdiscid is not found.
"""

import os
Expand Down Expand Up @@ -97,10 +97,7 @@ def _find_library(name, version=0):
def _open_library(lib_name):
"""Open a library by name or location
"""
try:
return ctypes.cdll.LoadLibrary(lib_name)
except OSError as err:
raise ImportError(err)
return ctypes.cdll.LoadLibrary(lib_name)

_LIB_NAME = _find_library(_LIB_BASE_NAME, _LIB_MAJOR_VERSION)
_LIB = _open_library(_LIB_NAME)
Expand Down
3 changes: 2 additions & 1 deletion doc/install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Dependencies
The module :mod:`discid` cannot be imported
without `Libdiscid`_ >= 0.2.2 installed.
If you want to use it as optional dependency,
import the module only when needed or catch the :exc:`ImportError`.
import the module only when needed or catch the :exc:`OSError`
when libdiscid is not found.

Package Repositories (Linux)
----------------------------
Expand Down

0 comments on commit 2626879

Please sign in to comment.