Skip to content
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

bpo-29240: Fix locale encodings in UTF-8 Mode #5170

Merged
merged 1 commit into from Jan 15, 2018
Merged

bpo-29240: Fix locale encodings in UTF-8 Mode #5170

merged 1 commit into from Jan 15, 2018

Conversation

vstinner
Copy link
Member

@vstinner vstinner commented Jan 13, 2018

Modify locale.localeconv(), time.tzname, os.strerror() and other
functions to ignore the UTF-8 Mode: always use the current locale
encoding.

Changes:

  • Add _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx(). On decoding or
    encoding error, they return the position of the error and an error
    message which are used to raise Unicode errors in
    PyUnicode_DecodeLocale() and PyUnicode_EncodeLocale().
  • Replace _Py_DecodeCurrentLocale() with _Py_DecodeLocaleEx().
  • PyUnicode_DecodeLocale() now uses _Py_DecodeLocaleEx() for all
    cases, especially for the strict error handler.
  • Add _Py_DecodeUTF8Ex(): return more information on decoding error
    and supports the strict error handler.
  • Rename _Py_EncodeUTF8_surrogateescape() to _Py_EncodeUTF8Ex().
  • Replace _Py_EncodeCurrentLocale() with _Py_EncodeLocaleEx().
  • Ignore the UTF-8 mode to encode/decode localeconv(), strerror()
    and time zone name.
  • Remove PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize()
    and PyUnicode_EncodeLocale() now ignore the UTF-8 mode: always use
    the "current" locale.
  • Remove _PyUnicode_DecodeCurrentLocale(),
    _PyUnicode_DecodeCurrentLocaleAndSize() and
    _PyUnicode_EncodeCurrentLocale().

https://bugs.python.org/issue29240

Modify locale.localeconv(), time.tzname, os.strerror() and other
functions to ignore the UTF-8 Mode: always use the current locale
encoding.

Changes:

* Add _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx(). On decoding or
  encoding error, they return the position of the error and an error
  message which are used to raise Unicode errors in
  PyUnicode_DecodeLocale() and PyUnicode_EncodeLocale().
* Replace _Py_DecodeCurrentLocale() with _Py_DecodeLocaleEx().
* PyUnicode_DecodeLocale() now uses _Py_DecodeLocaleEx() for all
  cases, especially for the strict error handler.
* Add _Py_DecodeUTF8Ex(): return more information on decoding error
  and supports the strict error handler.
* Rename _Py_EncodeUTF8_surrogateescape() to _Py_EncodeUTF8Ex().
* Replace _Py_EncodeCurrentLocale() with _Py_EncodeLocaleEx().
* Ignore the UTF-8 mode to encode/decode localeconv(), strerror()
  and time zone name.
* Remove PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize()
  and PyUnicode_EncodeLocale() now ignore the UTF-8 mode: always use
  the "current" locale.
* Remove _PyUnicode_DecodeCurrentLocale(),
  _PyUnicode_DecodeCurrentLocaleAndSize() and
  _PyUnicode_EncodeCurrentLocale().
@vstinner
Copy link
Member Author

I tested this PR using test_all_locales.py attached to https://bugs.python.org/issue29240 on Fedora 27, FreeBSD 11.0 and macOS 10.13.2. It works as expected.

@vstinner vstinner merged commit 7ed7aea into python:master Jan 15, 2018
@vstinner vstinner deleted the decode_locale_ex branch January 15, 2018 09:45
jeethu pushed a commit to jeethu/cpython that referenced this pull request Jan 16, 2018
Modify locale.localeconv(), time.tzname, os.strerror() and other
functions to ignore the UTF-8 Mode: always use the current locale
encoding.

Changes:

* Add _Py_DecodeLocaleEx() and _Py_EncodeLocaleEx(). On decoding or
  encoding error, they return the position of the error and an error
  message which are used to raise Unicode errors in
  PyUnicode_DecodeLocale() and PyUnicode_EncodeLocale().
* Replace _Py_DecodeCurrentLocale() with _Py_DecodeLocaleEx().
* PyUnicode_DecodeLocale() now uses _Py_DecodeLocaleEx() for all
  cases, especially for the strict error handler.
* Add _Py_DecodeUTF8Ex(): return more information on decoding error
  and supports the strict error handler.
* Rename _Py_EncodeUTF8_surrogateescape() to _Py_EncodeUTF8Ex().
* Replace _Py_EncodeCurrentLocale() with _Py_EncodeLocaleEx().
* Ignore the UTF-8 mode to encode/decode localeconv(), strerror()
  and time zone name.
* Remove PyUnicode_DecodeLocale(), PyUnicode_DecodeLocaleAndSize()
  and PyUnicode_EncodeLocale() now ignore the UTF-8 mode: always use
  the "current" locale.
* Remove _PyUnicode_DecodeCurrentLocale(),
  _PyUnicode_DecodeCurrentLocaleAndSize() and
  _PyUnicode_EncodeCurrentLocale().
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants