Skip to content

[3.7] bpo-29571: Fix test_re.test_locale_flag() #12178

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 5, 2019
Merged

[3.7] bpo-29571: Fix test_re.test_locale_flag() #12178

merged 2 commits into from
Mar 5, 2019

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Mar 5, 2019

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.

On Windows, set temporarily the LC_CTYPE locale to the user preferred
encoding to ensure that it uses the ANSI code page, to be consistent
with locale.getpreferredencoding().

https://bugs.python.org/issue29571

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.

On Windows, set temporarily the LC_CTYPE locale to the user preferred
encoding to ensure that it uses the ANSI code page, to be consistent
with locale.getpreferredencoding().
@vstinner
Copy link
Member Author

vstinner commented Mar 5, 2019

I tested manually the PR on Linux with "LANG=en_IN ./python -m test -v test_re": fail without the change, pass with the change.

I also tested the PR on Windows: test_re pass.

@vstinner vstinner merged commit 279657b into python:3.7 Mar 5, 2019
@vstinner vstinner deleted the test_locale_flag37 branch March 5, 2019 15:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants