]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Support 'mbcs' as a 'built-in' encoding, so the C API can use it without
authorMark Hammond <mhammond@skippinet.com.au>
Tue, 1 Jul 2003 00:13:27 +0000 (00:13 +0000)
committerMark Hammond <mhammond@skippinet.com.au>
Tue, 1 Jul 2003 00:13:27 +0000 (00:13 +0000)
defering to the encodings package.
As described in [ 763111 ] mbcs encoding should skip encodings package

Objects/unicodeobject.c

index af427dd11887c2ae8546b24f588e6a4fcccb729a..b165597273550b4e3e4a89c9a7428a4cce57bc3d 100644 (file)
@@ -531,6 +531,10 @@ PyObject *PyUnicode_Decode(const char *s,
         return PyUnicode_DecodeUTF8(s, size, errors);
     else if (strcmp(encoding, "latin-1") == 0)
         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)
         return PyUnicode_DecodeASCII(s, size, errors);
 
@@ -591,6 +595,10 @@ PyObject *PyUnicode_AsEncodedString(PyObject *unicode,
            return PyUnicode_AsUTF8String(unicode);
        else if (strcmp(encoding, "latin-1") == 0)
            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)
            return PyUnicode_AsASCIIString(unicode);
     }
@@ -2621,6 +2629,17 @@ PyObject *PyUnicode_EncodeMBCS(const Py_UNICODE *p,
     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 */
 
 /* --- Character Mapping Codec -------------------------------------------- */