Commit 0e7e715a authored by Victor Stinner's avatar Victor Stinner

(Merge 3.2) Issue #13025: mimetypes is now reading MIME types using the UTF-8

encoding, instead of the locale encoding.
parents 792b47f6 82ac9bcd
...@@ -199,7 +199,7 @@ class MimeTypes: ...@@ -199,7 +199,7 @@ class MimeTypes:
list of standard types, else to the list of non-standard list of standard types, else to the list of non-standard
types. types.
""" """
with open(filename) as fp: with open(filename, encoding='utf-8') as fp:
self.readfp(fp, strict) self.readfp(fp, strict)
def readfp(self, fp, strict=True): def readfp(self, fp, strict=True):
......
This diff is collapsed.
import mimetypes
import io import io
import unittest import locale
import mimetypes
import sys import sys
import unittest
from test import support from test import support
...@@ -62,6 +63,18 @@ class MimeTypesTestCase(unittest.TestCase): ...@@ -62,6 +63,18 @@ class MimeTypesTestCase(unittest.TestCase):
all = self.db.guess_all_extensions('image/jpg', strict=True) all = self.db.guess_all_extensions('image/jpg', strict=True)
eq(all, []) eq(all, [])
def test_encoding(self):
getpreferredencoding = locale.getpreferredencoding
self.addCleanup(setattr, locale, 'getpreferredencoding',
getpreferredencoding)
locale.getpreferredencoding = lambda: 'ascii'
filename = support.findfile("mime.types")
mimes = mimetypes.MimeTypes([filename])
exts = mimes.guess_all_extensions('application/vnd.geocube+xml',
strict=True)
self.assertEqual(exts, ['.g3', '.g\xb3'])
@unittest.skipUnless(sys.platform.startswith("win"), "Windows only") @unittest.skipUnless(sys.platform.startswith("win"), "Windows only")
class Win32MimeTypesTestCase(unittest.TestCase): class Win32MimeTypesTestCase(unittest.TestCase):
......
...@@ -305,6 +305,9 @@ Core and Builtins ...@@ -305,6 +305,9 @@ Core and Builtins
Library Library
------- -------
- Issue #13025: mimetypes is now reading MIME types using the UTF-8 encoding,
instead of the locale encoding.
- Issue #10653: On Windows, use strftime() instead of wcsftime() because - Issue #10653: On Windows, use strftime() instead of wcsftime() because
wcsftime() doesn't format time zone correctly. wcsftime() doesn't format time zone correctly.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment