|
@@ -53,8 +53,6 @@ class Magic:
|
|
|
raw - Do not try to decode "non-printable" chars.
|
|
|
extension - Print a slash-separated list of valid extensions for the file type found.
|
|
|
"""
|
|
|
-
|
|
|
- self.cookie = None
|
|
|
self.flags = MAGIC_NONE
|
|
|
if mime:
|
|
|
self.flags |= MAGIC_MIME_TYPE
|
|
@@ -152,7 +150,7 @@ class Magic:
|
|
|
# incorrect fix for a threading problem, however I'm leaving
|
|
|
# it in because it's harmless and I'm slightly afraid to
|
|
|
# remove it.
|
|
|
- if self.cookie and magic_close:
|
|
|
+ if hasattr(self, 'cookie') and self.cookie and magic_close:
|
|
|
magic_close(self.cookie)
|
|
|
self.cookie = None
|
|
|
|
|
@@ -206,41 +204,8 @@ def from_descriptor(fd, mime=False):
|
|
|
m = _get_magic_type(mime)
|
|
|
return m.from_descriptor(fd)
|
|
|
|
|
|
-
|
|
|
-libmagic = None
|
|
|
-# Let's try to find magic or magic1
|
|
|
-dll = ctypes.util.find_library('magic') \
|
|
|
- or ctypes.util.find_library('magic1') \
|
|
|
- or ctypes.util.find_library('cygmagic-1') \
|
|
|
- or ctypes.util.find_library('libmagic-1') \
|
|
|
- or ctypes.util.find_library('msys-magic-1') # for MSYS2
|
|
|
-
|
|
|
-# necessary because find_library returns None if it doesn't find the library
|
|
|
-if dll:
|
|
|
- libmagic = ctypes.CDLL(dll)
|
|
|
-
|
|
|
-if not libmagic or not libmagic._name:
|
|
|
- windows_dlls = ['magic1.dll', 'cygmagic-1.dll', 'libmagic-1.dll', 'msys-magic-1.dll']
|
|
|
- platform_to_lib = {'darwin': ['/opt/local/lib/libmagic.dylib',
|
|
|
- '/usr/local/lib/libmagic.dylib'] +
|
|
|
- # Assumes there will only be one version installed
|
|
|
- glob.glob('/usr/local/Cellar/libmagic/*/lib/libmagic.dylib'), # flake8:noqa
|
|
|
- 'win32': windows_dlls,
|
|
|
- 'cygwin': windows_dlls,
|
|
|
- 'linux': ['libmagic.so.1'],
|
|
|
- # fallback for some Linuxes (e.g. Alpine) where library search does not work # flake8:noqa
|
|
|
- }
|
|
|
- platform = 'linux' if sys.platform.startswith('linux') else sys.platform
|
|
|
- for dll in platform_to_lib.get(platform, []):
|
|
|
- try:
|
|
|
- libmagic = ctypes.CDLL(dll)
|
|
|
- break
|
|
|
- except OSError:
|
|
|
- pass
|
|
|
-
|
|
|
-if not libmagic or not libmagic._name:
|
|
|
- # It is better to raise an ImportError since we are importing magic module
|
|
|
- raise ImportError('failed to find libmagic. Check your installation')
|
|
|
+from . import loader
|
|
|
+libmagic = loader.load_lib()
|
|
|
|
|
|
magic_t = ctypes.c_void_p
|
|
|
|
|
@@ -453,7 +418,7 @@ def _add_compat(to_module):
|
|
|
def deprecation_wrapper(fn):
|
|
|
def _(*args, **kwargs):
|
|
|
warnings.warn(
|
|
|
- "Using compatability mode with libmagic's python binding. "
|
|
|
+ "Using compatibility mode with libmagic's python binding. "
|
|
|
"See https://github.com/ahupp/python-magic/blob/master/COMPAT.md for details.",
|
|
|
PendingDeprecationWarning)
|
|
|
|