diff options
author | Georg Brandl <georg@python.org> | 2007-08-08 13:03:41 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2007-08-08 13:03:41 (GMT) |
commit | 9616444427cbbc5283f21a09ffa852ad21805588 (patch) | |
tree | 4e317891a8fc12947cad39710b84961ebc775221 | |
parent | 52c0c368b9d279f4972e15f596616a436e5e2a6e (diff) | |
download | cpython-9616444427cbbc5283f21a09ffa852ad21805588.zip cpython-9616444427cbbc5283f21a09ffa852ad21805588.tar.gz cpython-9616444427cbbc5283f21a09ffa852ad21805588.tar.bz2 |
Revert the fix for #1548891, it broke backwards compatibility with arbitrary read buffers.
Fixes #1730114.
-rw-r--r-- | Doc/lib/libstringio.tex | 4 | ||||
-rw-r--r-- | Lib/test/test_StringIO.py | 22 | ||||
-rw-r--r-- | Misc/NEWS | 4 | ||||
-rw-r--r-- | Modules/cStringIO.c | 7 |
4 files changed, 9 insertions, 28 deletions
diff --git a/Doc/lib/libstringio.tex b/Doc/lib/libstringio.tex index 2431251..73ff0e4 100644 --- a/Doc/lib/libstringio.tex +++ b/Doc/lib/libstringio.tex @@ -78,6 +78,10 @@ Unlike the memory files implemented by the \refmodule{StringIO} 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 diff --git a/Lib/test/test_StringIO.py b/Lib/test/test_StringIO.py index 9f79b02..58cbec0 100644 --- a/Lib/test/test_StringIO.py +++ b/Lib/test/test_StringIO.py @@ -121,28 +121,6 @@ class TestStringIO(TestGenericStringIO): 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 @@ -782,10 +782,6 @@ Extension Modules - Patch #1576166: Support os.utime for directories on Windows NT+. -- Bug #1548891: The cStringIO.StringIO() constructor now encodes unicode - arguments with the system default encoding just like the write() - method does, instead of converting it to a raw buffer. - - Patch #1572724: fix typo ('=' instead of '==') in _msi.c. - Bug #1572832: fix a bug in ISO-2022 codecs which may cause segfault diff --git a/Modules/cStringIO.c b/Modules/cStringIO.c index 5834e20..0cc9c6b 100644 --- a/Modules/cStringIO.c +++ b/Modules/cStringIO.c @@ -673,8 +673,11 @@ newIobject(PyObject *s) { 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; |