summaryrefslogtreecommitdiffstats
path: root/Modules/_codecsmodule.c
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2000-03-28 20:29:59 (GMT)
committerGuido van Rossum <guido@python.org>2000-03-28 20:29:59 (GMT)
commit24bdb0474fca186da95dc045f157074e4d57c6b6 (patch)
treef3dc1f458303217ae0b3ecbff23d7dfe5e7b6d13 /Modules/_codecsmodule.c
parent66d451397577a7710902b75104839afc7ca05b81 (diff)
downloadcpython-24bdb0474fca186da95dc045f157074e4d57c6b6.zip
cpython-24bdb0474fca186da95dc045f157074e4d57c6b6.tar.gz
cpython-24bdb0474fca186da95dc045f157074e4d57c6b6.tar.bz2
Marc-Andre Lemburg:
The attached patch set includes a workaround to get Python with Unicode compile on BSDI 4.x (courtesy Thomas Wouters; the cause is a bug in the BSDI wchar.h header file) and Python interfaces for the MBCS codec donated by Mark Hammond. Also included are some minor corrections w/r to the docs of the new "es" and "es#" parser markers (use PyMem_Free() instead of free(); thanks to Mark Hammond for finding these). The unicodedata tests are now in a separate file (test_unicodedata.py) to avoid problems if the module cannot be found.
Diffstat (limited to 'Modules/_codecsmodule.c')
-rw-r--r--Modules/_codecsmodule.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 6c8a2d4..4f368f8 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -286,6 +286,26 @@ charmap_decode(PyObject *self,
size);
}
+#ifdef MS_WIN32
+
+static PyObject *
+mbcs_decode(PyObject *self,
+ PyObject *args)
+{
+ const char *data;
+ int size;
+ const char *errors = NULL;
+
+ if (!PyArg_ParseTuple(args, "t#|z:mbcs_decode",
+ &data, &size, &errors))
+ return NULL;
+
+ return codec_tuple(PyUnicode_DecodeMBCS(data, size, errors),
+ size);
+}
+
+#endif /* MS_WIN32 */
+
/* --- Encoder ------------------------------------------------------------ */
static PyObject *
@@ -491,6 +511,28 @@ charmap_encode(PyObject *self,
PyUnicode_GET_SIZE(str));
}
+#ifdef MS_WIN32
+
+static PyObject *
+mbcs_encode(PyObject *self,
+ PyObject *args)
+{
+ PyObject *str;
+ const char *errors = NULL;
+
+ if (!PyArg_ParseTuple(args, "U|z:mbcs_encode",
+ &str, &errors))
+ return NULL;
+
+ return codec_tuple(PyUnicode_EncodeMBCS(
+ PyUnicode_AS_UNICODE(str),
+ PyUnicode_GET_SIZE(str),
+ errors),
+ PyUnicode_GET_SIZE(str));
+}
+
+#endif /* MS_WIN32 */
+
/* --- Module API --------------------------------------------------------- */
static PyMethodDef _codecs_functions[] = {
@@ -519,6 +561,10 @@ static PyMethodDef _codecs_functions[] = {
{"charmap_decode", charmap_decode, 1},
{"readbuffer_encode", readbuffer_encode, 1},
{"charbuffer_encode", charbuffer_encode, 1},
+#ifdef MS_WIN32
+ {"mbcs_encode", mbcs_encode, 1},
+ {"mbcs_decode", mbcs_decode, 1},
+#endif
{NULL, NULL} /* sentinel */
};