We use mimetypes.guess_type in
|
def get_content_type(self, file_name): |
|
"""Guess the mime type of a file. |
|
|
|
@param file_name: file name |
|
@type file_name: str |
|
@return: MIME type |
|
@rtype: str |
|
""" |
|
return mimetypes.guess_type(file_name)[0] or "application/octet-stream" |
guess_type has strict option set to
True by default which means that
common_types included in Python stdlib are ignored.
For example, in a containerized environment without
/etc/mime.types file,
.rtf extension is not resolvable with strict mode turned on:
/usr/bin/python2.7
(None, None)
/usr/bin/python3.10
(None, None)
/usr/bin/python3.6
(None, None)
/usr/bin/python3.8
(None, None)
/usr/bin/python3.9
(None, None)
but without it, it works:
/usr/bin/python2.7
('application/rtf', None)
/usr/bin/python3.10
('application/rtf', None)
/usr/bin/python3.6
('application/rtf', None)
/usr/bin/python3.8
('application/rtf', None)
/usr/bin/python3.9
('application/rtf', None)
so turning off the strict mode might make it better for containerized environments and if we merge #162 we won't need mailcap package for tests (provides /etc/mime.types).
We use
mimetypes.guess_typeinkobo/kobo/http.py
Lines 32 to 40 in eaff9b4
guess_typehasstrictoption set toTrueby default which means that common_types included in Python stdlib are ignored.For example, in a containerized environment without
/etc/mime.typesfile,.rtfextension is not resolvable with strict mode turned on:but without it, it works:
so turning off the strict mode might make it better for containerized environments and if we merge #162 we won't need mailcap package for tests (provides
/etc/mime.types).