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
........
This commit is contained in:
Benjamin Peterson 2009-09-18 21:42:35 +00:00
parent 7a4e5866f7
commit 308d637c94
7 changed files with 29 additions and 13 deletions

View file

@ -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__},