[Python-checkins] r73259 - in python/branches/py3k: Doc/library/io.rst Lib/_pyio.py Lib/test/test_io.py Lib/test/test_memoryio.py Misc/NEWS Modules/_io/stringio.c Modules/_io/textio.c

benjamin.peterson python-checkins at python.org
Sat Jun 6 20:02:18 CEST 2009


Author: benjamin.peterson
Date: Sat Jun  6 20:02:12 2009
New Revision: 73259

Log:
give the C implementation of TextIOWrapper the errors property #6217

Modified:
   python/branches/py3k/Doc/library/io.rst
   python/branches/py3k/Lib/_pyio.py
   python/branches/py3k/Lib/test/test_io.py
   python/branches/py3k/Lib/test/test_memoryio.py
   python/branches/py3k/Misc/NEWS
   python/branches/py3k/Modules/_io/stringio.c
   python/branches/py3k/Modules/_io/textio.c

Modified: python/branches/py3k/Doc/library/io.rst
==============================================================================
--- python/branches/py3k/Doc/library/io.rst	(original)
+++ python/branches/py3k/Doc/library/io.rst	Sat Jun  6 20:02:12 2009
@@ -600,6 +600,10 @@
       The name of the encoding used to decode the stream's bytes into
       strings, and to encode strings into bytes.
 
+   .. attribute:: errors
+
+      The error setting of the decoder or encoder.
+
    .. attribute:: newlines
 
       A string, a tuple of strings, or ``None``, indicating the newlines
@@ -665,13 +669,9 @@
    If *line_buffering* is ``True``, :meth:`flush` is implied when a call to
    write contains a newline character.
 
-   :class:`TextIOWrapper` provides these data attributes in addition to those of
+   :class:`TextIOWrapper` provides one attribute in addition to those of
    :class:`TextIOBase` and its parents:
 
-   .. attribute:: errors
-
-      The encoding and decoding error setting.
-
    .. attribute:: line_buffering
 
       Whether line buffering is enabled.

