[Python-Dev] cStringIO.StringIO() buffer behavior

"Martin v. Löwis" martin at v.loewis.de
Sun Aug 5 18:37:48 CEST 2007


> See bugs #1548891 and #1730114.
> 
> In the former, it was reported that cStringIO works differently from StringIO
> when handling unicode strings; it used GetReadBuffer which returned the raw
> internal UCS-2 or UCS-4 encoded string.
> 
> I changed it to use GetCharBuffer, which converts to a string using the
> default encoding first. This fix was also in 2.5.1.
> 
> The latter bug now complains that this excludes things like array.array()s
> from being used as an argument to cStringIO.StringIO(), which worked before
> with GetReadBuffer.
> 
> What's the preferred solution here?

I think the 2.5.0 behavior to accept array.array should be restored (and
a test case be added). What to do about Unicode strings, I don't know.
I agree with Guido that they are officially not supported in cStringIO,
so it would be best to reject them. OTOH, since 2.5.1 already supports
them, another choice would be continue supporting them, in the same way
as they are supported in 2.5.1. Either solution would special-case
Unicode strings.

Regards,
Martin



More information about the Python-Dev mailing list