Visitar URL original
[3.7] bpo-29571: Fix test_re.test_locale_flag() (GH-12099) by miss-islington · Pull Request #12108 · python/cpython · GitHub
Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
bpo-29571: Fix test_re.test_locale_flag() (GH-12099)
Use locale.getpreferredencoding() rather than locale.getlocale() to
get the locale encoding. With some locales, locale.getlocale()
returns the wrong encoding.

For example, on Fedora 29, locale.getlocale() returns ISO-8859-1
encoding for the "en_IN" locale, whereas
locale.getpreferredencoding() reports the correct encoding: UTF-8.
(cherry picked from commit ab71f8b)

Co-authored-by: Victor Stinner <vstinner@redhat.com>
  • Loading branch information
vstinner authored and miss-islington committed Feb 28, 2019
commit 1a311ad3e692272da1473dbe024bf695416874ec
3 changes: 1 addition & 2 deletions Lib/test/test_re.py
Original file line number Diff line number Diff line change
Expand Up @@ -1516,8 +1516,7 @@ def test_ascii_and_unicode_flag(self):
self.assertRaises(re.error, re.compile, r'(?au)\w')

def test_locale_flag(self):
import locale
_, enc = locale.getlocale(locale.LC_CTYPE)
enc = locale.getpreferredencoding()
# Search non-ASCII letter
for i in range(128, 256):
try:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix ``test_re.test_locale_flag()``: use ``locale.getpreferredencoding()``
rather than ``locale.getlocale()`` to get the locale encoding. With some
locales, ``locale.getlocale()`` returns the wrong encoding.