mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
Add PyUnicode_DecodeLocaleAndSize() and PyUnicode_DecodeLocale()
* PyUnicode_DecodeLocaleAndSize() and PyUnicode_DecodeLocale() decode a string from the current locale encoding * _Py_char2wchar() writes an "error code" in the size argument to indicate if the function failed because of memory allocation failure or because of a decoding error. The function doesn't write the error message directly to stderr. * Fix time.strftime() (if wcsftime() is missing): decode strftime() result from the current locale encoding, not from the filesystem encoding.
This commit is contained in:
parent
3607e3de27
commit
af02e1c85a
7 changed files with 174 additions and 84 deletions
|
@ -532,7 +532,7 @@ time_strftime(PyObject *self, PyObject *args)
|
|||
#ifdef HAVE_WCSFTIME
|
||||
ret = PyUnicode_FromWideChar(outbuf, buflen);
|
||||
#else
|
||||
ret = PyUnicode_DecodeFSDefaultAndSize(outbuf, buflen);
|
||||
ret = PyUnicode_DecodeLocaleAndSize(outbuf, buflen, 1);
|
||||
#endif
|
||||
PyMem_Free(outbuf);
|
||||
break;
|
||||
|
@ -764,8 +764,8 @@ PyInit_timezone(PyObject *m) {
|
|||
#endif /* PYOS_OS2 */
|
||||
#endif
|
||||
PyModule_AddIntConstant(m, "daylight", daylight);
|
||||
otz0 = PyUnicode_DecodeFSDefaultAndSize(tzname[0], strlen(tzname[0]));
|
||||
otz1 = PyUnicode_DecodeFSDefaultAndSize(tzname[1], strlen(tzname[1]));
|
||||
otz0 = PyUnicode_DecodeLocale(tzname[0], 1);
|
||||
otz1 = PyUnicode_DecodeLocale(tzname[1], 1);
|
||||
PyModule_AddObject(m, "tzname", Py_BuildValue("(NN)", otz0, otz1));
|
||||
#else /* !HAVE_TZNAME || __GLIBC__ || __CYGWIN__*/
|
||||
#ifdef HAVE_STRUCT_TM_TM_ZONE
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue