summaryrefslogtreecommitdiffstats
path: root/Modules/_codecsmodule.c
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-05-12 10:15:57 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-05-12 10:15:57 (GMT)
commit0c59ff64304aeb8a415f098406e6033bc3fed7b4 (patch)
treee2b1cb61607caf5a5613500e024effa1f9f9e95e /Modules/_codecsmodule.c
parent5096088c073142e6c359b438c863a390f4fae3b8 (diff)
downloadcpython-0c59ff64304aeb8a415f098406e6033bc3fed7b4.zip
cpython-0c59ff64304aeb8a415f098406e6033bc3fed7b4.tar.gz
cpython-0c59ff64304aeb8a415f098406e6033bc3fed7b4.tar.bz2
Issue #20173: Converted the _codecs module to Argument Clinic.
Diffstat (limited to 'Modules/_codecsmodule.c')
-rw-r--r--Modules/_codecsmodule.c1244
1 files changed, 629 insertions, 615 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index d8b4bbd..0e90f3c 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.");
-
-static
-PyObject *codec_lookup(PyObject *self, PyObject *args)
-{
- char *encoding;
+/*[clinic input]
+_codecs.lookup
+ encoding: str
+ /
- if (!PyArg_ParseTuple(args, "s:lookup", &encoding))
- return NULL;
+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]*/
+{
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 ------------------------------------------------------ */
+/*[clinic input]
+_codecs.escape_decode
+ data: Py_buffer(accept={str, buffer})
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-escape_decode(PyObject *self,
- PyObject *args)
+_codecs_escape_decode_impl(PyModuleDef *module, Py_buffer *data,
+ const char *errors)
+/*[clinic end generated code: output=648fa3e78d03e658 input=0018edfd99db714d]*/
{
- Py_buffer pbuf;
- const char *errors = NULL;
- PyObject *result;
-
- 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;
+ 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)
+ PyObject *decoded = PyUnicode_DecodeUTF16Stateful(data->buf, data->len,
+ errors, &byteorder,
+ final ? NULL : &consumed);
+ if (decoded == 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.utf_32_decode
+ data: Py_buffer
+ errors: str(accept={str, NoneType}) = NULL
+ final: int(c_default="0") = False
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_32_decode(PyObject *self,
- PyObject *args)
+_codecs_utf_32_decode_impl(PyModuleDef *module, Py_buffer *data,
+ const char *errors, int final)
+/*[clinic end generated code: output=b7635e55857e8efb input=86d4f41c6c2e763d]*/
{
- 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);
- 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);
}
+/*[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);
}
+/*[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]*/
+
static PyObject *
-utf_32_be_decode(PyObject *self,
- PyObject *args)
+_codecs_utf_32_be_decode_impl(PyModuleDef *module, Py_buffer *data,
+ const char *errors, int final)
+/*[clinic end generated code: output=a8356b0f36779981 input=19c271b5d34926d8]*/
{
- 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_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;
+ /* 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))
- 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)
+ Py_ssize_t consumed = data->len;
+ PyObject *decoded = PyUnicode_DecodeUTF32Stateful(data->buf, data->len,
+ errors, &byteorder,
+ final ? NULL : &consumed);
+ if (decoded == 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);
}
+/*[clinic input]
+_codecs.charmap_decode
+ data: Py_buffer
+ errors: str(accept={str, NoneType}) = NULL
+ mapping: object = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-charmap_decode(PyObject *self,
- PyObject *args)
+_codecs_charmap_decode_impl(PyModuleDef *module, Py_buffer *data,
+ const char *errors, PyObject *mapping)
+/*[clinic end generated code: output=87d27f365098bbae input=19712ca35c5a80e2]*/
{
- Py_buffer pbuf;
- PyObject *unicode;
- const char *errors = NULL;
- PyObject *mapping = NULL;
+ 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);
}
+/*[clinic input]
+_codecs.unicode_internal_encode
+ obj: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-unicode_internal_encode(PyObject *self,
- PyObject *args)
+_codecs_unicode_internal_encode_impl(PyModuleDef *module, PyObject *obj,
+ const char *errors)
+/*[clinic end generated code: output=be08457068ad503b input=8628f0280cf5ba61]*/
{
- PyObject *obj;
- const char *errors = NULL;
-
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;
}
}
+/*[clinic input]
+_codecs.utf_7_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_7_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_7_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=a7accc496a32b759 input=fd91a78f103b0421]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:utf_7_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -769,16 +741,19 @@ utf_7_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.utf_8_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_8_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_8_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=ec831d80e7aedede input=2c22d40532f071f3]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:utf_8_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -798,17 +773,20 @@ utf_8_encode(PyObject *self,
*/
+/*[clinic input]
+_codecs.utf_16_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ byteorder: int = 0
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_16_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_16_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors, int byteorder)
+/*[clinic end generated code: output=93ac58e960a9ee4d input=3935a489b2d5385e]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
- int byteorder = 0;
-
- if (!PyArg_ParseTuple(args, "O|zi:utf_16_encode",
- &str, &errors, &byteorder))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -821,16 +799,19 @@ utf_16_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.utf_16_le_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_16_le_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_16_le_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=422bedb8da34fb66 input=bc27df05d1d20dfe]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:utf_16_le_encode",
- &str, &errors))
- return NULL;
+ 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;
}
+/*[clinic input]
+_codecs.utf_16_be_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_16_be_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_16_be_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=3aa7ee9502acdd77 input=5a69d4112763462b]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:utf_16_be_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -872,17 +856,20 @@ utf_16_be_encode(PyObject *self,
*/
+/*[clinic input]
+_codecs.utf_32_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ byteorder: int = 0
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_32_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_32_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors, int byteorder)
+/*[clinic end generated code: output=3e7d5a003b02baed input=434a1efa492b8d58]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
- int byteorder = 0;
-
- if (!PyArg_ParseTuple(args, "O|zi:utf_32_encode",
- &str, &errors, &byteorder))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -895,16 +882,19 @@ utf_32_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.utf_32_le_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_32_le_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_32_le_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=5dda641cd33dbfc2 input=dfa2d7dc78b99422]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:utf_32_le_encode",
- &str, &errors))
- return NULL;
+ 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;
}
+/*[clinic input]
+_codecs.utf_32_be_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-utf_32_be_encode(PyObject *self,
- PyObject *args)
+_codecs_utf_32_be_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=ccca8b44d91a7c7a input=4595617b18169002]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:utf_32_be_encode",
- &str, &errors))
- return NULL;
+ 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;
}
+/*[clinic input]
+_codecs.unicode_escape_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-unicode_escape_encode(PyObject *self,
- PyObject *args)
+_codecs_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=389f23d2b8f8d80b input=8273506f14076912]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:unicode_escape_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -961,16 +957,19 @@ unicode_escape_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.raw_unicode_escape_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-raw_unicode_escape_encode(PyObject *self,
- PyObject *args)
+_codecs_raw_unicode_escape_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=fec4e39d6ec37a62 input=181755d5dfacef3c]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:raw_unicode_escape_encode",
- &str, &errors))
- return NULL;
+ 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;
}
+/*[clinic input]
+_codecs.latin_1_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-latin_1_encode(PyObject *self,
- PyObject *args)
+_codecs_latin_1_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=ecf00eb8e48c889c input=f03f6dcf1d84bee4]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:latin_1_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -1005,16 +1007,19 @@ latin_1_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.ascii_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-ascii_encode(PyObject *self,
- PyObject *args)
+_codecs_ascii_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=a9d18fc6b6b91cfb input=d87e25a10a593fee]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:ascii_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -1027,17 +1032,21 @@ ascii_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.charmap_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ mapping: object = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-charmap_encode(PyObject *self,
- PyObject *args)
+_codecs_charmap_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors, PyObject *mapping)
+/*[clinic end generated code: output=14ca42b83853c643 input=85f4172661e8dad9]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
- PyObject *mapping = NULL;
+ 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
+/*[clinic input]
+_codecs.mbcs_encode
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-mbcs_encode(PyObject *self,
- PyObject *args)
+_codecs_mbcs_encode_impl(PyModuleDef *module, PyObject *str,
+ const char *errors)
+/*[clinic end generated code: output=d1a013bc68798bd7 input=65c09ee1e4203263]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
-
- if (!PyArg_ParseTuple(args, "O|z:mbcs_encode",
- &str, &errors))
- return NULL;
+ PyObject *v;
str = PyUnicode_FromObject(str);
if (str == NULL || PyUnicode_READY(str) < 0) {
@@ -1085,17 +1101,20 @@ mbcs_encode(PyObject *self,
return v;
}
+/*[clinic input]
+_codecs.code_page_encode
+ code_page: int
+ str: object
+ errors: str(accept={str, NoneType}) = NULL
+ /
+[clinic start generated code]*/
+
static PyObject *
-code_page_encode(PyObject *self,
- PyObject *args)
+_codecs_code_page_encode_impl(PyModuleDef *module, int code_page,
+ PyObject *str, const char *errors)
+/*[clinic end generated code: output=3b406618dbfbce25 input=c8562ec460c2e309]*/
{
- PyObject *str, *v;
- const char *errors = NULL;
- int code_page;
-
- if (!PyArg_ParseTuple(args, "iO|z:code_page_encode",
- &code_page, &str, &errors))
- return NULL;
+ 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)
-{
- const char *name;
- PyObject *handler;
+Register the specified error handler under the name errors.
- if (!PyArg_ParseTuple(args, "sO:register_error",
- &name, &handler))
- return NULL;
- if (PyCodec_RegisterError(name, handler))
+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]*/
+{
+ 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)
-{
- const char *name;
+lookup_error(errors) -> handler
- if (!PyArg_ParseTuple(args, "s:lookup_error",
- &name))
- return NULL;
+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]*/
+{
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 */
};