making magic dependancy optional
This commit is contained in:
parent
ed7b182281
commit
3d66f99c95
11
av98.py
11
av98.py
|
@ -23,7 +23,6 @@ import glob
|
|||
import hashlib
|
||||
import io
|
||||
import mimetypes
|
||||
import magic
|
||||
import os
|
||||
import os.path
|
||||
import filecmp
|
||||
|
@ -55,6 +54,12 @@ try:
|
|||
except ModuleNotFoundError:
|
||||
_HAS_CRYPTOGRAPHY = False
|
||||
|
||||
try:
|
||||
import magic
|
||||
_HAS_MAGIC = True
|
||||
except ModuleNotFoundError:
|
||||
_HAS_MAGIC = False
|
||||
|
||||
_VERSION = "1.0.4dev"
|
||||
|
||||
_MAX_REDIRECTS = 5
|
||||
|
@ -466,8 +471,10 @@ you'll be able to transparently follow links to Gopherspace!""")
|
|||
tmpfile = cached
|
||||
mime,encoding = mimetypes.guess_type(cached,strict=False)
|
||||
#gmi Mimetype is not recognized yet
|
||||
if not mime :
|
||||
if not mime and _HAS_MAGIC :
|
||||
mime = magic.from_file(cached,mime=True)
|
||||
elif not _HAS_MAGIC :
|
||||
print("Cannot guess the mime type of the file. Install Python-magic")
|
||||
if mime.startswith("text"):
|
||||
#if mime == "text/gemini":
|
||||
mime = "text/gemini"
|
||||
|
|
Loading…
Reference in New Issue