summaryrefslogtreecommitdiffstats
path: root/Modules/_codecsmodule.c
diff options
context:
space:
mode:
Diffstat (limited to 'Modules/_codecsmodule.c')
-rw-r--r--Modules/_codecsmodule.c64
1 files changed, 22 insertions, 42 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c
index 52f3479..d8b4bbd 100644
--- a/Modules/_codecsmodule.c
+++ b/Modules/_codecsmodule.c
@@ -47,6 +47,7 @@ module _codecs
[clinic start generated code]*/
/*[clinic end generated code: output=da39a3ee5e6b4b0d input=e1390e3da3cb9deb]*/
+#include "clinic/_codecsmodule.c.h"
/* --- Registry ----------------------------------------------------------- */
@@ -95,13 +96,15 @@ a ValueError. Other possible values are 'ignore', 'replace' and\n\
codecs.register_error that can handle ValueErrors.");
static PyObject *
-codec_encode(PyObject *self, PyObject *args)
+codec_encode(PyObject *self, PyObject *args, PyObject *kwargs)
{
+ static char *kwlist[] = {"obj", "encoding", "errors", NULL};
const char *encoding = NULL;
const char *errors = NULL;
PyObject *v;
- if (!PyArg_ParseTuple(args, "O|ss:encode", &v, &encoding, &errors))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:encode", kwlist,
+ &v, &encoding, &errors))
return NULL;
if (encoding == NULL)
@@ -122,13 +125,15 @@ as well as any other name registered with codecs.register_error that is\n\
able to handle ValueErrors.");
static PyObject *
-codec_decode(PyObject *self, PyObject *args)
+codec_decode(PyObject *self, PyObject *args, PyObject *kwargs)
{
+ static char *kwlist[] = {"obj", "encoding", "errors", NULL};
const char *encoding = NULL;
const char *errors = NULL;
PyObject *v;
- if (!PyArg_ParseTuple(args, "O|ss:decode", &v, &encoding, &errors))
+ if (!PyArg_ParseTupleAndKeywords(args, kwargs, "O|ss:decode", kwlist,
+ &v, &encoding, &errors))
return NULL;
if (encoding == NULL)
@@ -149,37 +154,9 @@ _codecs._forget_codec
Purge the named codec from the internal codec lookup cache
[clinic start generated code]*/
-PyDoc_STRVAR(_codecs__forget_codec__doc__,
-"_forget_codec($module, encoding, /)\n"
-"--\n"
-"\n"
-"Purge the named codec from the internal codec lookup cache");
-
-#define _CODECS__FORGET_CODEC_METHODDEF \
- {"_forget_codec", (PyCFunction)_codecs__forget_codec, METH_VARARGS, _codecs__forget_codec__doc__},
-
-static PyObject *
-_codecs__forget_codec_impl(PyModuleDef *module, const char *encoding);
-
-static PyObject *
-_codecs__forget_codec(PyModuleDef *module, PyObject *args)
-{
- PyObject *return_value = NULL;
- const char *encoding;
-
- if (!PyArg_ParseTuple(args,
- "s:_forget_codec",
- &encoding))
- goto exit;
- return_value = _codecs__forget_codec_impl(module, encoding);
-
-exit:
- return return_value;
-}
-
static PyObject *
_codecs__forget_codec_impl(PyModuleDef *module, const char *encoding)
-/*[clinic end generated code: output=a75e631591702a5c input=18d5d92d0e386c38]*/
+/*[clinic end generated code: output=b56a9b99d2d28080 input=18d5d92d0e386c38]*/
{
if (_PyCodec_Forget(encoding) < 0) {
return NULL;
@@ -204,15 +181,18 @@ static PyObject *
escape_decode(PyObject *self,
PyObject *args)
{
+ Py_buffer pbuf;
const char *errors = NULL;
- const char *data;
- Py_ssize_t size;
+ PyObject *result;
- if (!PyArg_ParseTuple(args, "s#|z:escape_decode",
- &data, &size, &errors))
+ if (!PyArg_ParseTuple(args, "s*|z:escape_decode",
+ &pbuf, &errors))
return NULL;
- return codec_tuple(PyBytes_DecodeEscape(data, size, errors, 0, NULL),
- size);
+ result = codec_tuple(
+ PyBytes_DecodeEscape(pbuf.buf, pbuf.len, errors, 0, NULL),
+ pbuf.len);
+ PyBuffer_Release(&pbuf);
+ return result;
}
static PyObject *
@@ -750,7 +730,7 @@ unicode_internal_encode(PyObject *self,
u = PyUnicode_AsUnicodeAndSize(obj, &len);
if (u == NULL)
return NULL;
- if (len > PY_SSIZE_T_MAX / sizeof(Py_UNICODE))
+ if ((size_t)len > (size_t)PY_SSIZE_T_MAX / sizeof(Py_UNICODE))
return PyErr_NoMemory();
size = len * sizeof(Py_UNICODE);
return codec_tuple(PyBytes_FromStringAndSize((const char*)u, size),
@@ -1179,9 +1159,9 @@ static PyMethodDef _codecs_functions[] = {
register__doc__},
{"lookup", codec_lookup, METH_VARARGS,
lookup__doc__},
- {"encode", codec_encode, METH_VARARGS,
+ {"encode", (PyCFunction)codec_encode, METH_VARARGS|METH_KEYWORDS,
encode__doc__},
- {"decode", codec_decode, METH_VARARGS,
+ {"decode", (PyCFunction)codec_decode, METH_VARARGS|METH_KEYWORDS,
decode__doc__},
{"escape_encode", escape_encode, METH_VARARGS},
{"escape_decode", escape_decode, METH_VARARGS},