
Hi, A friend and I have hit a funny situation with the `mimetypes.py` library guessing the type for a '.json' file. Is there a reason why '.json' hasn't been added to the mapping? Without `mailcap` installed: [root@de169da8cc46 /]# python3 -m mimetypes build.json I don't know anything about type build.json With `mailcap` installed: [root@de169da8cc46 /]# python3 -m mimetypes build.json type: application/json encoding: None We experimented with adding a mapping for '.json' to 'application/json' to `mimetypes.py` and it seems to work fine for us. It looks like it has been registered with IANA and everything. Proposed diff: ntangsurat@derigible ~/git/e4r7hbug.cpython/Lib master $ git diff diff --git a/Lib/mimetypes.py b/Lib/mimetypes.py index 3d68694864..5919b45a9b 100644 --- a/Lib/mimetypes.py +++ b/Lib/mimetypes.py @@ -439,6 +439,7 @@ def _default_mime_types(): '.jpeg' : 'image/jpeg', '.jpg' : 'image/jpeg', '.js' : 'application/javascript', + '.json' : 'application/json', '.ksh' : 'text/plain', '.latex' : 'application/x-latex', '.m1v' : 'video/mpeg', Nate.

On Wed, 9 Aug 2017 at 10:43 Nate. <e4r7hbug@gmail.com> wrote:
Probably no one thought about it since the module was added in 1997 which is only 2 years after the creation of JavaScript itself. :)
Feel free to file a bug at bugs.python.org and if you aren't too bothered then submit a PR to github.com/python/cpython (https://devguide.python.org/ has all the details).

09.08.17 21:17, Brett Cannon пише:
No one proposed a patch.

On 10 August 2017 at 04:24, Serhiy Storchaka <storchaka@gmail.com> wrote:
That's not *quite* true - there was at least one proposal a few years to modernise the mimetypes list, but the one I was involved in reviewing got intertwined with a proposal to completely rewrite the mimetypes module, and the submitter wasn't interested in creating a more minimalist patch that solved the specific problem (i.e. the list was pretty out of date) without all the extraneous changes to how the module actually worked :( Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

O, fun! Thank you for the guidance. I managed to find a Bug already created, http://bugs.python.org/issue30824. I'll create a Pull Request using that Bug. On Wed, Aug 9, 2017 at 1:18 PM Brett Cannon <brett@python.org> wrote:

On Wed, Aug 09, 2017 at 05:42:18PM +0000, "Nate." <e4r7hbug@gmail.com> wrote:
My guess is that nobody uses mimetypes without mailcap.
Patches should be published at the issue tracker.
Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.

On Wed, 9 Aug 2017 at 10:43 Nate. <e4r7hbug@gmail.com> wrote:
Probably no one thought about it since the module was added in 1997 which is only 2 years after the creation of JavaScript itself. :)
Feel free to file a bug at bugs.python.org and if you aren't too bothered then submit a PR to github.com/python/cpython (https://devguide.python.org/ has all the details).

09.08.17 21:17, Brett Cannon пише:
No one proposed a patch.

On 10 August 2017 at 04:24, Serhiy Storchaka <storchaka@gmail.com> wrote:
That's not *quite* true - there was at least one proposal a few years to modernise the mimetypes list, but the one I was involved in reviewing got intertwined with a proposal to completely rewrite the mimetypes module, and the submitter wasn't interested in creating a more minimalist patch that solved the specific problem (i.e. the list was pretty out of date) without all the extraneous changes to how the module actually worked :( Cheers, Nick. -- Nick Coghlan | ncoghlan@gmail.com | Brisbane, Australia

O, fun! Thank you for the guidance. I managed to find a Bug already created, http://bugs.python.org/issue30824. I'll create a Pull Request using that Bug. On Wed, Aug 9, 2017 at 1:18 PM Brett Cannon <brett@python.org> wrote:

On Wed, Aug 09, 2017 at 05:42:18PM +0000, "Nate." <e4r7hbug@gmail.com> wrote:
My guess is that nobody uses mimetypes without mailcap.
Patches should be published at the issue tracker.
Oleg. -- Oleg Broytman http://phdru.name/ phd@phdru.name Programmers don't die, they just GOSUB without RETURN.
participants (5)
-
Brett Cannon
-
Nate.
-
Nick Coghlan
-
Oleg Broytman
-
Serhiy Storchaka