classification
Title: mimetypes - "strict" on Windows
Type: behavior Stage: patch review
Components: Library (Lib), Windows Versions: Python 3.11
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: Norman Lorrain, brandonschabell, paul.moore, steve.dower, tim.golden, zach.ware
Priority: normal Keywords: patch

Created on 2021-05-17 19:54 by Norman Lorrain, last changed 2021-07-12 00:10 by brandonschabell.

Pull Requests
URL Status Linked Edit
PR 27088 open brandonschabell, 2021-07-12 00:10
Messages (2)
msg393826 - (view) Author: Norman Lorrain (Norman Lorrain) * Date: 2021-05-17 19:54
On Windows 10 machine, unit tests show this error:

    0:05:10 load avg: 3.24 [221/427/1] test_mimetypes failed
    test test_mimetypes failed -- Traceback (most recent call last):
    File "D:\github\cpython\lib\test\test_mimetypes.py", line 289, in test_guess_type
        eq(type_info, "I don't know anything about type foo.pic")
    AssertionError: 'type: image/pict encoding: None' != "I don't know anything about type foo.pic"
    - type: image/pict encoding: None
    + I don't know anything about type foo.pic

The test is verifying that the code reports `image/pict` as a *non-standard* MIME type:

    def test_guess_type(self):
        eq = self.assertEqual

        type_info = self.mimetypes_cmd("-l", "foo.pic")
        eq(type_info, "type: image/pict encoding: None")

        type_info = self.mimetypes_cmd("foo.pic")
        eq(type_info, "I don't know anything about type foo.pic")

Looking in my registry, I see the entry for `.pic`

    [HKEY_CLASSES_ROOT\.pic]
    @="QuickTime.pic"
    "Content Type"="image/pict"
    ...etc

The module seems to report everything it finds in the registry as "strict"
msg393827 - (view) Author: Norman Lorrain (Norman Lorrain) * Date: 2021-05-17 20:07
Possible solution is to read the Windows Registry entries, assigning those entries as "strict=False".  Unit tests pass with this change:

diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py
index 018793c4f0..dd2bddf064 100644
--- a/Lib/mimetypes.py
+++ b/Lib/mimetypes.py
@@ -350,7 +350,7 @@ def init(files=None):
     if files is None or _db is None:
         db = MimeTypes()
         if _winreg:
-            db.read_windows_registry()
+            db.read_windows_registry(strict = False)
 
         if files is None:
             files = knownfiles
History
Date User Action Args
2021-07-12 00:10:05brandonschabellsetkeywords: + patch
nosy: + brandonschabell

pull_requests: + pull_request25636
stage: patch review
2021-05-18 02:12:01ned.deilysetnosy: + paul.moore, tim.golden, zach.ware, steve.dower
components: + Windows
2021-05-17 20:07:31Norman Lorrainsetmessages: + msg393827
2021-05-17 19:54:58Norman Lorraincreate