diff Modules/cStringIO.c @ 73054:27ae7d4e1983 2.7

Issue #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.
author Antoine Pitrou <solipsis@pitrou.net>
date Sat, 22 Oct 2011 21:26:01 +0200
parents b36cb4602e21
children ba1c48f8b571
line wrap: on
line diff
--- a/Modules/cStringIO.c	Fri Oct 21 22:22:43 2011 +0200
+++ b/Modules/cStringIO.c	Sat Oct 22 21:26:01 2011 +0200
@@ -661,7 +661,11 @@
   char *buf;
   Py_ssize_t size;
 
-  if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) {
+  if (PyUnicode_Check(s)) {
+    if (PyObject_AsCharBuffer(s, (const char **)&buf, &size) != 0)
+      return NULL;
+  }
+  else if (PyObject_AsReadBuffer(s, (const void **)&buf, &size)) {
     PyErr_Format(PyExc_TypeError, "expected read buffer, %.200s found",
                  s->ob_type->tp_name);
     return NULL;