]> granicus.if.org Git - python/commitdiff
Issue 5449: Fix io.BytesIO to not accept arbitrary keywords
authorAlexandre Vassalotti <alexandre@peadrop.com>
Tue, 4 Aug 2009 23:19:13 +0000 (23:19 +0000)
committerAlexandre Vassalotti <alexandre@peadrop.com>
Tue, 4 Aug 2009 23:19:13 +0000 (23:19 +0000)
Patch contributed by Erick Tryzelaar.

Lib/test/test_memoryio.py
Modules/_io/bytesio.c

index 7dd1658ca476aa85650eb953b6de07d06a53a601..6ab83282fef28696c0c7162415b6510f9b575e97 100644 (file)
@@ -461,6 +461,11 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
         self.assertEqual(memio.write(a), 10)
         self.assertEqual(memio.getvalue(), buf)
 
+    def test_issue5449(self):
+        buf = self.buftype("1234567890")
+        self.ioclass(initial_bytes=buf)
+        self.assertRaises(TypeError, self.ioclass, buf, foo=None)
+
 
 class TextIOTestMixin:
 
index 7b56551e615b66ab96f11cd17b0af5e7f5020098..5ca878dc81d3fbe66931fc101f3d980ff991f89f 100644 (file)
@@ -759,9 +759,11 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 static int
 bytesio_init(bytesio *self, PyObject *args, PyObject *kwds)
 {
+    char *kwlist[] = {"initial_bytes", NULL};
     PyObject *initvalue = NULL;
 
-    if (!PyArg_ParseTuple(args, "|O:BytesIO", &initvalue))
+    if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:BytesIO", kwlist,
+                                     &initvalue))
         return -1;
 
     /* In case, __init__ is called multiple times. */