Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Strict mimetypes or not? #163

Open
frenzymadness opened this issue Jan 26, 2022 · 0 comments
Open

Strict mimetypes or not? #163

frenzymadness opened this issue Jan 26, 2022 · 0 comments

Comments

@frenzymadness
Copy link
Contributor

We use mimetypes.guess_type in

kobo/kobo/http.py

Lines 32 to 40 in eaff9b4

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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant