[Python-checkins] r68001 - sandbox/trunk/io-c/_textio.c
amaury.forgeotdarc
python-checkins at python.org
Mon Dec 29 01:57:16 CET 2008
Author: amaury.forgeotdarc
Date: Mon Dec 29 01:57:16 2008
New Revision: 68001
Log:
Add TextIOWrapper.close() and flush()
Modified:
sandbox/trunk/io-c/_textio.c
Modified: sandbox/trunk/io-c/_textio.c
==============================================================================
--- sandbox/trunk/io-c/_textio.c (original)
+++ sandbox/trunk/io-c/_textio.c Mon Dec 29 01:57:16 2008
@@ -986,6 +986,27 @@
}
static PyObject *
+TextIOWrapper_flush(PyTextIOWrapperObject *self, PyObject *args)
+{
+ self->telling = self->seekable;
+ return PyObject_CallMethod(self->buffer, "flush", NULL);
+}
+
+static PyObject *
+TextIOWrapper_close(PyTextIOWrapperObject *self, PyObject *args)
+{
+ PyObject *res = PyObject_CallMethod(self, "flush", NULL);
+ if (res == NULL) {
+ /* If flush() fails, just give up */
+ PyErr_Clear();
+ }
+ else
+ Py_DECREF(res);
+
+ return PyObject_CallMethod(self->buffer, "close", NULL);
+}
+
+static PyObject *
TextIOWrapper_iternext(PyTextIOWrapperObject *self)
{
PyObject *line;
@@ -1020,13 +1041,14 @@
{"readable", (PyCFunction)TextIOWrapper_readable, METH_NOARGS},
{"writable", (PyCFunction)TextIOWrapper_writable, METH_NOARGS},
{"isatty", (PyCFunction)TextIOWrapper_isatty, METH_NOARGS},
- {"flush", (PyCFunction)BufferedWriter_flush, METH_NOARGS},
*/
{"write", (PyCFunction)TextIOWrapper_write, METH_VARARGS},
{"read", (PyCFunction)TextIOWrapper_read, METH_VARARGS},
{"readline", (PyCFunction)TextIOWrapper_readline, METH_VARARGS},
{"fileno", (PyCFunction)TextIOWrapper_fileno, METH_NOARGS},
+ {"flush", (PyCFunction)TextIOWrapper_flush, METH_NOARGS},
+ {"close", (PyCFunction)TextIOWrapper_close, METH_NOARGS},
/* {"seek", (PyCFunction)TextIOWrapper_seek, METH_VARARGS},
{"tell", (PyCFunction)TextIOWrapper_tell, METH_NOARGS},
{"truncate", (PyCFunction)TextIOWrapper_truncate, METH_VARARGS},
More information about the Python-checkins
mailing list