[Python-modules-commits] [python-tidylib] 05/08: Use ctypes.util.find_library instead of hard-coded names list
Dmitry Shachnev
mitya57 at moszumanska.debian.org
Sun Sep 25 10:58:35 UTC 2016
This is an automated email from the git hooks/post-receive script.
mitya57 pushed a commit to branch master
in repository python-tidylib.
commit d0fdad94d8fa84babb23a9bfe9d8945b811c2aec
Author: Dmitry Shachnev <mitya57 at gmail.com>
Date: Sun Sep 25 13:32:27 2016 +0300
Use ctypes.util.find_library instead of hard-coded names list
Forwarded: https://github.com/countergram/pytidylib/pull/16
Patch-Name: 0002-Use-find_library.patch
---
tidylib/tidy.py | 27 +++++++++------------------
1 file changed, 9 insertions(+), 18 deletions(-)
diff --git a/tidylib/tidy.py b/tidylib/tidy.py
index a71ae9f..de15252 100644
--- a/tidylib/tidy.py
+++ b/tidylib/tidy.py
@@ -19,6 +19,7 @@
# THE SOFTWARE.
import ctypes
+import ctypes.util
import threading
import platform
import warnings
@@ -27,10 +28,6 @@ from .sink import create_sink, destroy_sink
__all__ = ['Tidy', 'PersistentTidy']
-# Default search order for library names if nothing is passed in
-LIB_NAMES = ['libtidy', 'libtidy.so', 'libtidy-0.99.so.0', 'cygtidy-0-99-0',
- 'tidylib', 'libtidy.dylib', 'tidy']
-
# Error code from library
ENOMEM = -12
@@ -80,18 +77,12 @@ class Tidy(object):
""" Wrapper around the HTML Tidy library for cleaning up possibly invalid
HTML and XHTML. """
- def __init__(self, lib_names=LIB_NAMES):
- lib_names = lib_names if isinstance(lib_names, list) else [lib_names]
- for name in lib_names:
- try:
- self._tidy = load_library(name)
- break
- except OSError:
- continue
- if self._tidy is None:
- raise OSError(
- "Could not load libtidy using any of these names: "
- + ",".join(lib_names))
+ def __init__(self, lib_name=None):
+ if lib_name is None:
+ lib_name = ctypes.util.find_library('tidy')
+ if lib_name is None:
+ raise OSError("Could not locate libtidy")
+ self._tidy = load_library(lib_name)
self._tidy.tidyCreate.restype = ctypes.POINTER(ctypes.c_void_p) # Fix for 64-bit systems
@contextmanager
@@ -194,8 +185,8 @@ class PersistentTidy(Tidy):
automatically set. Thread-local storage is used for the document object
(one document per thread). """
- def __init__(self, lib_names=LIB_NAMES):
- Tidy.__init__(self, lib_names)
+ def __init__(self, lib_name=None):
+ Tidy.__init__(self, lib_name)
self._local = threading.local()
self._local.doc = self._tidy.tidyCreate()
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/python-tidylib.git
More information about the Python-modules-commits
mailing list