Fall back to guess_mime_mimedb if file command fails in guess_mime_file
This commit is contained in:
parent
d7e64d9fd6
commit
0ae7b3ae53
|
@ -294,16 +294,15 @@ def guess_mime_file (filename):
|
||||||
cmd = [file_prog, "--brief", "--mime", "--uncompress", filename]
|
cmd = [file_prog, "--brief", "--mime", "--uncompress", filename]
|
||||||
try:
|
try:
|
||||||
outparts = backtick(cmd).strip().split(";")
|
outparts = backtick(cmd).strip().split(";")
|
||||||
|
mime2 = outparts[0].split(" ", 1)[0]
|
||||||
except OSError:
|
except OSError:
|
||||||
# ignore errors, as file(1) is only a fallback
|
mime2 = None
|
||||||
return mime, encoding
|
|
||||||
mime2 = outparts[0].split(" ", 1)[0]
|
|
||||||
# Some file(1) implementations return an empty or unknown mime type
|
# Some file(1) implementations return an empty or unknown mime type
|
||||||
# when the uncompressor program is not installed, other
|
# when the uncompressor program is not installed, other
|
||||||
# implementation return the original file type.
|
# implementation return the original file type.
|
||||||
# The following detects both cases.
|
# The following detects both cases.
|
||||||
if (mime2 in ('application/x-empty', 'application/octet-stream') or
|
if (mime2 in ('application/x-empty', 'application/octet-stream') or
|
||||||
mime2 in Mime2Encoding):
|
mime2 in Mime2Encoding or not mime2):
|
||||||
# The uncompressor program file(1) uses is not installed
|
# The uncompressor program file(1) uses is not installed
|
||||||
# or is not able to uncompress.
|
# or is not able to uncompress.
|
||||||
# Try to get mime information from the file extension.
|
# Try to get mime information from the file extension.
|
||||||
|
|
Loading…
Reference in New Issue