Commit ba5c7432 authored by Alexandre Vassalotti's avatar Alexandre Vassalotti

Issue 5449: Fix io.BytesIO to not accept arbitrary keywords

Patch contributed by Erick Tryzelaar.
parent bbffb25c
...@@ -461,6 +461,11 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase): ...@@ -461,6 +461,11 @@ class PyBytesIOTest(MemoryTestMixin, MemorySeekTestMixin, unittest.TestCase):
self.assertEqual(memio.write(a), 10) self.assertEqual(memio.write(a), 10)
self.assertEqual(memio.getvalue(), buf) 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: class TextIOTestMixin:
......
...@@ -759,9 +759,11 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds) ...@@ -759,9 +759,11 @@ bytesio_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int static int
bytesio_init(bytesio *self, PyObject *args, PyObject *kwds) bytesio_init(bytesio *self, PyObject *args, PyObject *kwds)
{ {
char *kwlist[] = {"initial_bytes", NULL};
PyObject *initvalue = NULL; PyObject *initvalue = NULL;
if (!PyArg_ParseTuple(args, "|O:BytesIO", &initvalue)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O:BytesIO", kwlist,
&initvalue))
return -1; return -1;
/* In case, __init__ is called multiple times. */ /* In case, __init__ is called multiple times. */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment