]> granicus.if.org Git - python/commitdiff
backport keyword argument support for bytearray.decode
authorBenjamin Peterson <benjamin@python.org>
Fri, 18 Sep 2009 21:46:21 +0000 (21:46 +0000)
committerBenjamin Peterson <benjamin@python.org>
Fri, 18 Sep 2009 21:46:21 +0000 (21:46 +0000)
Lib/test/test_bytes.py
Objects/bytearrayobject.c

index 615c9557503c46441b3b0f8a7e3c73ac276d14b7..6257455c8a10471463175246a1eb5d01c0329ffa 100644 (file)
@@ -186,6 +186,8 @@ class BaseBytesTest(unittest.TestCase):
         b = self.type2test(sample, "latin1")
         self.assertRaises(UnicodeDecodeError, b.decode, "utf8")
         self.assertEqual(b.decode("utf8", "ignore"), "Hello world\n")
+        self.assertEqual(b.decode(errors="ignore", encoding="utf8"),
+                         "Hello world\n")
 
     def test_from_int(self):
         b = self.type2test(0)
index b183cc1b626df8360a135d7d3dd1bc04492c9cd7..0390c1d994c3243a8c48cd27563deadd025f08f1 100644 (file)
@@ -2942,12 +2942,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) {
 #ifdef Py_USING_UNICODE
@@ -3189,7 +3190,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__},