Refs #33173 -- Used locale.getlocale() instead of getdefaultlocale().

locale.getdefaultlocale() was deprecated in Python 3.11, see
https://bugs.python.org/issue46659.
This commit is contained in:
Mariusz Felisiak 2022-03-08 13:17:05 +01:00 committed by GitHub
parent d9fc383a5e
commit d4fd31684a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 3 deletions

View File

@ -249,12 +249,12 @@ def filepath_to_uri(path):
def get_system_encoding(): def get_system_encoding():
""" """
The encoding of the default system locale. Fallback to 'ascii' if the The encoding for the character type functions. Fallback to 'ascii' if the
#encoding is unsupported by Python or could not be determined. See tickets #encoding is unsupported by Python or could not be determined. See tickets
#10335 and #5846. #10335 and #5846.
""" """
try: try:
encoding = locale.getdefaultlocale()[1] or "ascii" encoding = locale.getlocale()[1] or "ascii"
codecs.lookup(encoding) codecs.lookup(encoding)
except Exception: except Exception:
encoding = "ascii" encoding = "ascii"

View File

@ -106,7 +106,7 @@ class TestEncodingUtils(SimpleTestCase):
self.assertEqual(smart_str("foo"), "foo") self.assertEqual(smart_str("foo"), "foo")
def test_get_default_encoding(self): def test_get_default_encoding(self):
with mock.patch("locale.getdefaultlocale", side_effect=Exception): with mock.patch("locale.getlocale", side_effect=Exception):
self.assertEqual(get_system_encoding(), "ascii") self.assertEqual(get_system_encoding(), "ascii")
def test_repercent_broken_unicode_recursion_error(self): def test_repercent_broken_unicode_recursion_error(self):