[Python-checkins] r74936 - in python/trunk: Lib/test/test_bytes.py Objects/bytearrayobject.c

benjamin.peterson python-checkins at python.org
Fri Sep 18 23:46:21 CEST 2009


Author: benjamin.peterson
Date: Fri Sep 18 23:46:21 2009
New Revision: 74936

Log:
backport keyword argument support for bytearray.decode

Modified:
   python/trunk/Lib/test/test_bytes.py
   python/trunk/Objects/bytearrayobject.c

Modified: python/trunk/Lib/test/test_bytes.py
==============================================================================
--- python/trunk/Lib/test/test_bytes.py	(original)
+++ python/trunk/Lib/test/test_bytes.py	Fri Sep 18 23:46:21 2009
@@ -186,6 +186,8 @@
         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)

Modified: python/trunk/Objects/bytearrayobject.c
==============================================================================
--- python/trunk/Objects/bytearrayobject.c	(original)
+++ python/trunk/Objects/bytearrayobject.c	Fri Sep 18 23:46:21 2009
@@ -2942,12 +2942,13 @@
 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 @@
      _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__},


More information about the Python-checkins mailing list