Manual py3k backport: [svn r74316] Issue #5449: Fix io.BytesIO to not accept arbitrary keywords

This commit is contained in:
Antoine Pitrou 2009-10-24 12:28:22 +00:00
parent fa94e80f3b
commit f7820c1626
2 changed files with 8 additions and 1 deletions

View File

@ -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:

View File

@ -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. */