Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit e07d5cf

Browse files
committed
Jeff Epler's patch adding an xreadlines() method. (It just imports
the xreadlines module and lets it do its thing.)
1 parent 07b78a8 commit e07d5cf

1 file changed

Lines changed: 25 additions & 1 deletion

File tree

Objects/fileobject.c

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -963,6 +963,29 @@ file_readline(PyFileObject *f, PyObject *args)
963963
return get_line(f, n);
964964
}
965965

966+
static PyObject *
967+
file_xreadlines(PyFileObject *f, PyObject *args)
968+
{
969+
static PyObject* xreadlines_function = NULL;
970+
971+
if (!PyArg_ParseTuple(args, ":xreadlines"))
972+
return NULL;
973+
974+
if (!xreadlines_function) {
975+
PyObject *xreadlines_module =
976+
PyImport_ImportModule("xreadlines");
977+
if(!xreadlines_module)
978+
return NULL;
979+
980+
xreadlines_function = PyObject_GetAttrString(xreadlines_module,
981+
"xreadlines");
982+
Py_DECREF(xreadlines_module);
983+
if(!xreadlines_function)
984+
return NULL;
985+
}
986+
return PyObject_CallFunction(xreadlines_function, "(O)", f);
987+
}
988+
966989
static PyObject *
967990
file_readlines(PyFileObject *f, PyObject *args)
968991
{
@@ -1009,7 +1032,7 @@ file_readlines(PyFileObject *f, PyObject *args)
10091032
buffersize *= 2;
10101033
if (buffersize > INT_MAX) {
10111034
PyErr_SetString(PyExc_OverflowError,
1012-
"line is longer than a Python string can hold");
1035+
"line is longer than a Python string can hold");
10131036
goto error;
10141037
}
10151038
if (big_buffer == NULL) {
@@ -1232,6 +1255,7 @@ static PyMethodDef file_methods[] = {
12321255
{"tell", (PyCFunction)file_tell, 0},
12331256
{"readinto", (PyCFunction)file_readinto, 0},
12341257
{"readlines", (PyCFunction)file_readlines, 1},
1258+
{"xreadlines", (PyCFunction)file_xreadlines, 1},
12351259
{"writelines", (PyCFunction)file_writelines, 0},
12361260
{"flush", (PyCFunction)file_flush, 0},
12371261
{"close", (PyCFunction)file_close, 0},

0 commit comments

Comments
 (0)