diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2018-01-15 10:45:49 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-15 10:45:49 +0100 |
commit | 7ed7aead9503102d2ed316175f198104e0cd674c (patch) | |
tree | 0b70b3b7d2eed5ea92552c1b93953d0333f5a869 /Include | |
parent | ee3b83547c6b0cac1da2cb44aaaea533a1d1bbc8 (diff) | |
download | cpython-git-7ed7aead9503102d2ed316175f198104e0cd674c.tar.gz |
bpo-29240: Fix locale encodings in UTF-8 Mode (#5170)
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().
Diffstat (limited to 'Include')
-rw-r--r-- | Include/fileutils.h | 37 | ||||
-rw-r--r-- | Include/unicodeobject.h | 14 |
2 files changed, 30 insertions, 21 deletions
diff --git a/Include/fileutils.h b/Include/fileutils.h index 2527d84669..b4f8b11a63 100644 --- a/Include/fileutils.h +++ b/Include/fileutils.h @@ -20,18 +20,41 @@ PyAPI_FUNC(char*) _Py_EncodeLocaleRaw( #endif #ifdef Py_BUILD_CORE +PyAPI_FUNC(int) _Py_DecodeUTF8Ex( + const char *arg, + Py_ssize_t arglen, + wchar_t **wstr, + size_t *wlen, + const char **reason, + int surrogateescape); + +PyAPI_FUNC(int) _Py_EncodeUTF8Ex( + const wchar_t *text, + char **str, + size_t *error_pos, + const char **reason, + int raw_malloc, + int surrogateescape); + PyAPI_FUNC(wchar_t*) _Py_DecodeUTF8_surrogateescape( - const char *s, - Py_ssize_t size, - size_t *p_wlen); + const char *arg, + Py_ssize_t arglen); -PyAPI_FUNC(wchar_t *) _Py_DecodeCurrentLocale( +PyAPI_FUNC(int) _Py_DecodeLocaleEx( const char *arg, - size_t *size); + wchar_t **wstr, + size_t *wlen, + const char **reason, + int current_locale, + int surrogateescape); -PyAPI_FUNC(char*) _Py_EncodeCurrentLocale( +PyAPI_FUNC(int) _Py_EncodeLocaleEx( const wchar_t *text, - size_t *error_pos); + char **str, + size_t *error_pos, + const char **reason, + int current_locale, + int surrogateescape); #endif #ifndef Py_LIMITED_API diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index d263026b56..0274de6733 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1810,20 +1810,6 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeLocale( PyObject *unicode, const char *errors ); - -PyAPI_FUNC(PyObject*) _PyUnicode_DecodeCurrentLocale( - const char *str, - const char *errors); - -PyAPI_FUNC(PyObject*) _PyUnicode_DecodeCurrentLocaleAndSize( - const char *str, - Py_ssize_t len, - const char *errors); - -PyAPI_FUNC(PyObject*) _PyUnicode_EncodeCurrentLocale( - PyObject *unicode, - const char *errors - ); #endif /* --- File system encoding ---------------------------------------------- */ |