Commit 82ac9bcd authored by Victor Stinner's avatar Victor Stinner

Issue #13025: mimetypes is now reading MIME types using the UTF-8 encoding,

instead of the locale encoding.
parent c1f32ca0
......@@ -199,7 +199,7 @@ class MimeTypes:
list of standard types, else to the list of non-standard
types.
"""
with open(filename) as fp:
with open(filename, encoding='utf-8') as fp:
self.readfp(fp, strict)
def readfp(self, fp, strict=True):
......
This diff is collapsed.
import mimetypes
import io
import unittest
import locale
import mimetypes
import sys
import unittest
from test import support
......@@ -62,6 +63,18 @@ class MimeTypesTestCase(unittest.TestCase):
all = self.db.guess_all_extensions('image/jpg', strict=True)
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")
class Win32MimeTypesTestCase(unittest.TestCase):
......
......@@ -43,6 +43,9 @@ Core and Builtins
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
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