mirror of
https://github.com/python/cpython.git
synced 2025-10-17 20:28:43 +00:00
Use PyUnicode_EncodeCodePage() instead of PyUnicode_EncodeMBCS() with
PyUnicode_AsUnicodeAndSize()
This commit is contained in:
parent
22168998f5
commit
ac931b1e5b
1 changed files with 3 additions and 16 deletions
|
@ -3051,13 +3051,7 @@ PyObject *
|
||||||
PyUnicode_EncodeFSDefault(PyObject *unicode)
|
PyUnicode_EncodeFSDefault(PyObject *unicode)
|
||||||
{
|
{
|
||||||
#ifdef HAVE_MBCS
|
#ifdef HAVE_MBCS
|
||||||
const Py_UNICODE *wstr;
|
return PyUnicode_EncodeCodePage(CP_ACP, unicode, NULL);
|
||||||
Py_ssize_t wlen;
|
|
||||||
|
|
||||||
wstr = PyUnicode_AsUnicodeAndSize(unicode, &wlen);
|
|
||||||
if (wstr == NULL)
|
|
||||||
return NULL;
|
|
||||||
return PyUnicode_EncodeMBCS(wstr, wlen, NULL);
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
return _PyUnicode_AsUTF8String(unicode, "surrogateescape");
|
return _PyUnicode_AsUTF8String(unicode, "surrogateescape");
|
||||||
#else
|
#else
|
||||||
|
@ -3141,15 +3135,8 @@ PyUnicode_AsEncodedString(PyObject *unicode,
|
||||||
(strcmp(lower, "iso-8859-1") == 0))
|
(strcmp(lower, "iso-8859-1") == 0))
|
||||||
return _PyUnicode_AsLatin1String(unicode, errors);
|
return _PyUnicode_AsLatin1String(unicode, errors);
|
||||||
#ifdef HAVE_MBCS
|
#ifdef HAVE_MBCS
|
||||||
else if (strcmp(lower, "mbcs") == 0) {
|
else if (strcmp(lower, "mbcs") == 0)
|
||||||
const Py_UNICODE *wstr;
|
return PyUnicode_EncodeCodePage(CP_ACP, unicode, errors);
|
||||||
Py_ssize_t wlen;
|
|
||||||
|
|
||||||
wstr = PyUnicode_AsUnicodeAndSize(unicode, &wlen);
|
|
||||||
if (wstr == NULL)
|
|
||||||
return NULL;
|
|
||||||
return PyUnicode_EncodeMBCS(wstr, wlen, errors);
|
|
||||||
}
|
|
||||||
#endif
|
#endif
|
||||||
else if (strcmp(lower, "ascii") == 0)
|
else if (strcmp(lower, "ascii") == 0)
|
||||||
return _PyUnicode_AsASCIIString(unicode, errors);
|
return _PyUnicode_AsASCIIString(unicode, errors);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue