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

Alexandre Vassalotti alexandre at peadrop.com
Sun Aug 5 20:48:11 CEST 2007


On 8/5/07, Georg Brandl <g.brandl at gmx.net> wrote:
> 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?
>

The best thing would be add a special case for ascii-only unicode
objects, and keep the old behavior. However, I believe this will be
ugly, especially in O_write. So, it would perhaps be better to simply
stop supporting unicode objects.

-- Alexandre


More information about the Python-Dev mailing list