[Python-checkins] r68820 - in python/branches/io-c/Modules: _iomodule.h _textio.c io.c

antoine.pitrou python-checkins at python.org
Tue Jan 20 22:29:59 CET 2009


Author: antoine.pitrou
Date: Tue Jan 20 22:29:59 2009
New Revision: 68820

Log:
Add class TextIOBase



Modified:
   python/branches/io-c/Modules/_iomodule.h
   python/branches/io-c/Modules/_textio.c
   python/branches/io-c/Modules/io.c

Modified: python/branches/io-c/Modules/_iomodule.h
==============================================================================
--- python/branches/io-c/Modules/_iomodule.h	(original)
+++ python/branches/io-c/Modules/_iomodule.h	Tue Jan 20 22:29:59 2009
@@ -2,11 +2,15 @@
  * Declarations shared between the different parts of the io module
  */
 
-extern PyTypeObject PyFileIO_Type;
-extern PyTypeObject PyBytesIO_Type;
+/* ABCs */
 extern PyTypeObject PyIOBase_Type;
 extern PyTypeObject PyRawIOBase_Type;
 extern PyTypeObject PyBufferedIOBase_Type;
+extern PyTypeObject PyTextIOBase_Type;
+
+/* Concrete classes */
+extern PyTypeObject PyFileIO_Type;
+extern PyTypeObject PyBytesIO_Type;
 extern PyTypeObject PyBufferedReader_Type;
 extern PyTypeObject PyBufferedWriter_Type;
 extern PyTypeObject PyBufferedRWPair_Type;

Modified: python/branches/io-c/Modules/_textio.c
==============================================================================
--- python/branches/io-c/Modules/_textio.c	(original)
+++ python/branches/io-c/Modules/_textio.c	Tue Jan 20 22:29:59 2009
@@ -28,26 +28,93 @@
     return NULL;
 }
 
+PyDoc_STRVAR(TextIOBase_read_doc,
+    "Read at most n characters from stream.\n"
+    "\n"
+    "Read from underlying buffer until we have n characters or we hit EOF.\n"
+    "If n is negative or omitted, read until EOF.\n"
+    );
+
 static PyObject *
 TextIOBase_read(PyObject *self, PyObject *args)
 {
     return _unsupported("read");
 }
 
+PyDoc_STRVAR(TextIOBase_readline_doc,
+    "Read until newline or EOF.\n"
+    "\n"
+    "Returns an empty string if EOF is hit immediately.\n"
+    );
+
 static PyObject *
-TextIOBase_write(PyObject *self, PyObject *args)
+TextIOBase_readline(PyObject *self, PyObject *args)
 {
     return _unsupported("read");
 }
 
+PyDoc_STRVAR(TextIOBase_write_doc,
+    "Write string to stream.\n"
+    "Returns the number of characters written (which is always equal to\n"
+    "the length of the string).\n"
+    );
+
 static PyObject *
-TextIOBase_readline(PyObject *self, PyObject *args)
+TextIOBase_write(PyObject *self, PyObject *args)
 {
     return _unsupported("read");
 }
 
 /* XXX properties: encoding, newlines */
 
+static PyMethodDef TextIOBase_methods[] = {
+    {"read", TextIOBase_read, METH_VARARGS, TextIOBase_read_doc},
+    {"readline", TextIOBase_readline, METH_VARARGS, TextIOBase_readline_doc},
+    {"write", TextIOBase_write, METH_VARARGS, TextIOBase_write_doc},
+    {NULL, NULL}
+};
+
+PyTypeObject PyTextIOBase_Type = {
+    PyVarObject_HEAD_INIT(NULL, 0)
+    "TextIOBase",               /*tp_name*/
+    0,                          /*tp_basicsize*/
+    0,                          /*tp_itemsize*/
+    0,                          /*tp_dealloc*/
+    0,                          /*tp_print*/
+    0,                          /*tp_getattr*/
+    0,                          /*tp_setattr*/
+    0,                          /*tp_compare */
+    0,                          /*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 | Py_TPFLAGS_BASETYPE,  /*tp_flags*/
+    TextIOBase_doc,             /* tp_doc */
+    0,                          /* tp_traverse */
+    0,                          /* tp_clear */
+    0,                          /* tp_richcompare */
+    0,                          /* tp_weaklistoffset */
+    0,                          /* tp_iter */
+    0,                          /* tp_iternext */
+    TextIOBase_methods,         /* tp_methods */
+    0,                          /* tp_members */
+    0,                          /* tp_getset */
+    &PyIOBase_Type,             /* tp_base */
+    0,                          /* tp_dict */
+    0,                          /* tp_descr_get */
+    0,                          /* tp_descr_set */
+    0,                          /* tp_dictoffset */
+    0,                          /* tp_init */
+    0,                          /* tp_alloc */
+    0,                          /* tp_new */
+};
+
 
 /* IncrementalNewlineDecoder */
 

Modified: python/branches/io-c/Modules/io.c
==============================================================================
--- python/branches/io-c/Modules/io.c	(original)
+++ python/branches/io-c/Modules/io.c	Tue Jan 20 22:29:59 2009
@@ -674,8 +674,14 @@
     Py_INCREF(&PyBufferedRandom_Type);
     PyModule_AddObject(m, "BufferedRandom", (PyObject *) &PyBufferedRandom_Type);
 
+    /* BufferedIOBase */
+    if (PyType_Ready(&PyTextIOBase_Type) < 0)
+        goto fail;
+    Py_INCREF(&PyTextIOBase_Type);
+    PyModule_AddObject(m, "TextIOBase", (PyObject *) &PyTextIOBase_Type);
+
     /* TextIOWrapper */
-    PyTextIOWrapper_Type.tp_base = &PyIOBase_Type;
+    PyTextIOWrapper_Type.tp_base = &PyTextIOBase_Type;
     if (PyType_Ready(&PyTextIOWrapper_Type) < 0)
         goto fail;
     Py_INCREF(&PyTextIOWrapper_Type);


More information about the Python-checkins mailing list