New submission from Rodrigo Parra: The functions looks up for the file extension in three maps: types_map, suffix_map and encodings_map.
Lookup in types_map is case insensitive (by calling lower() first). Lookup in both suffix_map and encodings_map is case sensitive. These can lead to some seemingly counterintuitive results, like: a) guess_type("foo.tar") == ("application/x-tar", None) guess_type("foo.TAR") == ("application/x-tar", None) b) guess_type("foo.tgz") == ("application/x-tar", "gzip") guess_type("foo.TGZ") == (None, None) c) guess_type("foo.tar.gz") == ("application/x-tar", "gzip") guess_type("foo.TAR.GZ") == (None, None) Lookup should be case insensitive at least for the suffix_map, in which case (b) would be solved. The submitted patch implements this change. As for the encodings_map, I am not so sure, in particular because of the tar.Z extension. I found that the compress command expects the uppercase 'Z'. If someone is relying in the results of guess_type to call compress, errors could occur. ---------- components: Library (Lib) files: case_guess_type.patch keywords: patch messages: 209218 nosy: Rodrigo.Parra, tim.golden priority: normal severity: normal status: open title: Inconsistency with uppercase file extensions in MimeTypes.guess_type type: behavior versions: Python 3.4 Added file: http://bugs.python.org/file33703/case_guess_type.patch _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue20392> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com