Modified: python/branches/py3k/Lib/_pyio.py
==============================================================================
--- python/branches/py3k/Lib/_pyio.py	(original)
+++ python/branches/py3k/Lib/_pyio.py	Sat Jun  6 20:02:12 2009
@@ -1286,6 +1286,13 @@
         """
         return None
 
+    @property
+    def errors(self):
+        """Error setting of the decoder or encoder.
+
+        Subclasses should override."""
+        return None
+
 io.TextIOBase.register(TextIOBase)
 
 
@@ -1933,6 +1940,10 @@
         return object.__repr__(self)
 
     @property
+    def errors(self):
+        return None
+
+    @property
     def encoding(self):
         return None
 

Modified: python/branches/py3k/Lib/test/test_io.py
==============================================================================
--- python/branches/py3k/Lib/test/test_io.py	(original)
+++ python/branches/py3k/Lib/test/test_io.py	Sat Jun  6 20:02:12 2009
@@ -2024,6 +2024,12 @@
             with self.open(filename, 'rb') as f:
                 self.assertEquals(f.read(), 'bbbzzz'.encode(charset))
 
+    def test_errors_property(self):
+        with self.open(support.TESTFN, "w") as f:
+            self.assertEqual(f.errors, "strict")
+        with self.open(support.TESTFN, "w", errors="replace") as f:
+            self.assertEqual(f.errors, "replace")
+
 
 class CTextIOWrapperTest(TextIOWrapperTest):
 

Modified: python/branches/py3k/Lib/test/test_memoryio.py
==============================================================================
--- python/branches/py3k/Lib/test/test_memoryio.py	(original)
+++ python/branches/py3k/Lib/test/test_memoryio.py	Sat Jun  6 20:02:12 2009
@@ -459,9 +459,9 @@
 
         # These are just dummy values but we nevertheless check them for fear
         # of unexpected breakage.
-        self.assertTrue(memio.encoding is None)
-        self.assertEqual(memio.errors, "strict")
-        self.assertEqual(memio.line_buffering, False)
+        self.assertIsNone(memio.encoding)
+        self.assertIsNone(memio.errors)
+        self.assertFalse(memio.line_buffering)
 
     def test_newline_none(self):
         # newline=None

Modified: python/branches/py3k/Misc/NEWS
==============================================================================
--- python/branches/py3k/Misc/NEWS	(original)
+++ python/branches/py3k/Misc/NEWS	Sat Jun  6 20:02:12 2009
@@ -21,6 +21,10 @@
 Library
 -------
 
+- Issue #6217: The C implementation of io.TextIOWrapper didn't include the
+  errors property.  Additionally, the errors and encoding properties of StringIO
+  are always None now.
+
 - Issue #6137: The pickle module now translates module names when loading
   or dumping pickles with a 2.x-compatible protocol, in order to make data
   sharing and migration easier. This behaviour can be disabled using the

Modified: python/branches/py3k/Modules/_io/stringio.c
==============================================================================
--- python/branches/py3k/Modules/_io/stringio.c	(original)
+++ python/branches/py3k/Modules/_io/stringio.c	Sat Jun  6 20:02:12 2009
@@ -661,22 +661,6 @@
 }
 
 static PyObject *
-stringio_encoding(StringIOObject *self, void *context)
-{
-    CHECK_INITIALIZED(self);
-    CHECK_CLOSED(self);
-    Py_RETURN_NONE;
-}
-
-static PyObject *
-stringio_errors(StringIOObject *self, void *context)
-{
-    CHECK_INITIALIZED(self);
-    CHECK_CLOSED(self);
-    return PyUnicode_FromString("strict");
-}
-
-static PyObject *
 stringio_line_buffering(StringIOObject *self, void *context)
 {
     CHECK_INITIALIZED(self);
@@ -720,8 +704,6 @@
         will be found.
     */
     {"buffer",         (getter)stringio_buffer,         NULL, NULL},
-    {"encoding",       (getter)stringio_encoding,       NULL, NULL},
-    {"errors",         (getter)stringio_errors,         NULL, NULL},
     {"line_buffering", (getter)stringio_line_buffering, NULL, NULL},
     {NULL}
 };

Modified: python/branches/py3k/Modules/_io/textio.c
==============================================================================
--- python/branches/py3k/Modules/_io/textio.c	(original)
+++ python/branches/py3k/Modules/_io/textio.c	Sat Jun  6 20:02:12 2009
@@ -104,6 +104,18 @@
     Py_RETURN_NONE;
 }
 
+PyDoc_STRVAR(TextIOBase_errors_doc,
+    "The error setting of the decoder or encoder.\n"
+    "\n"
+    "Subclasses should override.\n"
+    );
+
+static PyObject *
+TextIOBase_errors_get(PyObject *self, void *context)
+{
+    Py_RETURN_NONE;
+}
+
 
 static PyMethodDef TextIOBase_methods[] = {
     {"detach", (PyCFunction)TextIOBase_detach, METH_NOARGS, TextIOBase_detach_doc},
@@ -116,6 +128,7 @@
 static PyGetSetDef TextIOBase_getset[] = {
     {"encoding", (getter)TextIOBase_encoding_get, NULL, TextIOBase_encoding_doc},
     {"newlines", (getter)TextIOBase_newlines_get, NULL, TextIOBase_newlines_doc},
+    {"errors", (getter)TextIOBase_errors_get, NULL, TextIOBase_errors_doc},
     {NULL}
 };
 
@@ -2462,6 +2475,13 @@
 }
 
 static PyObject *
+TextIOWrapper_errors_get(PyTextIOWrapperObject *self, void *context)
+{
+    CHECK_INITIALIZED(self);
+    return PyUnicode_FromString(PyBytes_AS_STRING(self->errors));
+}
+
+static PyObject *
 TextIOWrapper_chunk_size_get(PyTextIOWrapperObject *self, void *context)
 {
     CHECK_INITIALIZED(self);
@@ -2519,6 +2539,7 @@
 /*    {"mode", (getter)TextIOWrapper_mode_get, NULL, NULL},
 */
     {"newlines", (getter)TextIOWrapper_newlines_get, NULL, NULL},
+    {"errors", (getter)TextIOWrapper_errors_get, NULL, NULL},
     {"_CHUNK_SIZE", (getter)TextIOWrapper_chunk_size_get,
                     (setter)TextIOWrapper_chunk_size_set, NULL},
     {NULL}


More information about the Python-checkins mailing list