Skip to content

Strict mimetypes or not? #163

Description

@frenzymadness

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

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions