diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index d8b4bbda28a..0e90f3c9c6f 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -51,16 +51,21 @@ module _codecs /* --- Registry ----------------------------------------------------------- */ -PyDoc_STRVAR(register__doc__, -"register(search_function)\n\ -\n\ -Register a codec search function. Search functions are expected to take\n\ -one argument, the encoding name in all lower case letters, and either\n\ -return None, or a tuple of functions (encoder, decoder, stream_reader,\n\ -stream_writer) (or a CodecInfo object)."); +/*[clinic input] +_codecs.register + search_function: object + / -static -PyObject *codec_register(PyObject *self, PyObject *search_function) +Register a codec search function. + +Search functions are expected to take one argument, the encoding name in +all lower case letters, and either return None, or a tuple of functions +(encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object). +[clinic start generated code]*/ + +static PyObject * +_codecs_register(PyModuleDef *module, PyObject *search_function) +/*[clinic end generated code: output=d17608b6ad380eb8 input=369578467955cae4]*/ { if (PyCodec_Register(search_function)) return NULL; @@ -68,79 +73,73 @@ PyObject *codec_register(PyObject *self, PyObject *search_function) Py_RETURN_NONE; } -PyDoc_STRVAR(lookup__doc__, -"lookup(encoding) -> CodecInfo\n\ -\n\ -Looks up a codec tuple in the Python codec registry and returns\n\ -a CodecInfo object."); +/*[clinic input] +_codecs.lookup + encoding: str + / -static -PyObject *codec_lookup(PyObject *self, PyObject *args) +Looks up a codec tuple in the Python codec registry and returns a CodecInfo object. +[clinic start generated code]*/ + +static PyObject * +_codecs_lookup_impl(PyModuleDef *module, const char *encoding) +/*[clinic end generated code: output=798e41aff0c04ef6 input=3c572c0db3febe9c]*/ { - char *encoding; - - if (!PyArg_ParseTuple(args, "s:lookup", &encoding)) - return NULL; - return _PyCodec_Lookup(encoding); } -PyDoc_STRVAR(encode__doc__, -"encode(obj, [encoding[,errors]]) -> object\n\ -\n\ -Encodes obj using the codec registered for encoding. encoding defaults\n\ -to the default encoding. errors may be given to set a different error\n\ -handling scheme. Default is 'strict' meaning that encoding errors raise\n\ -a ValueError. Other possible values are 'ignore', 'replace' and\n\ -'xmlcharrefreplace' as well as any other name registered with\n\ -codecs.register_error that can handle ValueErrors."); +/*[clinic input] +_codecs.encode + obj: object + encoding: str(c_default="NULL") = sys.getdefaultencoding() + errors: str(c_default="NULL") = "strict" + +Encodes obj using the codec registered for encoding. + +encoding defaults to the default encoding. errors may be given to set a +different error handling scheme. Default is 'strict' meaning that encoding +errors raise a ValueError. Other possible values are 'ignore', 'replace' +and 'backslashreplace' as well as any other name registered with +codecs.register_error that can handle ValueErrors. +[clinic start generated code]*/ static PyObject * -codec_encode(PyObject *self, PyObject *args, PyObject *kwargs) +_codecs_encode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, + const char *errors) +/*[clinic end generated code: output=5c073f62249c8d7c input=2440d769df020a0e]*/ { - static char *kwlist[] = {"obj", "encoding", "errors", NULL}; - const char *encoding = NULL; - const char *errors = NULL; - PyObject *v; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:encode", kwlist, - &v, &encoding, &errors)) - return NULL; - if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); /* Encode via the codec registry */ - return PyCodec_Encode(v, encoding, errors); + return PyCodec_Encode(obj, encoding, errors); } -PyDoc_STRVAR(decode__doc__, -"decode(obj, [encoding[,errors]]) -> object\n\ -\n\ -Decodes obj using the codec registered for encoding. encoding defaults\n\ -to the default encoding. errors may be given to set a different error\n\ -handling scheme. Default is 'strict' meaning that encoding errors raise\n\ -a ValueError. Other possible values are 'ignore' and 'replace'\n\ -as well as any other name registered with codecs.register_error that is\n\ -able to handle ValueErrors."); +/*[clinic input] +_codecs.decode + obj: object + encoding: str(c_default="NULL") = sys.getdefaultencoding() + errors: str(c_default="NULL") = "strict" + +Decodes obj using the codec registered for encoding. + +encoding defaults to the default encoding. errors may be given to set a +different error handling scheme. Default is 'strict' meaning that encoding +errors raise a ValueError. Other possible values are 'ignore', 'replace' +and 'backslashreplace' as well as any other name registered with +codecs.register_error that can handle ValueErrors. +[clinic start generated code]*/ static PyObject * -codec_decode(PyObject *self, PyObject *args, PyObject *kwargs) +_codecs_decode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, + const char *errors) +/*[clinic end generated code: output=c81cbf6189a7f878 input=a351e5f5baad1544]*/ { - static char *kwlist[] = {"obj", "encoding", "errors", NULL}; - const char *encoding = NULL; - const char *errors = NULL; - PyObject *v; - - if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:decode", kwlist, - &v, &encoding, &errors)) - return NULL; - if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); /* Decode via the codec registry */ - return PyCodec_Decode(v, encoding, errors); + return PyCodec_Decode(obj, encoding, errors); } /* --- Helpers ------------------------------------------------------------ */ @@ -165,51 +164,49 @@ _codecs__forget_codec_impl(PyModuleDef *module, const char *encoding) } static -PyObject *codec_tuple(PyObject *unicode, +PyObject *codec_tuple(PyObject *decoded, Py_ssize_t len) { - PyObject *v; - if (unicode == NULL) + if (decoded == NULL) return NULL; - v = Py_BuildValue("On", unicode, len); - Py_DECREF(unicode); - return v; + return Py_BuildValue("Nn", decoded, len); } /* --- String codecs ------------------------------------------------------ */ -static PyObject * -escape_decode(PyObject *self, - PyObject *args) -{ - Py_buffer pbuf; - const char *errors = NULL; - PyObject *result; +/*[clinic input] +_codecs.escape_decode + data: Py_buffer(accept={str, buffer}) + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "s*|z:escape_decode", - &pbuf, &errors)) - return NULL; - result = codec_tuple( - PyBytes_DecodeEscape(pbuf.buf, pbuf.len, errors, 0, NULL), - pbuf.len); - PyBuffer_Release(&pbuf); - return result; +static PyObject * +_codecs_escape_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors) +/*[clinic end generated code: output=648fa3e78d03e658 input=0018edfd99db714d]*/ +{ + PyObject *decoded = PyBytes_DecodeEscape(data->buf, data->len, + errors, 0, NULL); + return codec_tuple(decoded, data->len); } +/*[clinic input] +_codecs.escape_encode + data: object(subclass_of='&PyBytes_Type') + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ + static PyObject * -escape_encode(PyObject *self, - PyObject *args) +_codecs_escape_encode_impl(PyModuleDef *module, PyObject *data, + const char *errors) +/*[clinic end generated code: output=fcd6f34fe4111c50 input=da9ded00992f32f2]*/ { - PyObject *str; Py_ssize_t size; Py_ssize_t newsize; - const char *errors = NULL; PyObject *v; - if (!PyArg_ParseTuple(args, "O!|z:escape_encode", - &PyBytes_Type, &str, &errors)) - return NULL; - - size = PyBytes_GET_SIZE(str); + size = PyBytes_GET_SIZE(data); if (size > PY_SSIZE_T_MAX / 4) { PyErr_SetString(PyExc_OverflowError, "string is too large to encode"); @@ -229,7 +226,7 @@ escape_encode(PyObject *self, for (i = 0; i < size; i++) { /* There's at least enough room for a hex escape */ assert(newsize - (p - PyBytes_AS_STRING(v)) >= 4); - c = PyBytes_AS_STRING(str)[i]; + c = PyBytes_AS_STRING(data)[i]; if (c == '\'' || c == '\\') *p++ = '\\', *p++ = c; else if (c == '\t') @@ -257,18 +254,18 @@ escape_encode(PyObject *self, } /* --- Decoder ------------------------------------------------------------ */ +/*[clinic input] +_codecs.unicode_internal_decode + obj: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ static PyObject * -unicode_internal_decode(PyObject *self, - PyObject *args) +_codecs_unicode_internal_decode_impl(PyModuleDef *module, PyObject *obj, + const char *errors) +/*[clinic end generated code: output=9fe47c2cd8807d92 input=8d57930aeda170c6]*/ { - PyObject *obj; - const char *errors = NULL; - - if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode", - &obj, &errors)) - return NULL; - if (PyUnicode_Check(obj)) { if (PyUnicode_READY(obj) < 0) return NULL; @@ -289,120 +286,109 @@ unicode_internal_decode(PyObject *self, } } +/*[clinic input] +_codecs.utf_7_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -utf_7_decode(PyObject *self, - PyObject *args) +_codecs_utf_7_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=ca945e907e72e827 input=bc4d6247ecdb01e6]*/ { - Py_buffer pbuf; - const char *errors = NULL; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded = NULL; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_7_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; - - decoded = PyUnicode_DecodeUTF7Stateful(pbuf.buf, pbuf.len, errors, - final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF7Stateful(data->buf, data->len, + errors, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } +/*[clinic input] +_codecs.utf_8_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -utf_8_decode(PyObject *self, - PyObject *args) +_codecs_utf_8_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=7309f9ff4ef5c9b6 input=39161d71e7422ee2]*/ { - Py_buffer pbuf; - const char *errors = NULL; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded = NULL; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_8_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; - - decoded = PyUnicode_DecodeUTF8Stateful(pbuf.buf, pbuf.len, errors, - final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF8Stateful(data->buf, data->len, + errors, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } +/*[clinic input] +_codecs.utf_16_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -utf_16_decode(PyObject *self, - PyObject *args) +_codecs_utf_16_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=8d2fa0507d9bef2c input=f3cf01d1461007ce]*/ { - Py_buffer pbuf; - const char *errors = NULL; int byteorder = 0; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_16_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; /* This is overwritten unless final is true. */ - decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } +/*[clinic input] +_codecs.utf_16_le_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -utf_16_le_decode(PyObject *self, - PyObject *args) +_codecs_utf_16_le_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=4fd621515ef4ce18 input=a77e3bf97335d94e]*/ { - Py_buffer pbuf; - const char *errors = NULL; int byteorder = -1; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded = NULL; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_16_le_decode", - &pbuf, &errors, &final)) - return NULL; - - consumed = pbuf.len; /* This is overwritten unless final is true. */ - decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } +/*[clinic input] +_codecs.utf_16_be_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -utf_16_be_decode(PyObject *self, - PyObject *args) +_codecs_utf_16_be_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=792f4eacb3e1fa05 input=606f69fae91b5563]*/ { - Py_buffer pbuf; - const char *errors = NULL; int byteorder = 1; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded = NULL; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_16_be_decode", - &pbuf, &errors, &final)) - return NULL; - - consumed = pbuf.len; /* This is overwritten unless final is true. */ - decoded = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } @@ -413,98 +399,94 @@ utf_16_be_decode(PyObject *self, being the value in effect at the end of data. */ +/*[clinic input] +_codecs.utf_16_ex_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + byteorder: int = 0 + final: int(c_default="0") = False + / +[clinic start generated code]*/ static PyObject * -utf_16_ex_decode(PyObject *self, - PyObject *args) +_codecs_utf_16_ex_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int byteorder, int final) +/*[clinic end generated code: output=f136a186dc2defa0 input=f6e7f697658c013e]*/ { - Py_buffer pbuf; - const char *errors = NULL; - int byteorder = 0; - PyObject *unicode, *tuple; - int final = 0; - Py_ssize_t consumed; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; - if (!PyArg_ParseTuple(args, "y*|zii:utf_16_ex_decode", - &pbuf, &errors, &byteorder, &final)) - return NULL; - consumed = pbuf.len; /* This is overwritten unless final is true. */ - unicode = PyUnicode_DecodeUTF16Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (unicode == NULL) - return NULL; - tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); - Py_DECREF(unicode); - return tuple; -} - -static PyObject * -utf_32_decode(PyObject *self, - PyObject *args) -{ - Py_buffer pbuf; - const char *errors = NULL; - int byteorder = 0; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_32_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; /* This is overwritten unless final is true. */ - decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); + PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); if (decoded == NULL) return NULL; + return Py_BuildValue("Nni", decoded, consumed, byteorder); +} + +/*[clinic input] +_codecs.utf_32_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + +static PyObject * +_codecs_utf_32_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=b7635e55857e8efb input=86d4f41c6c2e763d]*/ +{ + int byteorder = 0; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } +/*[clinic input] +_codecs.utf_32_le_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -utf_32_le_decode(PyObject *self, - PyObject *args) +_codecs_utf_32_le_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=a79d1787d8ddf988 input=d18b650772d188ba]*/ { - Py_buffer pbuf; - const char *errors = NULL; int byteorder = -1; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded; - - if (!PyArg_ParseTuple(args, "y*|zi:utf_32_le_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; /* This is overwritten unless final is true. */ - decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } -static PyObject * -utf_32_be_decode(PyObject *self, - PyObject *args) -{ - Py_buffer pbuf; - const char *errors = NULL; - int byteorder = 1; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded; +/*[clinic input] +_codecs.utf_32_be_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "y*|zi:utf_32_be_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; /* This is overwritten unless final is true. */ - decoded = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; +static PyObject * +_codecs_utf_32_be_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=a8356b0f36779981 input=19c271b5d34926d8]*/ +{ + int byteorder = 1; + /* This is overwritten unless final is true. */ + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } @@ -515,167 +497,157 @@ utf_32_be_decode(PyObject *self, being the value in effect at the end of data. */ +/*[clinic input] +_codecs.utf_32_ex_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + byteorder: int = 0 + final: int(c_default="0") = False + / +[clinic start generated code]*/ static PyObject * -utf_32_ex_decode(PyObject *self, - PyObject *args) +_codecs_utf_32_ex_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int byteorder, int final) +/*[clinic end generated code: output=ab8c70977c1992f5 input=4af3e6ccfe34a076]*/ { - Py_buffer pbuf; - const char *errors = NULL; - int byteorder = 0; - PyObject *unicode, *tuple; - int final = 0; - Py_ssize_t consumed; - - if (!PyArg_ParseTuple(args, "y*|zii:utf_32_ex_decode", - &pbuf, &errors, &byteorder, &final)) + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len, + errors, &byteorder, + final ? NULL : &consumed); + if (decoded == NULL) return NULL; - consumed = pbuf.len; /* This is overwritten unless final is true. */ - unicode = PyUnicode_DecodeUTF32Stateful(pbuf.buf, pbuf.len, errors, - &byteorder, final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (unicode == NULL) - return NULL; - tuple = Py_BuildValue("Oni", unicode, consumed, byteorder); - Py_DECREF(unicode); - return tuple; + return Py_BuildValue("Nni", decoded, consumed, byteorder); } +/*[clinic input] +_codecs.unicode_escape_decode + data: Py_buffer(accept={str, buffer}) + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ + static PyObject * -unicode_escape_decode(PyObject *self, - PyObject *args) +_codecs_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors) +/*[clinic end generated code: output=d1aa63f2620c4999 input=49fd27d06813a7f5]*/ { - Py_buffer pbuf; - const char *errors = NULL; - PyObject *unicode; - - if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode", - &pbuf, &errors)) - return NULL; - - unicode = PyUnicode_DecodeUnicodeEscape(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + PyObject *decoded = PyUnicode_DecodeUnicodeEscape(data->buf, data->len, + errors); + return codec_tuple(decoded, data->len); } +/*[clinic input] +_codecs.raw_unicode_escape_decode + data: Py_buffer(accept={str, buffer}) + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ + static PyObject * -raw_unicode_escape_decode(PyObject *self, - PyObject *args) +_codecs_raw_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors) +/*[clinic end generated code: output=0bf96cc182d81379 input=770903a211434ebc]*/ { - Py_buffer pbuf; - const char *errors = NULL; - PyObject *unicode; - - if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode", - &pbuf, &errors)) - return NULL; - - unicode = PyUnicode_DecodeRawUnicodeEscape(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + PyObject *decoded = PyUnicode_DecodeRawUnicodeEscape(data->buf, data->len, + errors); + return codec_tuple(decoded, data->len); } +/*[clinic input] +_codecs.latin_1_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ + static PyObject * -latin_1_decode(PyObject *self, - PyObject *args) +_codecs_latin_1_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors) +/*[clinic end generated code: output=66b916f5055aaf13 input=5cad0f1759c618ec]*/ { - Py_buffer pbuf; - PyObject *unicode; - const char *errors = NULL; - - if (!PyArg_ParseTuple(args, "y*|z:latin_1_decode", - &pbuf, &errors)) - return NULL; - - unicode = PyUnicode_DecodeLatin1(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + PyObject *decoded = PyUnicode_DecodeLatin1(data->buf, data->len, errors); + return codec_tuple(decoded, data->len); } +/*[clinic input] +_codecs.ascii_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ + static PyObject * -ascii_decode(PyObject *self, - PyObject *args) +_codecs_ascii_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors) +/*[clinic end generated code: output=7f213a1b5cdafc65 input=ad1106f64037bd16]*/ { - Py_buffer pbuf; - PyObject *unicode; - const char *errors = NULL; - - if (!PyArg_ParseTuple(args, "y*|z:ascii_decode", - &pbuf, &errors)) - return NULL; - - unicode = PyUnicode_DecodeASCII(pbuf.buf, pbuf.len, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + PyObject *decoded = PyUnicode_DecodeASCII(data->buf, data->len, errors); + return codec_tuple(decoded, data->len); } -static PyObject * -charmap_decode(PyObject *self, - PyObject *args) -{ - Py_buffer pbuf; - PyObject *unicode; - const char *errors = NULL; - PyObject *mapping = NULL; +/*[clinic input] +_codecs.charmap_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + mapping: object = NULL + / +[clinic start generated code]*/ + +static PyObject * +_codecs_charmap_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, PyObject *mapping) +/*[clinic end generated code: output=87d27f365098bbae input=19712ca35c5a80e2]*/ +{ + PyObject *decoded; - if (!PyArg_ParseTuple(args, "y*|zO:charmap_decode", - &pbuf, &errors, &mapping)) - return NULL; if (mapping == Py_None) mapping = NULL; - unicode = PyUnicode_DecodeCharmap(pbuf.buf, pbuf.len, mapping, errors); - PyBuffer_Release(&pbuf); - return codec_tuple(unicode, pbuf.len); + decoded = PyUnicode_DecodeCharmap(data->buf, data->len, mapping, errors); + return codec_tuple(decoded, data->len); } #ifdef HAVE_MBCS +/*[clinic input] +_codecs.mbcs_decode + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -mbcs_decode(PyObject *self, - PyObject *args) +_codecs_mbcs_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final) +/*[clinic end generated code: output=0ebaf3a5b20e53fa input=d492c1ca64f4fa8a]*/ { - Py_buffer pbuf; - const char *errors = NULL; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded = NULL; - - if (!PyArg_ParseTuple(args, "y*|zi:mbcs_decode", - &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; - - decoded = PyUnicode_DecodeMBCSStateful(pbuf.buf, pbuf.len, errors, - final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeMBCSStateful(data->buf, data->len, + errors, final ? NULL : &consumed); return codec_tuple(decoded, consumed); } +/*[clinic input] +_codecs.code_page_decode + codepage: int + data: Py_buffer + errors: str(accept={str, NoneType}) = NULL + final: int(c_default="0") = False + / +[clinic start generated code]*/ + static PyObject * -code_page_decode(PyObject *self, - PyObject *args) +_codecs_code_page_decode_impl(PyModuleDef *module, int codepage, + Py_buffer *data, const char *errors, int final) +/*[clinic end generated code: output=4318e3d9971e31ba input=4f3152a304e21d51]*/ { - Py_buffer pbuf; - const char *errors = NULL; - int final = 0; - Py_ssize_t consumed; - PyObject *decoded = NULL; - int code_page; - - if (!PyArg_ParseTuple(args, "iy*|zi:code_page_decode", - &code_page, &pbuf, &errors, &final)) - return NULL; - consumed = pbuf.len; - - decoded = PyUnicode_DecodeCodePageStateful(code_page, - pbuf.buf, pbuf.len, errors, - final ? NULL : &consumed); - PyBuffer_Release(&pbuf); - if (decoded == NULL) - return NULL; + Py_ssize_t consumed = data->len; + PyObject *decoded = PyUnicode_DecodeCodePageStateful(code_page, + data->buf, data->len, + errors, + final ? NULL : &consumed); return codec_tuple(decoded, consumed); } @@ -683,43 +655,39 @@ code_page_decode(PyObject *self, /* --- Encoder ------------------------------------------------------------ */ +/*[clinic input] +_codecs.readbuffer_encode + data: Py_buffer(accept={str, buffer}) + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ + static PyObject * -readbuffer_encode(PyObject *self, - PyObject *args) +_codecs_readbuffer_encode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors) +/*[clinic end generated code: output=319cc24083299859 input=b7c322b89d4ab923]*/ { - Py_buffer pdata; - const char *data; - Py_ssize_t size; - const char *errors = NULL; - PyObject *result; - - if (!PyArg_ParseTuple(args, "s*|z:readbuffer_encode", - &pdata, &errors)) - return NULL; - data = pdata.buf; - size = pdata.len; - - result = PyBytes_FromStringAndSize(data, size); - PyBuffer_Release(&pdata); - return codec_tuple(result, size); + PyObject *result = PyBytes_FromStringAndSize(data->buf, data->len); + return codec_tuple(result, data->len); } -static PyObject * -unicode_internal_encode(PyObject *self, - PyObject *args) -{ - PyObject *obj; - const char *errors = NULL; +/*[clinic input] +_codecs.unicode_internal_encode + obj: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ +static PyObject * +_codecs_unicode_internal_encode_impl(PyModuleDef *module, PyObject *obj, + const char *errors) +/*[clinic end generated code: output=be08457068ad503b input=8628f0280cf5ba61]*/ +{ if (PyErr_WarnEx(PyExc_DeprecationWarning, "unicode_internal codec has been deprecated", 1)) return NULL; - if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode", - &obj, &errors)) - return NULL; - if (PyUnicode_Check(obj)) { Py_UNICODE *u; Py_ssize_t len, size; @@ -741,22 +709,26 @@ unicode_internal_encode(PyObject *self, PyObject *result; if (PyObject_GetBuffer(obj, &view, PyBUF_SIMPLE) != 0) return NULL; - result = codec_tuple(PyBytes_FromStringAndSize(view.buf, view.len), view.len); + result = codec_tuple(PyBytes_FromStringAndSize(view.buf, view.len), + view.len); PyBuffer_Release(&view); return result; } } -static PyObject * -utf_7_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.utf_7_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:utf_7_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=a7accc496a32b759 input=fd91a78f103b0421]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -769,16 +741,19 @@ utf_7_encode(PyObject *self, return v; } -static PyObject * -utf_8_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.utf_8_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:utf_8_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=ec831d80e7aedede input=2c22d40532f071f3]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -798,17 +773,20 @@ utf_8_encode(PyObject *self, */ -static PyObject * -utf_16_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; - int byteorder = 0; +/*[clinic input] +_codecs.utf_16_encode + str: object + errors: str(accept={str, NoneType}) = NULL + byteorder: int = 0 + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode", - &str, &errors, &byteorder)) - return NULL; +static PyObject * +_codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors, int byteorder) +/*[clinic end generated code: output=93ac58e960a9ee4d input=3935a489b2d5385e]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -821,16 +799,19 @@ utf_16_encode(PyObject *self, return v; } -static PyObject * -utf_16_le_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.utf_16_le_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=422bedb8da34fb66 input=bc27df05d1d20dfe]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -843,16 +824,19 @@ utf_16_le_encode(PyObject *self, return v; } -static PyObject * -utf_16_be_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.utf_16_be_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=3aa7ee9502acdd77 input=5a69d4112763462b]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -872,17 +856,20 @@ utf_16_be_encode(PyObject *self, */ -static PyObject * -utf_32_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; - int byteorder = 0; +/*[clinic input] +_codecs.utf_32_encode + str: object + errors: str(accept={str, NoneType}) = NULL + byteorder: int = 0 + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode", - &str, &errors, &byteorder)) - return NULL; +static PyObject * +_codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors, int byteorder) +/*[clinic end generated code: output=3e7d5a003b02baed input=434a1efa492b8d58]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -895,16 +882,19 @@ utf_32_encode(PyObject *self, return v; } -static PyObject * -utf_32_le_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.utf_32_le_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=5dda641cd33dbfc2 input=dfa2d7dc78b99422]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -917,16 +907,19 @@ utf_32_le_encode(PyObject *self, return v; } -static PyObject * -utf_32_be_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.utf_32_be_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=ccca8b44d91a7c7a input=4595617b18169002]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -939,16 +932,19 @@ utf_32_be_encode(PyObject *self, return v; } -static PyObject * -unicode_escape_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.unicode_escape_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=389f23d2b8f8d80b input=8273506f14076912]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -961,16 +957,19 @@ unicode_escape_encode(PyObject *self, return v; } -static PyObject * -raw_unicode_escape_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.raw_unicode_escape_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=fec4e39d6ec37a62 input=181755d5dfacef3c]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -983,16 +982,19 @@ raw_unicode_escape_encode(PyObject *self, return v; } -static PyObject * -latin_1_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.latin_1_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:latin_1_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=ecf00eb8e48c889c input=f03f6dcf1d84bee4]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -1005,16 +1007,19 @@ latin_1_encode(PyObject *self, return v; } -static PyObject * -ascii_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.ascii_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:ascii_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=a9d18fc6b6b91cfb input=d87e25a10a593fee]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -1027,17 +1032,21 @@ ascii_encode(PyObject *self, return v; } -static PyObject * -charmap_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; - PyObject *mapping = NULL; +/*[clinic input] +_codecs.charmap_encode + str: object + errors: str(accept={str, NoneType}) = NULL + mapping: object = NULL + / +[clinic start generated code]*/ + +static PyObject * +_codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors, PyObject *mapping) +/*[clinic end generated code: output=14ca42b83853c643 input=85f4172661e8dad9]*/ +{ + PyObject *v; - if (!PyArg_ParseTuple(args, "O|zO:charmap_encode", - &str, &errors, &mapping)) - return NULL; if (mapping == Py_None) mapping = NULL; @@ -1052,27 +1061,34 @@ charmap_encode(PyObject *self, return v; } -static PyObject* -charmap_build(PyObject *self, PyObject *args) +/*[clinic input] +_codecs.charmap_build + map: unicode + / +[clinic start generated code]*/ + +static PyObject * +_codecs_charmap_build_impl(PyModuleDef *module, PyObject *map) +/*[clinic end generated code: output=9485b58fa44afa6a input=d91a91d1717dbc6d]*/ { - PyObject *map; - if (!PyArg_ParseTuple(args, "U:charmap_build", &map)) - return NULL; return PyUnicode_BuildEncodingMap(map); } #ifdef HAVE_MBCS -static PyObject * -mbcs_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; +/*[clinic input] +_codecs.mbcs_encode + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", - &str, &errors)) - return NULL; +static PyObject * +_codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors) +/*[clinic end generated code: output=d1a013bc68798bd7 input=65c09ee1e4203263]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -1085,17 +1101,20 @@ mbcs_encode(PyObject *self, return v; } -static PyObject * -code_page_encode(PyObject *self, - PyObject *args) -{ - PyObject *str, *v; - const char *errors = NULL; - int code_page; +/*[clinic input] +_codecs.code_page_encode + code_page: int + str: object + errors: str(accept={str, NoneType}) = NULL + / +[clinic start generated code]*/ - if (!PyArg_ParseTuple(args, "iO|z:code_page_encode", - &code_page, &str, &errors)) - return NULL; +static PyObject * +_codecs_code_page_encode_impl(PyModuleDef *module, int code_page, + PyObject *str, const char *errors) +/*[clinic end generated code: output=3b406618dbfbce25 input=c8562ec460c2e309]*/ +{ + PyObject *v; str = PyUnicode_FromObject(str); if (str == NULL || PyUnicode_READY(str) < 0) { @@ -1114,99 +1133,94 @@ code_page_encode(PyObject *self, /* --- Error handler registry --------------------------------------------- */ -PyDoc_STRVAR(register_error__doc__, -"register_error(errors, handler)\n\ -\n\ -Register the specified error handler under the name\n\ -errors. handler must be a callable object, that\n\ -will be called with an exception instance containing\n\ -information about the location of the encoding/decoding\n\ -error and must return a (replacement, new position) tuple."); +/*[clinic input] +_codecs.register_error + errors: str + handler: object + / -static PyObject *register_error(PyObject *self, PyObject *args) +Register the specified error handler under the name errors. + +handler must be a callable object, that will be called with an exception +instance containing information about the location of the encoding/decoding +error and must return a (replacement, new position) tuple. +[clinic start generated code]*/ + +static PyObject * +_codecs_register_error_impl(PyModuleDef *module, const char *errors, + PyObject *handler) +/*[clinic end generated code: output=be00d3b1849ce68a input=5e6709203c2e33fe]*/ { - const char *name; - PyObject *handler; - - if (!PyArg_ParseTuple(args, "sO:register_error", - &name, &handler)) - return NULL; - if (PyCodec_RegisterError(name, handler)) + if (PyCodec_RegisterError(errors, handler)) return NULL; Py_RETURN_NONE; } -PyDoc_STRVAR(lookup_error__doc__, -"lookup_error(errors) -> handler\n\ -\n\ -Return the error handler for the specified error handling name\n\ -or raise a LookupError, if no handler exists under this name."); +/*[clinic input] +_codecs.lookup_error + name: str + / -static PyObject *lookup_error(PyObject *self, PyObject *args) +lookup_error(errors) -> handler + +Return the error handler for the specified error handling name or raise a +LookupError, if no handler exists under this name. +[clinic start generated code]*/ + +static PyObject * +_codecs_lookup_error_impl(PyModuleDef *module, const char *name) +/*[clinic end generated code: output=731e6df8c83c6158 input=4775dd65e6235aba]*/ { - const char *name; - - if (!PyArg_ParseTuple(args, "s:lookup_error", - &name)) - return NULL; return PyCodec_LookupError(name); } /* --- Module API --------------------------------------------------------- */ static PyMethodDef _codecs_functions[] = { - {"register", codec_register, METH_O, - register__doc__}, - {"lookup", codec_lookup, METH_VARARGS, - lookup__doc__}, - {"encode", (PyCFunction)codec_encode, METH_VARARGS|METH_KEYWORDS, - encode__doc__}, - {"decode", (PyCFunction)codec_decode, METH_VARARGS|METH_KEYWORDS, - decode__doc__}, - {"escape_encode", escape_encode, METH_VARARGS}, - {"escape_decode", escape_decode, METH_VARARGS}, - {"utf_8_encode", utf_8_encode, METH_VARARGS}, - {"utf_8_decode", utf_8_decode, METH_VARARGS}, - {"utf_7_encode", utf_7_encode, METH_VARARGS}, - {"utf_7_decode", utf_7_decode, METH_VARARGS}, - {"utf_16_encode", utf_16_encode, METH_VARARGS}, - {"utf_16_le_encode", utf_16_le_encode, METH_VARARGS}, - {"utf_16_be_encode", utf_16_be_encode, METH_VARARGS}, - {"utf_16_decode", utf_16_decode, METH_VARARGS}, - {"utf_16_le_decode", utf_16_le_decode, METH_VARARGS}, - {"utf_16_be_decode", utf_16_be_decode, METH_VARARGS}, - {"utf_16_ex_decode", utf_16_ex_decode, METH_VARARGS}, - {"utf_32_encode", utf_32_encode, METH_VARARGS}, - {"utf_32_le_encode", utf_32_le_encode, METH_VARARGS}, - {"utf_32_be_encode", utf_32_be_encode, METH_VARARGS}, - {"utf_32_decode", utf_32_decode, METH_VARARGS}, - {"utf_32_le_decode", utf_32_le_decode, METH_VARARGS}, - {"utf_32_be_decode", utf_32_be_decode, METH_VARARGS}, - {"utf_32_ex_decode", utf_32_ex_decode, METH_VARARGS}, - {"unicode_escape_encode", unicode_escape_encode, METH_VARARGS}, - {"unicode_escape_decode", unicode_escape_decode, METH_VARARGS}, - {"unicode_internal_encode", unicode_internal_encode, METH_VARARGS}, - {"unicode_internal_decode", unicode_internal_decode, METH_VARARGS}, - {"raw_unicode_escape_encode", raw_unicode_escape_encode, METH_VARARGS}, - {"raw_unicode_escape_decode", raw_unicode_escape_decode, METH_VARARGS}, - {"latin_1_encode", latin_1_encode, METH_VARARGS}, - {"latin_1_decode", latin_1_decode, METH_VARARGS}, - {"ascii_encode", ascii_encode, METH_VARARGS}, - {"ascii_decode", ascii_decode, METH_VARARGS}, - {"charmap_encode", charmap_encode, METH_VARARGS}, - {"charmap_decode", charmap_decode, METH_VARARGS}, - {"charmap_build", charmap_build, METH_VARARGS}, - {"readbuffer_encode", readbuffer_encode, METH_VARARGS}, -#ifdef HAVE_MBCS - {"mbcs_encode", mbcs_encode, METH_VARARGS}, - {"mbcs_decode", mbcs_decode, METH_VARARGS}, - {"code_page_encode", code_page_encode, METH_VARARGS}, - {"code_page_decode", code_page_decode, METH_VARARGS}, -#endif - {"register_error", register_error, METH_VARARGS, - register_error__doc__}, - {"lookup_error", lookup_error, METH_VARARGS, - lookup_error__doc__}, + _CODECS_REGISTER_METHODDEF + _CODECS_LOOKUP_METHODDEF + _CODECS_ENCODE_METHODDEF + _CODECS_DECODE_METHODDEF + _CODECS_ESCAPE_ENCODE_METHODDEF + _CODECS_ESCAPE_DECODE_METHODDEF + _CODECS_UTF_8_ENCODE_METHODDEF + _CODECS_UTF_8_DECODE_METHODDEF + _CODECS_UTF_7_ENCODE_METHODDEF + _CODECS_UTF_7_DECODE_METHODDEF + _CODECS_UTF_16_ENCODE_METHODDEF + _CODECS_UTF_16_LE_ENCODE_METHODDEF + _CODECS_UTF_16_BE_ENCODE_METHODDEF + _CODECS_UTF_16_DECODE_METHODDEF + _CODECS_UTF_16_LE_DECODE_METHODDEF + _CODECS_UTF_16_BE_DECODE_METHODDEF + _CODECS_UTF_16_EX_DECODE_METHODDEF + _CODECS_UTF_32_ENCODE_METHODDEF + _CODECS_UTF_32_LE_ENCODE_METHODDEF + _CODECS_UTF_32_BE_ENCODE_METHODDEF + _CODECS_UTF_32_DECODE_METHODDEF + _CODECS_UTF_32_LE_DECODE_METHODDEF + _CODECS_UTF_32_BE_DECODE_METHODDEF + _CODECS_UTF_32_EX_DECODE_METHODDEF + _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF + _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF + _CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF + _CODECS_UNICODE_INTERNAL_DECODE_METHODDEF + _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF + _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF + _CODECS_LATIN_1_ENCODE_METHODDEF + _CODECS_LATIN_1_DECODE_METHODDEF + _CODECS_ASCII_ENCODE_METHODDEF + _CODECS_ASCII_DECODE_METHODDEF + _CODECS_CHARMAP_ENCODE_METHODDEF + _CODECS_CHARMAP_DECODE_METHODDEF + _CODECS_CHARMAP_BUILD_METHODDEF + _CODECS_READBUFFER_ENCODE_METHODDEF + _CODECS_MBCS_ENCODE_METHODDEF + _CODECS_MBCS_DECODE_METHODDEF + _CODECS_CODE_PAGE_ENCODE_METHODDEF + _CODECS_CODE_PAGE_DECODE_METHODDEF + _CODECS_REGISTER_ERROR_METHODDEF + _CODECS_LOOKUP_ERROR_METHODDEF _CODECS__FORGET_CODEC_METHODDEF {NULL, NULL} /* sentinel */ }; diff --git a/Modules/clinic/_codecsmodule.c.h b/Modules/clinic/_codecsmodule.c.h index 238bed46f4c..2b97b187ce4 100644 --- a/Modules/clinic/_codecsmodule.c.h +++ b/Modules/clinic/_codecsmodule.c.h @@ -2,6 +2,121 @@ preserve [clinic start generated code]*/ +PyDoc_STRVAR(_codecs_register__doc__, +"register($module, search_function, /)\n" +"--\n" +"\n" +"Register a codec search function.\n" +"\n" +"Search functions are expected to take one argument, the encoding name in\n" +"all lower case letters, and either return None, or a tuple of functions\n" +"(encoder, decoder, stream_reader, stream_writer) (or a CodecInfo object)."); + +#define _CODECS_REGISTER_METHODDEF \ + {"register", (PyCFunction)_codecs_register, METH_O, _codecs_register__doc__}, + +PyDoc_STRVAR(_codecs_lookup__doc__, +"lookup($module, encoding, /)\n" +"--\n" +"\n" +"Looks up a codec tuple in the Python codec registry and returns a CodecInfo object."); + +#define _CODECS_LOOKUP_METHODDEF \ + {"lookup", (PyCFunction)_codecs_lookup, METH_O, _codecs_lookup__doc__}, + +static PyObject * +_codecs_lookup_impl(PyModuleDef *module, const char *encoding); + +static PyObject * +_codecs_lookup(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + const char *encoding; + + if (!PyArg_Parse(arg, "s:lookup", &encoding)) + goto exit; + return_value = _codecs_lookup_impl(module, encoding); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_encode__doc__, +"encode($module, /, obj, encoding=sys.getdefaultencoding(),\n" +" errors=\'strict\')\n" +"--\n" +"\n" +"Encodes obj using the codec registered for encoding.\n" +"\n" +"encoding defaults to the default encoding. errors may be given to set a\n" +"different error handling scheme. Default is \'strict\' meaning that encoding\n" +"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n" +"and \'backslashreplace\' as well as any other name registered with\n" +"codecs.register_error that can handle ValueErrors."); + +#define _CODECS_ENCODE_METHODDEF \ + {"encode", (PyCFunction)_codecs_encode, METH_VARARGS|METH_KEYWORDS, _codecs_encode__doc__}, + +static PyObject * +_codecs_encode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, + const char *errors); + +static PyObject * +_codecs_encode(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"obj", "encoding", "errors", NULL}; + PyObject *obj; + const char *encoding = NULL; + const char *errors = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:encode", _keywords, + &obj, &encoding, &errors)) + goto exit; + return_value = _codecs_encode_impl(module, obj, encoding, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_decode__doc__, +"decode($module, /, obj, encoding=sys.getdefaultencoding(),\n" +" errors=\'strict\')\n" +"--\n" +"\n" +"Decodes obj using the codec registered for encoding.\n" +"\n" +"encoding defaults to the default encoding. errors may be given to set a\n" +"different error handling scheme. Default is \'strict\' meaning that encoding\n" +"errors raise a ValueError. Other possible values are \'ignore\', \'replace\'\n" +"and \'backslashreplace\' as well as any other name registered with\n" +"codecs.register_error that can handle ValueErrors."); + +#define _CODECS_DECODE_METHODDEF \ + {"decode", (PyCFunction)_codecs_decode, METH_VARARGS|METH_KEYWORDS, _codecs_decode__doc__}, + +static PyObject * +_codecs_decode_impl(PyModuleDef *module, PyObject *obj, const char *encoding, + const char *errors); + +static PyObject * +_codecs_decode(PyModuleDef *module, PyObject *args, PyObject *kwargs) +{ + PyObject *return_value = NULL; + static char *_keywords[] = {"obj", "encoding", "errors", NULL}; + PyObject *obj; + const char *encoding = NULL; + const char *errors = NULL; + + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:decode", _keywords, + &obj, &encoding, &errors)) + goto exit; + return_value = _codecs_decode_impl(module, obj, encoding, errors); + +exit: + return return_value; +} + PyDoc_STRVAR(_codecs__forget_codec__doc__, "_forget_codec($module, encoding, /)\n" "--\n" @@ -27,4 +142,1257 @@ _codecs__forget_codec(PyModuleDef *module, PyObject *arg) exit: return return_value; } -/*[clinic end generated code: output=52cc017e06c8ef9a input=a9049054013a1b77]*/ + +PyDoc_STRVAR(_codecs_escape_decode__doc__, +"escape_decode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_ESCAPE_DECODE_METHODDEF \ + {"escape_decode", (PyCFunction)_codecs_escape_decode, METH_VARARGS, _codecs_escape_decode__doc__}, + +static PyObject * +_codecs_escape_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors); + +static PyObject * +_codecs_escape_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "s*|z:escape_decode", + &data, &errors)) + goto exit; + return_value = _codecs_escape_decode_impl(module, &data, errors); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_escape_encode__doc__, +"escape_encode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_ESCAPE_ENCODE_METHODDEF \ + {"escape_encode", (PyCFunction)_codecs_escape_encode, METH_VARARGS, _codecs_escape_encode__doc__}, + +static PyObject * +_codecs_escape_encode_impl(PyModuleDef *module, PyObject *data, + const char *errors); + +static PyObject * +_codecs_escape_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *data; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O!|z:escape_encode", + &PyBytes_Type, &data, &errors)) + goto exit; + return_value = _codecs_escape_encode_impl(module, data, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_unicode_internal_decode__doc__, +"unicode_internal_decode($module, obj, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UNICODE_INTERNAL_DECODE_METHODDEF \ + {"unicode_internal_decode", (PyCFunction)_codecs_unicode_internal_decode, METH_VARARGS, _codecs_unicode_internal_decode__doc__}, + +static PyObject * +_codecs_unicode_internal_decode_impl(PyModuleDef *module, PyObject *obj, + const char *errors); + +static PyObject * +_codecs_unicode_internal_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *obj; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:unicode_internal_decode", + &obj, &errors)) + goto exit; + return_value = _codecs_unicode_internal_decode_impl(module, obj, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_7_decode__doc__, +"utf_7_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_7_DECODE_METHODDEF \ + {"utf_7_decode", (PyCFunction)_codecs_utf_7_decode, METH_VARARGS, _codecs_utf_7_decode__doc__}, + +static PyObject * +_codecs_utf_7_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_7_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_7_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_7_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_8_decode__doc__, +"utf_8_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_8_DECODE_METHODDEF \ + {"utf_8_decode", (PyCFunction)_codecs_utf_8_decode, METH_VARARGS, _codecs_utf_8_decode__doc__}, + +static PyObject * +_codecs_utf_8_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_8_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_8_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_8_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_decode__doc__, +"utf_16_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_DECODE_METHODDEF \ + {"utf_16_decode", (PyCFunction)_codecs_utf_16_decode, METH_VARARGS, _codecs_utf_16_decode__doc__}, + +static PyObject * +_codecs_utf_16_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_16_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_16_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_16_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_le_decode__doc__, +"utf_16_le_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_LE_DECODE_METHODDEF \ + {"utf_16_le_decode", (PyCFunction)_codecs_utf_16_le_decode, METH_VARARGS, _codecs_utf_16_le_decode__doc__}, + +static PyObject * +_codecs_utf_16_le_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_16_le_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_16_le_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_16_le_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_be_decode__doc__, +"utf_16_be_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_BE_DECODE_METHODDEF \ + {"utf_16_be_decode", (PyCFunction)_codecs_utf_16_be_decode, METH_VARARGS, _codecs_utf_16_be_decode__doc__}, + +static PyObject * +_codecs_utf_16_be_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_16_be_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_16_be_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_16_be_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_ex_decode__doc__, +"utf_16_ex_decode($module, data, errors=None, byteorder=0, final=False,\n" +" /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_EX_DECODE_METHODDEF \ + {"utf_16_ex_decode", (PyCFunction)_codecs_utf_16_ex_decode, METH_VARARGS, _codecs_utf_16_ex_decode__doc__}, + +static PyObject * +_codecs_utf_16_ex_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int byteorder, int final); + +static PyObject * +_codecs_utf_16_ex_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int byteorder = 0; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zii:utf_16_ex_decode", + &data, &errors, &byteorder, &final)) + goto exit; + return_value = _codecs_utf_16_ex_decode_impl(module, &data, errors, byteorder, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_decode__doc__, +"utf_32_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_DECODE_METHODDEF \ + {"utf_32_decode", (PyCFunction)_codecs_utf_32_decode, METH_VARARGS, _codecs_utf_32_decode__doc__}, + +static PyObject * +_codecs_utf_32_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_32_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_32_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_32_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_le_decode__doc__, +"utf_32_le_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_LE_DECODE_METHODDEF \ + {"utf_32_le_decode", (PyCFunction)_codecs_utf_32_le_decode, METH_VARARGS, _codecs_utf_32_le_decode__doc__}, + +static PyObject * +_codecs_utf_32_le_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_32_le_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_32_le_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_32_le_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_be_decode__doc__, +"utf_32_be_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_BE_DECODE_METHODDEF \ + {"utf_32_be_decode", (PyCFunction)_codecs_utf_32_be_decode, METH_VARARGS, _codecs_utf_32_be_decode__doc__}, + +static PyObject * +_codecs_utf_32_be_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_utf_32_be_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:utf_32_be_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_utf_32_be_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_ex_decode__doc__, +"utf_32_ex_decode($module, data, errors=None, byteorder=0, final=False,\n" +" /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_EX_DECODE_METHODDEF \ + {"utf_32_ex_decode", (PyCFunction)_codecs_utf_32_ex_decode, METH_VARARGS, _codecs_utf_32_ex_decode__doc__}, + +static PyObject * +_codecs_utf_32_ex_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int byteorder, int final); + +static PyObject * +_codecs_utf_32_ex_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int byteorder = 0; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zii:utf_32_ex_decode", + &data, &errors, &byteorder, &final)) + goto exit; + return_value = _codecs_utf_32_ex_decode_impl(module, &data, errors, byteorder, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_unicode_escape_decode__doc__, +"unicode_escape_decode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UNICODE_ESCAPE_DECODE_METHODDEF \ + {"unicode_escape_decode", (PyCFunction)_codecs_unicode_escape_decode, METH_VARARGS, _codecs_unicode_escape_decode__doc__}, + +static PyObject * +_codecs_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors); + +static PyObject * +_codecs_unicode_escape_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "s*|z:unicode_escape_decode", + &data, &errors)) + goto exit; + return_value = _codecs_unicode_escape_decode_impl(module, &data, errors); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_raw_unicode_escape_decode__doc__, +"raw_unicode_escape_decode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_RAW_UNICODE_ESCAPE_DECODE_METHODDEF \ + {"raw_unicode_escape_decode", (PyCFunction)_codecs_raw_unicode_escape_decode, METH_VARARGS, _codecs_raw_unicode_escape_decode__doc__}, + +static PyObject * +_codecs_raw_unicode_escape_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors); + +static PyObject * +_codecs_raw_unicode_escape_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "s*|z:raw_unicode_escape_decode", + &data, &errors)) + goto exit; + return_value = _codecs_raw_unicode_escape_decode_impl(module, &data, errors); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_latin_1_decode__doc__, +"latin_1_decode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_LATIN_1_DECODE_METHODDEF \ + {"latin_1_decode", (PyCFunction)_codecs_latin_1_decode, METH_VARARGS, _codecs_latin_1_decode__doc__}, + +static PyObject * +_codecs_latin_1_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors); + +static PyObject * +_codecs_latin_1_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "y*|z:latin_1_decode", + &data, &errors)) + goto exit; + return_value = _codecs_latin_1_decode_impl(module, &data, errors); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_ascii_decode__doc__, +"ascii_decode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_ASCII_DECODE_METHODDEF \ + {"ascii_decode", (PyCFunction)_codecs_ascii_decode, METH_VARARGS, _codecs_ascii_decode__doc__}, + +static PyObject * +_codecs_ascii_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors); + +static PyObject * +_codecs_ascii_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "y*|z:ascii_decode", + &data, &errors)) + goto exit; + return_value = _codecs_ascii_decode_impl(module, &data, errors); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_charmap_decode__doc__, +"charmap_decode($module, data, errors=None, mapping=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_CHARMAP_DECODE_METHODDEF \ + {"charmap_decode", (PyCFunction)_codecs_charmap_decode, METH_VARARGS, _codecs_charmap_decode__doc__}, + +static PyObject * +_codecs_charmap_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, PyObject *mapping); + +static PyObject * +_codecs_charmap_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + PyObject *mapping = NULL; + + if (!PyArg_ParseTuple(args, "y*|zO:charmap_decode", + &data, &errors, &mapping)) + goto exit; + return_value = _codecs_charmap_decode_impl(module, &data, errors, mapping); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +#if defined(HAVE_MBCS) + +PyDoc_STRVAR(_codecs_mbcs_decode__doc__, +"mbcs_decode($module, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_MBCS_DECODE_METHODDEF \ + {"mbcs_decode", (PyCFunction)_codecs_mbcs_decode, METH_VARARGS, _codecs_mbcs_decode__doc__}, + +static PyObject * +_codecs_mbcs_decode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors, int final); + +static PyObject * +_codecs_mbcs_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "y*|zi:mbcs_decode", + &data, &errors, &final)) + goto exit; + return_value = _codecs_mbcs_decode_impl(module, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +#endif /* defined(HAVE_MBCS) */ + +#if defined(HAVE_MBCS) + +PyDoc_STRVAR(_codecs_code_page_decode__doc__, +"code_page_decode($module, codepage, data, errors=None, final=False, /)\n" +"--\n" +"\n"); + +#define _CODECS_CODE_PAGE_DECODE_METHODDEF \ + {"code_page_decode", (PyCFunction)_codecs_code_page_decode, METH_VARARGS, _codecs_code_page_decode__doc__}, + +static PyObject * +_codecs_code_page_decode_impl(PyModuleDef *module, int codepage, + Py_buffer *data, const char *errors, int final); + +static PyObject * +_codecs_code_page_decode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int codepage; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + int final = 0; + + if (!PyArg_ParseTuple(args, "iy*|zi:code_page_decode", + &codepage, &data, &errors, &final)) + goto exit; + return_value = _codecs_code_page_decode_impl(module, codepage, &data, errors, final); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +#endif /* defined(HAVE_MBCS) */ + +PyDoc_STRVAR(_codecs_readbuffer_encode__doc__, +"readbuffer_encode($module, data, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_READBUFFER_ENCODE_METHODDEF \ + {"readbuffer_encode", (PyCFunction)_codecs_readbuffer_encode, METH_VARARGS, _codecs_readbuffer_encode__doc__}, + +static PyObject * +_codecs_readbuffer_encode_impl(PyModuleDef *module, Py_buffer *data, + const char *errors); + +static PyObject * +_codecs_readbuffer_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + Py_buffer data = {NULL, NULL}; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "s*|z:readbuffer_encode", + &data, &errors)) + goto exit; + return_value = _codecs_readbuffer_encode_impl(module, &data, errors); + +exit: + /* Cleanup for data */ + if (data.obj) + PyBuffer_Release(&data); + + return return_value; +} + +PyDoc_STRVAR(_codecs_unicode_internal_encode__doc__, +"unicode_internal_encode($module, obj, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UNICODE_INTERNAL_ENCODE_METHODDEF \ + {"unicode_internal_encode", (PyCFunction)_codecs_unicode_internal_encode, METH_VARARGS, _codecs_unicode_internal_encode__doc__}, + +static PyObject * +_codecs_unicode_internal_encode_impl(PyModuleDef *module, PyObject *obj, + const char *errors); + +static PyObject * +_codecs_unicode_internal_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *obj; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:unicode_internal_encode", + &obj, &errors)) + goto exit; + return_value = _codecs_unicode_internal_encode_impl(module, obj, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_7_encode__doc__, +"utf_7_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_7_ENCODE_METHODDEF \ + {"utf_7_encode", (PyCFunction)_codecs_utf_7_encode, METH_VARARGS, _codecs_utf_7_encode__doc__}, + +static PyObject * +_codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_utf_7_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:utf_7_encode", + &str, &errors)) + goto exit; + return_value = _codecs_utf_7_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_8_encode__doc__, +"utf_8_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_8_ENCODE_METHODDEF \ + {"utf_8_encode", (PyCFunction)_codecs_utf_8_encode, METH_VARARGS, _codecs_utf_8_encode__doc__}, + +static PyObject * +_codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_utf_8_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:utf_8_encode", + &str, &errors)) + goto exit; + return_value = _codecs_utf_8_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_encode__doc__, +"utf_16_encode($module, str, errors=None, byteorder=0, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_ENCODE_METHODDEF \ + {"utf_16_encode", (PyCFunction)_codecs_utf_16_encode, METH_VARARGS, _codecs_utf_16_encode__doc__}, + +static PyObject * +_codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors, int byteorder); + +static PyObject * +_codecs_utf_16_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + int byteorder = 0; + + if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode", + &str, &errors, &byteorder)) + goto exit; + return_value = _codecs_utf_16_encode_impl(module, str, errors, byteorder); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_le_encode__doc__, +"utf_16_le_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_LE_ENCODE_METHODDEF \ + {"utf_16_le_encode", (PyCFunction)_codecs_utf_16_le_encode, METH_VARARGS, _codecs_utf_16_le_encode__doc__}, + +static PyObject * +_codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_utf_16_le_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode", + &str, &errors)) + goto exit; + return_value = _codecs_utf_16_le_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_16_be_encode__doc__, +"utf_16_be_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_16_BE_ENCODE_METHODDEF \ + {"utf_16_be_encode", (PyCFunction)_codecs_utf_16_be_encode, METH_VARARGS, _codecs_utf_16_be_encode__doc__}, + +static PyObject * +_codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_utf_16_be_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode", + &str, &errors)) + goto exit; + return_value = _codecs_utf_16_be_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_encode__doc__, +"utf_32_encode($module, str, errors=None, byteorder=0, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_ENCODE_METHODDEF \ + {"utf_32_encode", (PyCFunction)_codecs_utf_32_encode, METH_VARARGS, _codecs_utf_32_encode__doc__}, + +static PyObject * +_codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors, int byteorder); + +static PyObject * +_codecs_utf_32_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + int byteorder = 0; + + if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode", + &str, &errors, &byteorder)) + goto exit; + return_value = _codecs_utf_32_encode_impl(module, str, errors, byteorder); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_le_encode__doc__, +"utf_32_le_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_LE_ENCODE_METHODDEF \ + {"utf_32_le_encode", (PyCFunction)_codecs_utf_32_le_encode, METH_VARARGS, _codecs_utf_32_le_encode__doc__}, + +static PyObject * +_codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_utf_32_le_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode", + &str, &errors)) + goto exit; + return_value = _codecs_utf_32_le_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_utf_32_be_encode__doc__, +"utf_32_be_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UTF_32_BE_ENCODE_METHODDEF \ + {"utf_32_be_encode", (PyCFunction)_codecs_utf_32_be_encode, METH_VARARGS, _codecs_utf_32_be_encode__doc__}, + +static PyObject * +_codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_utf_32_be_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode", + &str, &errors)) + goto exit; + return_value = _codecs_utf_32_be_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_unicode_escape_encode__doc__, +"unicode_escape_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_UNICODE_ESCAPE_ENCODE_METHODDEF \ + {"unicode_escape_encode", (PyCFunction)_codecs_unicode_escape_encode, METH_VARARGS, _codecs_unicode_escape_encode__doc__}, + +static PyObject * +_codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_unicode_escape_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode", + &str, &errors)) + goto exit; + return_value = _codecs_unicode_escape_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_raw_unicode_escape_encode__doc__, +"raw_unicode_escape_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_RAW_UNICODE_ESCAPE_ENCODE_METHODDEF \ + {"raw_unicode_escape_encode", (PyCFunction)_codecs_raw_unicode_escape_encode, METH_VARARGS, _codecs_raw_unicode_escape_encode__doc__}, + +static PyObject * +_codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_raw_unicode_escape_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode", + &str, &errors)) + goto exit; + return_value = _codecs_raw_unicode_escape_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_latin_1_encode__doc__, +"latin_1_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_LATIN_1_ENCODE_METHODDEF \ + {"latin_1_encode", (PyCFunction)_codecs_latin_1_encode, METH_VARARGS, _codecs_latin_1_encode__doc__}, + +static PyObject * +_codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_latin_1_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:latin_1_encode", + &str, &errors)) + goto exit; + return_value = _codecs_latin_1_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_ascii_encode__doc__, +"ascii_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_ASCII_ENCODE_METHODDEF \ + {"ascii_encode", (PyCFunction)_codecs_ascii_encode, METH_VARARGS, _codecs_ascii_encode__doc__}, + +static PyObject * +_codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_ascii_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:ascii_encode", + &str, &errors)) + goto exit; + return_value = _codecs_ascii_encode_impl(module, str, errors); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_charmap_encode__doc__, +"charmap_encode($module, str, errors=None, mapping=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_CHARMAP_ENCODE_METHODDEF \ + {"charmap_encode", (PyCFunction)_codecs_charmap_encode, METH_VARARGS, _codecs_charmap_encode__doc__}, + +static PyObject * +_codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors, PyObject *mapping); + +static PyObject * +_codecs_charmap_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + PyObject *mapping = NULL; + + if (!PyArg_ParseTuple(args, "O|zO:charmap_encode", + &str, &errors, &mapping)) + goto exit; + return_value = _codecs_charmap_encode_impl(module, str, errors, mapping); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_charmap_build__doc__, +"charmap_build($module, map, /)\n" +"--\n" +"\n"); + +#define _CODECS_CHARMAP_BUILD_METHODDEF \ + {"charmap_build", (PyCFunction)_codecs_charmap_build, METH_O, _codecs_charmap_build__doc__}, + +static PyObject * +_codecs_charmap_build_impl(PyModuleDef *module, PyObject *map); + +static PyObject * +_codecs_charmap_build(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + PyObject *map; + + if (!PyArg_Parse(arg, "U:charmap_build", &map)) + goto exit; + return_value = _codecs_charmap_build_impl(module, map); + +exit: + return return_value; +} + +#if defined(HAVE_MBCS) + +PyDoc_STRVAR(_codecs_mbcs_encode__doc__, +"mbcs_encode($module, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_MBCS_ENCODE_METHODDEF \ + {"mbcs_encode", (PyCFunction)_codecs_mbcs_encode, METH_VARARGS, _codecs_mbcs_encode__doc__}, + +static PyObject * +_codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str, + const char *errors); + +static PyObject * +_codecs_mbcs_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "O|z:mbcs_encode", + &str, &errors)) + goto exit; + return_value = _codecs_mbcs_encode_impl(module, str, errors); + +exit: + return return_value; +} + +#endif /* defined(HAVE_MBCS) */ + +#if defined(HAVE_MBCS) + +PyDoc_STRVAR(_codecs_code_page_encode__doc__, +"code_page_encode($module, code_page, str, errors=None, /)\n" +"--\n" +"\n"); + +#define _CODECS_CODE_PAGE_ENCODE_METHODDEF \ + {"code_page_encode", (PyCFunction)_codecs_code_page_encode, METH_VARARGS, _codecs_code_page_encode__doc__}, + +static PyObject * +_codecs_code_page_encode_impl(PyModuleDef *module, int code_page, + PyObject *str, const char *errors); + +static PyObject * +_codecs_code_page_encode(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + int code_page; + PyObject *str; + const char *errors = NULL; + + if (!PyArg_ParseTuple(args, "iO|z:code_page_encode", + &code_page, &str, &errors)) + goto exit; + return_value = _codecs_code_page_encode_impl(module, code_page, str, errors); + +exit: + return return_value; +} + +#endif /* defined(HAVE_MBCS) */ + +PyDoc_STRVAR(_codecs_register_error__doc__, +"register_error($module, errors, handler, /)\n" +"--\n" +"\n" +"Register the specified error handler under the name errors.\n" +"\n" +"handler must be a callable object, that will be called with an exception\n" +"instance containing information about the location of the encoding/decoding\n" +"error and must return a (replacement, new position) tuple."); + +#define _CODECS_REGISTER_ERROR_METHODDEF \ + {"register_error", (PyCFunction)_codecs_register_error, METH_VARARGS, _codecs_register_error__doc__}, + +static PyObject * +_codecs_register_error_impl(PyModuleDef *module, const char *errors, + PyObject *handler); + +static PyObject * +_codecs_register_error(PyModuleDef *module, PyObject *args) +{ + PyObject *return_value = NULL; + const char *errors; + PyObject *handler; + + if (!PyArg_ParseTuple(args, "sO:register_error", + &errors, &handler)) + goto exit; + return_value = _codecs_register_error_impl(module, errors, handler); + +exit: + return return_value; +} + +PyDoc_STRVAR(_codecs_lookup_error__doc__, +"lookup_error($module, name, /)\n" +"--\n" +"\n" +"lookup_error(errors) -> handler\n" +"\n" +"Return the error handler for the specified error handling name or raise a\n" +"LookupError, if no handler exists under this name."); + +#define _CODECS_LOOKUP_ERROR_METHODDEF \ + {"lookup_error", (PyCFunction)_codecs_lookup_error, METH_O, _codecs_lookup_error__doc__}, + +static PyObject * +_codecs_lookup_error_impl(PyModuleDef *module, const char *name); + +static PyObject * +_codecs_lookup_error(PyModuleDef *module, PyObject *arg) +{ + PyObject *return_value = NULL; + const char *name; + + if (!PyArg_Parse(arg, "s:lookup_error", &name)) + goto exit; + return_value = _codecs_lookup_error_impl(module, name); + +exit: + return return_value; +} + +#ifndef _CODECS_MBCS_DECODE_METHODDEF + #define _CODECS_MBCS_DECODE_METHODDEF +#endif /* !defined(_CODECS_MBCS_DECODE_METHODDEF) */ + +#ifndef _CODECS_CODE_PAGE_DECODE_METHODDEF + #define _CODECS_CODE_PAGE_DECODE_METHODDEF +#endif /* !defined(_CODECS_CODE_PAGE_DECODE_METHODDEF) */ + +#ifndef _CODECS_MBCS_ENCODE_METHODDEF + #define _CODECS_MBCS_ENCODE_METHODDEF +#endif /* !defined(_CODECS_MBCS_ENCODE_METHODDEF) */ + +#ifndef _CODECS_CODE_PAGE_ENCODE_METHODDEF + #define _CODECS_CODE_PAGE_ENCODE_METHODDEF +#endif /* !defined(_CODECS_CODE_PAGE_ENCODE_METHODDEF) */ +/*[clinic end generated code: output=713a4081788da1bc input=a9049054013a1b77]*/