mirror of
https://github.com/python/cpython.git
synced 2025-08-24 02:35:59 +00:00
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.
This commit is contained in:
parent
66d4513975
commit
24bdb0474f
9 changed files with 116 additions and 56 deletions
|
@ -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 */
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue