[Python-checkins] r68821 - python/branches/io-c/Modules/_textio.c

antoine.pitrou python-checkins at python.org
Tue Jan 20 22:36:17 CET 2009


Author: antoine.pitrou
Date: Tue Jan 20 22:36:16 2009
New Revision: 68821

Log:
Add properties to TextIOBase



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

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:36:16 2009
@@ -65,8 +65,33 @@
     return _unsupported("read");
 }
 
-/* XXX properties: encoding, newlines */
-
+PyDoc_STRVAR(TextIOBase_encoding_doc,
+    "Encoding of the text stream.\n"
+    "\n"
+    "Subclasses should override.\n"
+    );
+
+static PyObject *
+TextIOBase_encoding_get(PyObject *self, void *context)
+{
+    Py_RETURN_NONE;
+}
+
+PyDoc_STRVAR(TextIOBase_newlines_doc,
+    "Line endings translated so far.\n"
+    "\n"
+    "Only line endings translated during reading are considered.\n"
+    "\n"
+    "Subclasses should override.\n"
+    );
+
+static PyObject *
+TextIOBase_newlines_get(PyObject *self, void *context)
+{
+    Py_RETURN_NONE;
+}
+
+
 static PyMethodDef TextIOBase_methods[] = {
     {"read", TextIOBase_read, METH_VARARGS, TextIOBase_read_doc},
     {"readline", TextIOBase_readline, METH_VARARGS, TextIOBase_readline_doc},
@@ -74,6 +99,12 @@
     {NULL, NULL}
 };
 
+static PyGetSetDef TextIOBase_getset[] = {
+    {"encoding", (getter)TextIOBase_encoding_get, NULL, TextIOBase_encoding_doc},
+    {"newlines", (getter)TextIOBase_newlines_get, NULL, TextIOBase_newlines_doc},
+    {0}
+};
+
 PyTypeObject PyTextIOBase_Type = {
     PyVarObject_HEAD_INIT(NULL, 0)
     "TextIOBase",               /*tp_name*/
@@ -104,7 +135,7 @@
     0,                          /* tp_iternext */
     TextIOBase_methods,         /* tp_methods */
     0,                          /* tp_members */
-    0,                          /* tp_getset */
+    TextIOBase_getset,          /* tp_getset */
     &PyIOBase_Type,             /* tp_base */
     0,                          /* tp_dict */
     0,                          /* tp_descr_get */


More information about the Python-checkins mailing list