diff options
author | Benjamin Peterson <benjamin@python.org> | 2009-12-13 19:19:07 +0000 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2009-12-13 19:19:07 +0000 |
commit | ddd392cbb9a94355a2ea32da4a42371d1333bfb8 (patch) | |
tree | f4c325ef0ec20e0e2007770992d371baa07c2bc7 /Modules/_io/bufferedio.c | |
parent | e304852e21a92ef0a74c2d85c070572fddb4fba8 (diff) | |
download | cpython-git-ddd392cbb9a94355a2ea32da4a42371d1333bfb8.tar.gz |
accept None as the same as having passed no argument in file types #7349
This is for consistency with imitation file objects like StringIO and BytesIO.
This commit also adds a few tests, where they were lacking for concerned
methods.
Diffstat (limited to 'Modules/_io/bufferedio.c')
-rw-r--r-- | Modules/_io/bufferedio.c | 18 |
1 files changed, 2 insertions, 16 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c index 3ab7906a93..ba937eda83 100644 --- a/Modules/_io/bufferedio.c +++ b/Modules/_io/bufferedio.c @@ -720,7 +720,7 @@ buffered_read(buffered *self, PyObject *args) PyObject *res; CHECK_INITIALIZED(self) - if (!PyArg_ParseTuple(args, "|n:read", &n)) { + if (!PyArg_ParseTuple(args, "|O&:read", &_PyIO_ConvertSsize_t, &n)) { return NULL; } if (n < -1) { @@ -950,25 +950,11 @@ end_unlocked: static PyObject * buffered_readline(buffered *self, PyObject *args) { - PyObject *limitobj = NULL; Py_ssize_t limit = -1; CHECK_INITIALIZED(self) - - if (!PyArg_ParseTuple(args, "|O:readline", &limitobj)) { + if (!PyArg_ParseTuple(args, "|O&:readline", &_PyIO_ConvertSsize_t, &limit)) return NULL; - } - if (limitobj) { - if (!PyNumber_Check(limitobj)) { - PyErr_Format(PyExc_TypeError, - "integer argument expected, got '%.200s'", - Py_TYPE(limitobj)->tp_name); - return NULL; - } - limit = PyNumber_AsSsize_t(limitobj, PyExc_OverflowError); - if (limit == -1 && PyErr_Occurred()) - return NULL; - } return _buffered_readline(self, limit); } |