diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-05-14 15:10:45 (GMT) |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-05-14 15:10:45 (GMT) |
commit | b78c448f4bad3afee409129337709e5fb110e5f3 (patch) | |
tree | 5360eae15e4d6e89c36ddc55df068fd80c2c5f38 /Modules | |
parent | ef5b4e3dc3b04327514d2e1704a8c8cd822d8beb (diff) | |
download | cpython-b78c448f4bad3afee409129337709e5fb110e5f3.zip cpython-b78c448f4bad3afee409129337709e5fb110e5f3.tar.gz cpython-b78c448f4bad3afee409129337709e5fb110e5f3.tar.bz2 |
Issue #21488: Add support of keyword arguments for codecs.encode and codecs.decode
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_codecsmodule.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/Modules/_codecsmodule.c b/Modules/_codecsmodule.c index 0b093ab..1b21300 100644 --- a/Modules/_codecsmodule.c +++ b/Modules/_codecsmodule.c @@ -89,13 +89,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) @@ -116,13 +118,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) @@ -1120,9 +1124,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}, |