Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(1)

Unified Diff: Modules/_codecsmodule.c

Issue 20173: Derby #4: Convert 53 sites to Argument Clinic across 5 files
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Modules/clinic/_codecsmodule.c.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Modules/_codecsmodule.c Thu Apr 16 11:58:11 2015 +0300
+++ b/Modules/_codecsmodule.c Thu Apr 16 18:43:49 2015 +0300
@@ -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,
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") = "utf-8"
+ 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 'xmlcharrefreplace' 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=cb1f62cf8d9e2a2c]*/
{
- 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") = "utf-8"
larry 2015/04/16 23:37:04 If #23967 is accepted, the Python default should b
storchaka 2015/04/17 19:34:04 It is always "utf-8" in Python 3. sys.getdefaulten
larry 2015/04/22 07:17:32 sys.getdefaultencoding() is not deprecated in the
storchaka 2015/04/23 12:07:32 PyUnicode_GetDefaultEncoding() just returns "utf-8
+ 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' and 'replace'
+as well as any other name registered with codecs.register_error that is able
+to 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=9d04293156021886]*/
{
- 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 @@ static PyObject *
}
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(types={'str', 'buffer'})
+ errors: str(nullable=True) = 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=f373087451274bbb]*/
{
- 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')
larry 2015/04/16 23:37:04 Isn't this exactly the same as the PyBytesObject c
storchaka 2015/04/17 19:34:04 Indeed. And there are similar misuses of the "O!"
+ errors: str(nullable=True) = 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=995ec13d87247ec7]*/
{
- 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(nullable=True) = 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=71d1d53c6ea4f0fc]*/
{
- 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(nullable=True) = 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=8fd0241dcc559fe8]*/
{
- 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(nullable=True) = 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=709f25fbc3cd9a3e]*/
{
- 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(nullable=True) = 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=81678c8535585915]*/
{
- 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(nullable=True) = 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=006e53be083b6777]*/
{
- 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(nullable=True) = 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=d9490ad0f74140f3]*/
{
- 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(nullable=True) = NULL
+ byteorder: int = 0
+ final: int(c_default="0") = False
larry 2015/04/16 23:37:04 bool?
storchaka 2015/04/17 19:34:04 Semantically this is bool, but old code (here and
larry 2015/04/22 07:17:32 The only difference between "bool" (format unit 'p
storchaka 2015/04/23 12:07:32 The downside of bool converter is that it is harde
+ /
+[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=56a16c35944e4668]*/
{
- 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))
+ PyObject *decoded = PyUnicode_DecodeUTF16Stateful(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_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;
+ return Py_BuildValue("Nni", decoded, consumed, byteorder);
}
+/*[clinic input]
+_codecs.utf_32_decode
+ data: Py_buffer
+ errors: str(nullable=True) = 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=778f09d112c84716]*/
{
- 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(nullable=True) = 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=7a398c6cadca231f]*/
{
- 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(nullable=True) = 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=573fb3c3b8ac000d]*/
{
- 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(nullable=True) = 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=56c2fd15274e69a0]*/
{
- 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(types={'str', 'buffer'})
+ errors: str(nullable=True) = 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=80f2ff60014d65c4]*/
{
- 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(types={'str', 'buffer'})
+ errors: str(nullable=True) = 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=ef77c7ab98ee2c60]*/
{
- 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(nullable=True) = 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=2ad8439a94444119]*/
{
- 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(nullable=True) = 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=0bfd2dd60e3e0152]*/
{
- 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(nullable=True) = 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=bf5ab0388adeac8e]*/
{
- 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(nullable=True) = 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=48841d508b7bacee]*/
{
- 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(nullable=True) = 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=74f589867f3429ce]*/
{
- 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(types={'str', 'buffer'})
+ errors: str(nullable=True) = 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=fc35dc93718e670d]*/
{
- 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(nullable=True) = 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=61192dad1fce371f]*/
{
- 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(nullable=True) = 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=802ba3f495219bbc]*/
{
- 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(nullable=True) = 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=5c283859a2a90bf7]*/
{
- 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(nullable=True) = 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=ed850025591019db]*/
{
- 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(nullable=True) = 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=950fcf919f117cb7]*/
{
- 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(nullable=True) = 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=65a55a23d2a1e18d]*/
{
- 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(nullable=True) = 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=452ef1b8f0b8c3d5]*/
{
- 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(nullable=True) = 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=a8e2cc9b4dbf40d9]*/
{
- 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(nullable=True) = 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=cef51fb9de6a04b3]*/
{
- 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(nullable=True) = 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=a9b4d66329b51e5b]*/
{
- 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(nullable=True) = 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=022a856c6bbac275]*/
{
- 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(nullable=True) = 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=e2ec958e195e3f30]*/
{
- 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(nullable=True) = 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=536afe3b176f737b]*/
{
- 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(nullable=True) = 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=6cfea1a4be31cde1]*/
{
- 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(nullable=True) = 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=30a1cf44d9315ec9]*/
{
- 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(nullable=True) = 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=b0c72790c2e2ce28]*/
{
- 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)
+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 */
};
« no previous file with comments | « Modules/clinic/_codecsmodule.c.h ('k') | no next file » | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+