Skip to content

[3.8] bpo-4963: Fix for initialization and non-deterministic behavior issues in mimetypes (GH-3062) #14375

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

Merged
merged 1 commit into from
Jun 25, 2019

Conversation

zooba
Copy link
Member

@zooba zooba commented Jun 25, 2019

@zooba zooba requested a review from a team as a code owner June 25, 2019 14:37
@zooba zooba merged commit 25fbe33 into python:3.8 Jun 25, 2019
@zooba zooba deleted the bpo-4963-3.8 branch June 25, 2019 15:20
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this pull request Jan 4, 2021
Python 3.6 gets some of those "wrong":
https://bugs.python.org/issue1043134

This has been fixed in Python 3.7:
python/cpython#14375

The override dict has been generated by copying the types_map from the
current git master:
https://github.com/python/cpython/blob/v3.10.0a3/Lib/mimetypes.py#L414-L547

And then running the following with Python 3.6:

    import mimetypes

    reverse = {}
    for ext, mimetype in types_map.items():
        if mimetype not in reverse:
            reverse[mimetype] = ext
    assert reverse['text/plain'] == '.txt'

    for mimetype, ext in reverse.items():
        got = mimetypes.guess_extension(mimetype)
        if got != ext:
            print(f'    "{mimetype}": "{ext}",  # not {got}')
The-Compiler added a commit to qutebrowser/qutebrowser that referenced this pull request Jan 5, 2021
Python 3.6 gets some of those "wrong":
https://bugs.python.org/issue1043134

This has been fixed in Python 3.7:
python/cpython#14375

The override dict has been generated by copying the types_map from the
current git master:
https://github.com/python/cpython/blob/v3.10.0a3/Lib/mimetypes.py#L414-L547

And then running the following with Python 3.6:

    import mimetypes

    reverse = {}
    for ext, mimetype in types_map.items():
        if mimetype not in reverse:
            reverse[mimetype] = ext
    assert reverse['text/plain'] == '.txt'

    for mimetype, ext in reverse.items():
        got = mimetypes.guess_extension(mimetype)
        if got != ext:
            print(f'    "{mimetype}": "{ext}",  # not {got}')
jugmac00 pushed a commit to jugmac00/launchpad that referenced this pull request Dec 5, 2022
Python 3.8 slightly changed how the `mimetypes` module is initialized
(python/cpython#14375), and this interacted
badly with the reinitialization code in `zope.contenttype` in such a way
as to make the extensions in `lp.services.mime` be ineffective.  Work
around this in a way that works with both old and new versions of Python
by monkey-patching `mimetypes.init`.
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

Successfully merging this pull request may close these issues.

4 participants