Skip to content

Commit

Permalink
Fix compat.py now that bundled libmagic is preferred
Browse files Browse the repository at this point in the history
  • Loading branch information
ddelange committed May 22, 2024
1 parent e112de3 commit eba05b6
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion magic/compat.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
'''

import ctypes
import os

from collections import namedtuple

Expand All @@ -16,6 +17,13 @@

_libraries = {}
_libraries['magic'] = loader.load_lib()
magic_file = None
if not os.environ.get("MAGIC"):
# wheels package the mime database in this directory
# prefer it when no magic file is specified by the user
mime_db = os.path.join(os.path.dirname(__file__), 'magic.mgc')
if os.path.exists(mime_db):
magic_file = mime_db

# Flag constants for open and setflags
MAGIC_NONE = NONE = 0
Expand Down Expand Up @@ -178,7 +186,7 @@ def setflags(self, flags):
"""
return _setflags(self._magic_t, flags)

def load(self, filename=None):
def load(self, filename=magic_file):
"""
Must be called to load entries in the colon separated list of database
files passed as argument or the default database file if no argument
Expand Down

0 comments on commit eba05b6

Please sign in to comment.