From d4fd31684ad5a7b9be8a9d26c5a8796f96c8d80b Mon Sep 17 00:00:00 2001 From: Mariusz Felisiak Date: Tue, 8 Mar 2022 13:17:05 +0100 Subject: [PATCH] Refs #33173 -- Used locale.getlocale() instead of getdefaultlocale(). locale.getdefaultlocale() was deprecated in Python 3.11, see https://bugs.python.org/issue46659. --- django/utils/encoding.py | 4 ++-- tests/utils_tests/test_encoding.py | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/django/utils/encoding.py b/django/utils/encoding.py index 89eac79dd4..360eb91ed5 100644 --- a/django/utils/encoding.py +++ b/django/utils/encoding.py @@ -249,12 +249,12 @@ def filepath_to_uri(path): 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 #10335 and #5846. """ try: - encoding = locale.getdefaultlocale()[1] or "ascii" + encoding = locale.getlocale()[1] or "ascii" codecs.lookup(encoding) except Exception: encoding = "ascii" diff --git a/tests/utils_tests/test_encoding.py b/tests/utils_tests/test_encoding.py index 8dddd4e250..6dea260b84 100644 --- a/tests/utils_tests/test_encoding.py +++ b/tests/utils_tests/test_encoding.py @@ -106,7 +106,7 @@ class TestEncodingUtils(SimpleTestCase): self.assertEqual(smart_str("foo"), "foo") 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") def test_repercent_broken_unicode_recursion_error(self):