Skip to content

Commit bb9c685

Browse files
committed
Move magic.mgc injection into Magic class
1 parent 359e007 commit bb9c685

1 file changed

Lines changed: 6 additions & 4 deletions

File tree

magic/__init__.py

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,12 @@ def __init__(self, mime=False, magic_file=None, mime_encoding=False,
9696
self.cookie = magic_open(self.flags)
9797
self.lock = threading.Lock()
9898

99+
if magic_file is None and not os.environ.get("MAGIC"):
100+
# wheels package the mime database in this directory
101+
# prefer it when no magic file is specified by the user
102+
mime_db = os.path.join(os.path.dirname(__file__), 'magic.mgc')
103+
if os.path.exists(mime_db):
104+
magic_file = mime_db
99105
magic_load(self.cookie, magic_file)
100106

101107
# MAGIC_EXTENSION was added in 523 or 524, so bail if
@@ -354,10 +360,6 @@ def magic_descriptor(cookie, fd):
354360

355361

356362
def magic_load(cookie, filename):
357-
mime_db = os.path.join(os.path.dirname(__file__), 'magic.mgc')
358-
if os.path.exists(mime_db):
359-
# wheels package the mime database in this directory
360-
return _magic_load(cookie, coerce_filename(mime_db))
361363
return _magic_load(cookie, coerce_filename(filename))
362364

363365

0 commit comments

Comments
 (0)