Any reason why cStringIO in 2.5 behaves different from 2.4?

Stefan Scholl stesch at no-spoon.de
Thu Jul 26 13:56:40 CEST 2007


Stefan Behnel <stefan.behnel-n05pAM at web.de> wrote:
> Stefan Scholl wrote:
>> After an hour searching for a potential bug in XML parsing
>> (PyXML), after updating from 2.4 to 2.5, I found this one:
>> 
>> $ python2.5
>> Python 2.5 (release25-maint, Dec  9 2006, 14:35:53)
>> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-20)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import StringIO
>>>>> x = StringIO.StringIO(u"m\xf6p")
>>>>> import cStringIO
>>>>> x = cStringIO.StringIO(u"m\xf6p")
>> Traceback (most recent call last):
>>   File "<stdin>", line 1, in <module>
>> UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in position 1: ordinal not in range(128)
>> $ python
>> Python 2.4.4 (#2, Apr  5 2007, 20:11:18)
>> [GCC 4.1.2 20061115 (prerelease) (Debian 4.1.1-21)] on linux2
>> Type "help", "copyright", "credits" or "license" for more information.
>>>>> import StringIO
>>>>> x = StringIO.StringIO(u"m\xf6p")
>>>>> import cStringIO
>>>>> x = cStringIO.StringIO(u"m\xf6p")
>> 
>> 
>> OK, that's why my code was fine with Python 2.4 and breaks with
>> 2.5.
> 
> It wasn't fine with 2.4 either:

Worked in my test, a few lines above ...

> 
> """
> Unlike the memory files implemented by the StringIO module, those provided by
> this module are not able to accept Unicode strings that cannot be encoded as
> plain ASCII strings.
> """
> 
> http://docs.python.org/lib/module-cStringIO.html
> 
> Read the docs...

Well, http://docs.python.org/lib/module-xml.sax.html is missing
the fact, that I can't use Unicode with parseString().

This parseString() uses cStringIO.



-- 
Web (en): http://www.no-spoon.de/ -*- Web (de): http://www.frell.de/



More information about the Python-list mailing list