[Python-checkins] r67838 - in sandbox/trunk/io-c: _iobase.c _textio.c
amaury.forgeotdarc
python-checkins at python.org
Thu Dec 18 01:32:34 CET 2008
Author: amaury.forgeotdarc
Date: Thu Dec 18 01:32:33 2008
New Revision: 67838
Log:
Really make these objects iterable
Modified:
sandbox/trunk/io-c/_iobase.c
sandbox/trunk/io-c/_textio.c
Modified: sandbox/trunk/io-c/_iobase.c
==============================================================================
--- sandbox/trunk/io-c/_iobase.c (original)
+++ sandbox/trunk/io-c/_iobase.c Thu Dec 18 01:32:33 2008
@@ -403,7 +403,7 @@
}
static PyObject *
-IOBase_next(PyObject *self, PyObject *args)
+IOBase_iternext(PyObject *self)
{
PyObject *line = PyObject_CallMethod(self, "readline", NULL);
@@ -537,9 +537,6 @@
{"__enter__", IOBase_enter, METH_NOARGS},
{"__exit__", IOBase_exit, METH_VARARGS},
- {"__iter__", IOBase_iter, METH_NOARGS},
- {"__next__", IOBase_next, METH_NOARGS},
-
{"readline", IOBase_readline, METH_VARARGS, IOBase_readline_doc},
{"readlines", IOBase_readlines, METH_VARARGS, IOBase_readlines_doc},
{"writelines", IOBase_writelines, METH_VARARGS},
@@ -579,8 +576,8 @@
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
+ IOBase_iter, /* tp_iter */
+ IOBase_iternext, /* tp_iternext */
IOBase_methods, /* tp_methods */
0, /* tp_members */
IOBase_getset, /* tp_getset */
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Thu Dec 18 01:32:33 2008
@@ -961,6 +961,30 @@
}
static PyObject *
+TextIOWrapper_iternext(PyTextIOWrapperObject *self)
+{
+ PyObject *line;
+
+ self->telling = 0;
+
+ line = PyObject_CallMethod((PyObject *)self, "readline", NULL);
+
+ if (line == NULL)
+ return NULL;
+
+ assert (PyUnicode_Check(line));
+
+ if (PyUnicode_GET_SIZE(line) == 0) {
+ Py_DECREF(line);
+ Py_CLEAR(self->snapshot);
+ self->telling = self->seekable;
+ return NULL;
+ }
+
+ return line;
+}
+
+static PyObject *
TextIOWrapper_name_get(PyTextIOWrapperObject *self, void *context)
{
return PyObject_GetAttrString(self->buffer, "name");
@@ -1029,7 +1053,7 @@
0, /* tp_richcompare */
offsetof(PyTextIOWrapperObject, weakreflist), /*tp_weaklistoffset*/
0, /* tp_iter */
- 0, /* tp_iternext */
+ (iternextfunc)TextIOWrapper_iternext, /* tp_iternext */
TextIOWrapper_methods, /* tp_methods */
TextIOWrapper_members, /* tp_members */
TextIOWrapper_getset, /* tp_getset */
More information about the Python-checkins
mailing list