diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2018-01-11 09:37:59 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-01-11 09:37:59 (GMT) |
commit | cb3ae5588bd7733e76dc09277bb7626652d9bb64 (patch) | |
tree | 137a100f35284a1327a8ec38052433aa21e13281 | |
parent | 3948207c610e931831828d33aaef258185df31db (diff) | |
download | cpython-cb3ae5588bd7733e76dc09277bb7626652d9bb64.zip cpython-cb3ae5588bd7733e76dc09277bb7626652d9bb64.tar.gz cpython-cb3ae5588bd7733e76dc09277bb7626652d9bb64.tar.bz2 |
bpo-29240: Ignore UTF-8 Mode in time module (#5148)
time.strftime() must use the current LC_CTYPE encoding, not UTF-8
if the UTF-8 mode is enabled.
Add _PyUnicode_DecodeCurrentLocale() function.
-rw-r--r-- | Include/unicodeobject.h | 4 | ||||
-rw-r--r-- | Modules/readline.c | 3 | ||||
-rw-r--r-- | Modules/timemodule.c | 12 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 6 |
4 files changed, 17 insertions, 8 deletions
diff --git a/Include/unicodeobject.h b/Include/unicodeobject.h index 576e7ad..d263026 100644 --- a/Include/unicodeobject.h +++ b/Include/unicodeobject.h @@ -1811,6 +1811,10 @@ PyAPI_FUNC(PyObject*) PyUnicode_EncodeLocale( 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, diff --git a/Modules/readline.c b/Modules/readline.c index 8db4cfd..caf661c 100644 --- a/Modules/readline.c +++ b/Modules/readline.c @@ -138,8 +138,7 @@ encode(PyObject *b) static PyObject * decode(const char *s) { - return _PyUnicode_DecodeCurrentLocaleAndSize(s, strlen(s), - "surrogateescape"); + return _PyUnicode_DecodeCurrentLocale(s, "surrogateescape"); } diff --git a/Modules/timemodule.c b/Modules/timemodule.c index 5cae03d..4e7f9d9 100644 --- a/Modules/timemodule.c +++ b/Modules/timemodule.c @@ -418,11 +418,11 @@ tmtotuple(struct tm *p SET(8, p->tm_isdst); #ifdef HAVE_STRUCT_TM_TM_ZONE PyStructSequence_SET_ITEM(v, 9, - PyUnicode_DecodeLocale(p->tm_zone, "surrogateescape")); + _PyUnicode_DecodeCurrentLocale(p->tm_zone, "surrogateescape")); SET(10, p->tm_gmtoff); #else PyStructSequence_SET_ITEM(v, 9, - PyUnicode_DecodeLocale(zone, "surrogateescape")); + _PyUnicode_DecodeCurrentLocale(zone, "surrogateescape")); PyStructSequence_SET_ITEM(v, 10, _PyLong_FromTime_t(gmtoff)); #endif /* HAVE_STRUCT_TM_TM_ZONE */ #undef SET @@ -809,8 +809,8 @@ time_strftime(PyObject *self, PyObject *args) #ifdef HAVE_WCSFTIME ret = PyUnicode_FromWideChar(outbuf, buflen); #else - ret = PyUnicode_DecodeLocaleAndSize(outbuf, buflen, - "surrogateescape"); + ret = _PyUnicode_DecodeCurrentLocaleAndSize(outbuf, buflen, + "surrogateescape"); #endif PyMem_Free(outbuf); break; @@ -1541,8 +1541,8 @@ PyInit_timezone(PyObject *m) { PyModule_AddIntConstant(m, "altzone", timezone-3600); #endif PyModule_AddIntConstant(m, "daylight", daylight); - otz0 = PyUnicode_DecodeLocale(tzname[0], "surrogateescape"); - otz1 = PyUnicode_DecodeLocale(tzname[1], "surrogateescape"); + otz0 = _PyUnicode_DecodeCurrentLocale(tzname[0], "surrogateescape"); + otz1 = _PyUnicode_DecodeCurrentLocale(tzname[1], "surrogateescape"); PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1)); #else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/ { diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 1a230e0..a6e02f4 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -3837,6 +3837,12 @@ _PyUnicode_DecodeCurrentLocaleAndSize(const char *str, Py_ssize_t len, } PyObject* +_PyUnicode_DecodeCurrentLocale(const char *str, const char *errors) +{ + return unicode_decode_locale(str, (Py_ssize_t)strlen(str), errors, 1); +} + +PyObject* PyUnicode_DecodeLocale(const char *str, const char *errors) { Py_ssize_t size = (Py_ssize_t)strlen(str); |