Skip to content

Commit

Permalink
Call mimetypes.guess_type with parameter strict=False
Browse files Browse the repository at this point in the history
  • Loading branch information
d-maurer committed Sep 26, 2023
1 parent 2a92b56 commit 8bf89a0
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

- Add some more MIME types and extensions.

- Call ``mimetypes.guess_type`` with parameter ``strict=False``. This
recognizes a few more content types related to ``midi``, ``pict``,
``xul`` and ``rtf``;
for details, see
`#14 <https://github.com/zopefoundation/zope.contenttype/issues/7>`_.


5.0 (2023-03-27)
================
Expand Down
2 changes: 1 addition & 1 deletion src/zope/contenttype/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ def guess_content_type(name='', body=b'', default=None):
# Attempt to determine the content type (and possibly
# content-encoding) based on an an object's name and
# entity body.
type, enc = mimetypes.guess_type(name)
type, enc = mimetypes.guess_type(name, strict=False)
if type is None:
if body:
if find_binary(body) is not None:
Expand Down
2 changes: 2 additions & 0 deletions src/zope/contenttype/tests/testContentTypes.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@ def test_guess_content_type(self):
self.assertEqual(ctype, "application/octet-stream")
ctype, _encoding = guess_content_type()
self.assertEqual(ctype, "text/x-unknown-content-type")
ctype, _encoding = guess_content_type("abc.rtf")
self.assertEqual(ctype, "application/rtf")

def test_add_one_file(self):
from zope.contenttype import add_files
Expand Down

0 comments on commit 8bf89a0

Please sign in to comment.