Commit e07d5cf9 authored by Guido van Rossum's avatar Guido van Rossum

Jeff Epler's patch adding an xreadlines() method. (It just imports

the xreadlines module and lets it do its thing.)
parent 07b78a87
...@@ -963,6 +963,29 @@ file_readline(PyFileObject *f, PyObject *args) ...@@ -963,6 +963,29 @@ file_readline(PyFileObject *f, PyObject *args)
return get_line(f, n); return get_line(f, n);
} }
static PyObject *
file_xreadlines(PyFileObject *f, PyObject *args)
{
static PyObject* xreadlines_function = NULL;
if (!PyArg_ParseTuple(args, ":xreadlines"))
return NULL;
if (!xreadlines_function) {
PyObject *xreadlines_module =
PyImport_ImportModule("xreadlines");
if(!xreadlines_module)
return NULL;
xreadlines_function = PyObject_GetAttrString(xreadlines_module,
"xreadlines");
Py_DECREF(xreadlines_module);
if(!xreadlines_function)
return NULL;
}
return PyObject_CallFunction(xreadlines_function, "(O)", f);
}
static PyObject * static PyObject *
file_readlines(PyFileObject *f, PyObject *args) file_readlines(PyFileObject *f, PyObject *args)
{ {
...@@ -1232,6 +1255,7 @@ static PyMethodDef file_methods[] = { ...@@ -1232,6 +1255,7 @@ static PyMethodDef file_methods[] = {
{"tell", (PyCFunction)file_tell, 0}, {"tell", (PyCFunction)file_tell, 0},
{"readinto", (PyCFunction)file_readinto, 0}, {"readinto", (PyCFunction)file_readinto, 0},
{"readlines", (PyCFunction)file_readlines, 1}, {"readlines", (PyCFunction)file_readlines, 1},
{"xreadlines", (PyCFunction)file_xreadlines, 1},
{"writelines", (PyCFunction)file_writelines, 0}, {"writelines", (PyCFunction)file_writelines, 0},
{"flush", (PyCFunction)file_flush, 0}, {"flush", (PyCFunction)file_flush, 0},
{"close", (PyCFunction)file_close, 0}, {"close", (PyCFunction)file_close, 0},
......
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