Commit 0ccda1ee authored by Mark Hammond's avatar Mark Hammond

Support 'mbcs' as a 'built-in' encoding, so the C API can use it without

defering to the encodings package.
As described in [ 763111 ] mbcs encoding should skip encodings package
parent ecc71710
...@@ -531,6 +531,10 @@ PyObject *PyUnicode_Decode(const char *s, ...@@ -531,6 +531,10 @@ PyObject *PyUnicode_Decode(const char *s,
return PyUnicode_DecodeUTF8(s, size, errors); return PyUnicode_DecodeUTF8(s, size, errors);
else if (strcmp(encoding, "latin-1") == 0) else if (strcmp(encoding, "latin-1") == 0)
return PyUnicode_DecodeLatin1(s, size, errors); return PyUnicode_DecodeLatin1(s, size, errors);
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
else if (strcmp(encoding, "mbcs") == 0)
return PyUnicode_DecodeMBCS(s, size, errors);
#endif
else if (strcmp(encoding, "ascii") == 0) else if (strcmp(encoding, "ascii") == 0)
return PyUnicode_DecodeASCII(s, size, errors); return PyUnicode_DecodeASCII(s, size, errors);
...@@ -591,6 +595,10 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode, ...@@ -591,6 +595,10 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode,
return PyUnicode_AsUTF8String(unicode); return PyUnicode_AsUTF8String(unicode);
else if (strcmp(encoding, "latin-1") == 0) else if (strcmp(encoding, "latin-1") == 0)
return PyUnicode_AsLatin1String(unicode); return PyUnicode_AsLatin1String(unicode);
#if defined(MS_WINDOWS) && defined(HAVE_USABLE_WCHAR_T)
else if (strcmp(encoding, "mbcs") == 0)
return PyUnicode_AsMBCSString(unicode);
#endif
else if (strcmp(encoding, "ascii") == 0) else if (strcmp(encoding, "ascii") == 0)
return PyUnicode_AsASCIIString(unicode); return PyUnicode_AsASCIIString(unicode);
} }
...@@ -2621,6 +2629,17 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p, ...@@ -2621,6 +2629,17 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
return repr; return repr;
} }
PyObject *PyUnicode_AsMBCSString(PyObject *unicode)
{
if (!PyUnicode_Check(unicode)) {
PyErr_BadArgument();
return NULL;
}
return PyUnicode_EncodeMBCS(PyUnicode_AS_UNICODE(unicode),
PyUnicode_GET_SIZE(unicode),
NULL);
}
#endif /* MS_WINDOWS */ #endif /* MS_WINDOWS */
/* --- Character Mapping Codec -------------------------------------------- */ /* --- Character Mapping Codec -------------------------------------------- */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment