From f7820c162648b7b724d0195541896a64ac5df294 Mon Sep 17 00:00:00 2001 From: Antoine Pitrou Date: Sat, 24 Oct 2009 12:28:22 +0000 Subject: [PATCH] Manual py3k backport: [svn r74316] Issue #5449: Fix io.BytesIO to not accept arbitrary keywords --- Lib/test/test_memoryio.py | 5 +++++ Modules/_io/bytesio.c | 4 +++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_memoryio.py b/Lib/test/test_memoryio.py index d94d1a63593..e55a811fda9 100644 --- a/Lib/test/test_memoryio.py +++ b/Lib/test/test_memoryio.py @@ -467,6 +467,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: diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index beba11c82e9..d25cb673f58 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -766,9 +766,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. */