diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-09-18 21:42:35 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-09-18 21:42:35 (GMT) |
commit | 308d637c94b9ed88c386b83891ad38b2131ebd12 (patch) | |
tree | da0e7c3d9999e3c0a3dbc02fb4be7fbffba5ed7e /Objects | |
parent | 7a4e5866f70ccbb76dae6e0139f5ddba8bc5761a (diff) | |
download | cpython-308d637c94b9ed88c386b83891ad38b2131ebd12.zip cpython-308d637c94b9ed88c386b83891ad38b2131ebd12.tar.gz cpython-308d637c94b9ed88c386b83891ad38b2131ebd12.tar.bz2 |
Merged revisions 74929 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r74929 | benjamin.peterson | 2009-09-18 16:14:55 -0500 (Fri, 18 Sep 2009) | 1 line
add keyword arguments support to str/unicode encode and decode #6300
........
Diffstat (limited to 'Objects')
-rw-r--r-- | Objects/bytearrayobject.c | 7 | ||||
-rw-r--r-- | Objects/bytesobject.c | 7 | ||||
-rw-r--r-- | Objects/unicodeobject.c | 9 |
3 files changed, 14 insertions, 9 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c index 835244a..c09ccde 100644 --- a/Objects/bytearrayobject.c +++ b/Objects/bytearrayobject.c @@ -2877,12 +2877,13 @@ as well as any other name registered with codecs.register_error that is\n\ able to handle UnicodeDecodeErrors."); static PyObject * -bytearray_decode(PyObject *self, PyObject *args) +bytearray_decode(PyObject *self, PyObject *args, PyObject *kwargs) { const char *encoding = NULL; const char *errors = NULL; + static char *kwlist[] = {"encoding", "errors", 0}; - if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", kwlist, &encoding, &errors)) return NULL; if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -3112,7 +3113,7 @@ bytearray_methods[] = { _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, {"count", (PyCFunction)bytearray_count, METH_VARARGS, count__doc__}, - {"decode", (PyCFunction)bytearray_decode, METH_VARARGS, decode_doc}, + {"decode", (PyCFunction)bytearray_decode, METH_VARARGS | METH_KEYWORDS, decode_doc}, {"endswith", (PyCFunction)bytearray_endswith, METH_VARARGS, endswith__doc__}, {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS, expandtabs__doc__}, diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c index fb4a845..27d4f95 100644 --- a/Objects/bytesobject.c +++ b/Objects/bytesobject.c @@ -2725,12 +2725,13 @@ as well as any other name registerd with codecs.register_error that is\n\ able to handle UnicodeDecodeErrors."); static PyObject * -bytes_decode(PyObject *self, PyObject *args) +bytes_decode(PyObject *self, PyObject *args, PyObject *kwargs) { const char *encoding = NULL; const char *errors = NULL; + static char *kwlist[] = {"encoding", "errors", 0}; - if (!PyArg_ParseTuple(args, "|ss:decode", &encoding, &errors)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:decode", kwlist, &encoding, &errors)) return NULL; if (encoding == NULL) encoding = PyUnicode_GetDefaultEncoding(); @@ -2831,7 +2832,7 @@ bytes_methods[] = { _Py_capitalize__doc__}, {"center", (PyCFunction)stringlib_center, METH_VARARGS, center__doc__}, {"count", (PyCFunction)bytes_count, METH_VARARGS, count__doc__}, - {"decode", (PyCFunction)bytes_decode, METH_VARARGS, decode__doc__}, + {"decode", (PyCFunction)bytes_decode, METH_VARARGS | METH_KEYWORDS, decode__doc__}, {"endswith", (PyCFunction)bytes_endswith, METH_VARARGS, endswith__doc__}, {"expandtabs", (PyCFunction)stringlib_expandtabs, METH_VARARGS, diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 758d054..78ef7e1 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -7141,13 +7141,15 @@ a UnicodeEncodeError. Other possible values are 'ignore', 'replace' and\n\ codecs.register_error that can handle UnicodeEncodeErrors."); static PyObject * -unicode_encode(PyUnicodeObject *self, PyObject *args) +unicode_encode(PyUnicodeObject *self, PyObject *args, PyObject *kwargs) { + static char *kwlist[] = {"encoding", "errors", 0}; char *encoding = NULL; char *errors = NULL; PyObject *v; - if (!PyArg_ParseTuple(args, "|ss:encode", &encoding, &errors)) + if (!PyArg_ParseTupleAndKeywords(args, kwargs, "|ss:encode", + kwlist, &encoding, &errors)) return NULL; v = PyUnicode_AsEncodedString((PyObject *)self, encoding, errors); if (v == NULL) @@ -8804,7 +8806,7 @@ static PyMethodDef unicode_methods[] = { /* Order is according to common usage: often used methods should appear first, since lookup is done sequentially. */ - {"encode", (PyCFunction) unicode_encode, METH_VARARGS, encode__doc__}, + {"encode", (PyCFunction) unicode_encode, METH_VARARGS | METH_KEYWORDS, encode__doc__}, {"replace", (PyCFunction) unicode_replace, METH_VARARGS, replace__doc__}, {"split", (PyCFunction) unicode_split, METH_VARARGS, split__doc__}, {"rsplit", (PyCFunction) unicode_rsplit, METH_VARARGS, rsplit__doc__}, @@ -8820,6 +8822,7 @@ static PyMethodDef unicode_methods[] = { {"ljust", (PyCFunction) unicode_ljust, METH_VARARGS, ljust__doc__}, {"lower", (PyCFunction) unicode_lower, METH_NOARGS, lower__doc__}, {"lstrip", (PyCFunction) unicode_lstrip, METH_VARARGS, lstrip__doc__}, +/* {"maketrans", (PyCFunction) unicode_maketrans, METH_VARARGS, maketrans__doc__}, */ {"rfind", (PyCFunction) unicode_rfind, METH_VARARGS, rfind__doc__}, {"rindex", (PyCFunction) unicode_rindex, METH_VARARGS, rindex__doc__}, {"rjust", (PyCFunction) unicode_rjust, METH_VARARGS, rjust__doc__}, |