[Python-checkins] CVS: python/dist/src/Objects fileobject.c,2.110,2.111
Guido van Rossum
gvanrossum@users.sourceforge.net
Sat, 21 Apr 2001 06:20:20 -0700
Update of /cvsroot/python/python/dist/src/Objects
In directory usw-pr-cvs1:/tmp/cvs-serv13379
Modified Files:
fileobject.c
Log Message:
Oops, forgot to merge this from the iter-branch to the trunk.
This adds "for line in file" iteration, as promised.
Index: fileobject.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Objects/fileobject.c,v
retrieving revision 2.110
retrieving revision 2.111
diff -C2 -r2.110 -r2.111
*** fileobject.c 2001/04/14 17:49:40 2.110
--- fileobject.c 2001/04/21 13:20:18 2.111
***************
*** 1298,1301 ****
--- 1298,1316 ----
}
+ static PyObject *
+ file_getiter(PyFileObject *f)
+ {
+ static PyObject *es;
+ PyObject *iter;
+ PyObject *rl = Py_FindMethod(file_methods, (PyObject *)f, "readline");
+ if (rl == NULL)
+ return NULL;
+ if (es == NULL)
+ es = PyString_FromString("");
+ iter = PyCallIter_New(rl, es);
+ Py_DECREF(rl);
+ return iter;
+ }
+
PyTypeObject PyFile_Type = {
PyObject_HEAD_INIT(&PyType_Type)
***************
*** 1304,1313 ****
sizeof(PyFileObject),
0,
! (destructor)file_dealloc, /*tp_dealloc*/
! 0, /*tp_print*/
! (getattrfunc)file_getattr, /*tp_getattr*/
! (setattrfunc)file_setattr, /*tp_setattr*/
! 0, /*tp_compare*/
! (reprfunc)file_repr, /*tp_repr*/
};
--- 1319,1344 ----
sizeof(PyFileObject),
0,
! (destructor)file_dealloc, /* tp_dealloc */
! 0, /* tp_print */
! (getattrfunc)file_getattr, /* tp_getattr */
! (setattrfunc)file_setattr, /* tp_setattr */
! 0, /* tp_compare */
! (reprfunc)file_repr, /* tp_repr */
! 0, /* tp_as_number */
! 0, /* tp_as_sequence */
! 0, /* tp_as_mapping */
! 0, /* tp_hash */
! 0, /* tp_call */
! 0, /* tp_str */
! 0, /* tp_getattro */
! 0, /* tp_setattro */
! 0, /* tp_as_buffer */
! Py_TPFLAGS_DEFAULT, /* tp_flags */
! 0, /* tp_doc */
! 0, /* tp_traverse */
! 0, /* tp_clear */
! 0, /* tp_richcompare */
! 0, /* tp_weaklistoffset */
! (getiterfunc)file_getiter, /* tp_iter */
};
***************
*** 1478,1482 ****
return fd;
}
-
-
-
--- 1509,1510 ----