[Python-checkins] r56831 - in python/branches/release25-maint: Doc/lib/libstringio.tex Lib/test/test_StringIO.py Misc/NEWS Modules/cStringIO.c

georg.brandl python-checkins at python.org
Wed Aug 8 15:03:45 CEST 2007


Author: georg.brandl
Date: Wed Aug  8 15:03:45 2007
New Revision: 56831

Modified:
   python/branches/release25-maint/Doc/lib/libstringio.tex
   python/branches/release25-maint/Lib/test/test_StringIO.py
   python/branches/release25-maint/Misc/NEWS
   python/branches/release25-maint/Modules/cStringIO.c
Log:
Revert the fix for #1548891, it broke backwards compatibility with arbitrary read buffers.
Fixes #1730114.
 (backport from rev. 56830)

Modified: python/branches/release25-maint/Doc/lib/libstringio.tex
==============================================================================
--- python/branches/release25-maint/Doc/lib/libstringio.tex	(original)
+++ python/branches/release25-maint/Doc/lib/libstringio.tex	Wed Aug  8 15:03:45 2007
@@ -78,6 +78,10 @@
 module, those provided by this module are not able to accept Unicode
 strings that cannot be encoded as plain \ASCII{} strings.
 
+Calling \function{StringIO()} with a Unicode string parameter populates
+the object with the buffer representation of the Unicode string, instead of
+encoding the string.
+
 Another difference from the \refmodule{StringIO} module is that calling
 \function{StringIO()} with a string parameter creates a read-only object.
 Unlike an object created without a string parameter, it does not have

Modified: python/branches/release25-maint/Lib/test/test_StringIO.py
==============================================================================
--- python/branches/release25-maint/Lib/test/test_StringIO.py	(original)
+++ python/branches/release25-maint/Lib/test/test_StringIO.py	Wed Aug  8 15:03:45 2007
@@ -120,28 +120,6 @@
 class TestcStringIO(TestGenericStringIO):
     MODULE = cStringIO
 
-    def test_unicode(self):
-
-        if not test_support.have_unicode: return
-
-        # The cStringIO module converts Unicode strings to character
-        # strings when writing them to cStringIO objects.
-        # Check that this works.
-
-        f = self.MODULE.StringIO()
-        f.write(unicode(self._line[:5]))
-        s = f.getvalue()
-        self.assertEqual(s, 'abcde')
-        self.assertEqual(type(s), types.StringType)
-
-        f = self.MODULE.StringIO(unicode(self._line[:5]))
-        s = f.getvalue()
-        self.assertEqual(s, 'abcde')
-        self.assertEqual(type(s), types.StringType)
-
-        self.assertRaises(UnicodeEncodeError, self.MODULE.StringIO,
-                          unicode('\xf4', 'latin-1'))
-
 import sys
 if sys.platform.startswith('java'):
     # Jython doesn't have a buffer object, so we just do a useless

Modified: python/branches/release25-maint/Misc/NEWS
==============================================================================
--- python/branches/release25-maint/Misc/NEWS	(original)
+++ python/branches/release25-maint/Misc/NEWS	Wed Aug  8 15:03:45 2007
@@ -26,6 +26,9 @@
 Library
 -------
 
+- Reverted the fix for bug #1548891 because it broke compatibility with
+  arbitrary read buffers. Added a note in the documentation.
+
 - GB18030 codec now can encode additional two-byte characters that
   are missing in GBK.
 

Modified: python/branches/release25-maint/Modules/cStringIO.c
==============================================================================
--- python/branches/release25-maint/Modules/cStringIO.c	(original)
+++ python/branches/release25-maint/Modules/cStringIO.c	Wed Aug  8 15:03:45 2007
@@ -665,8 +665,11 @@
   char *buf;
   Py_ssize_t size;
 
-  if (PyObject_AsCharBuffer(s, (const char **)&buf, &size) != 0)
-      return NULL;
+  if (PyObject_AsReadBuffer(s, (const char **)&buf, &size)) {
+    PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found",
+                 s->ob_type->tp_name);
+    return NULL;
+  }
 
   self = PyObject_New(Iobject, &Itype);
   if (!self) return NULL;


More information about the Python-checkins mailing list