[ python-Bugs-1678411 ] StringIO / cStringIO inconsistency with unicode
SourceForge.net
noreply at sourceforge.net
Mon Mar 12 01:04:16 CET 2007
Bugs item #1678411, was opened at 2007-03-11 18:07
Message generated for change (Comment added) made by arigo
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1678411&group_id=5470
Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Library
Group: None
>Status: Closed
>Resolution: Invalid
Priority: 5
Private: No
Submitted By: Armin Rigo (arigo)
Assigned to: Nobody/Anonymous (nobody)
Summary: StringIO / cStringIO inconsistency with unicode
Initial Comment:
When trying to write unicode strings into a
StringIO.StringIO() or a cStringIO.StringIO()
file, different things occur. (This causes
a failing test in the "mako" project if
cStringIO is not available.) Compare the
following with StringIO or with cStringIO:
f = StringIO()
f.write("\xC0")
f.write(u"hello")
print f.getvalue()
With cStringIO, unicode strings are
immediately encoded as ascii and the
getvalue() returns '\xC0hello'. With
StringIO, on the other hand, the
getvalue() crashes in a ''.join()
trying to convert 'xC0' to unicode.
Normal file() objects follow the same
behavior as cStringIO, so my guess is
that StringIO.py is wrong here.
----------------------------------------------------------------------
>Comment By: Armin Rigo (arigo)
Date: 2007-03-12 00:04
Message:
Logged In: YES
user_id=4771
Originator: YES
I missed the documentation, which already desribes
this difference.
----------------------------------------------------------------------
Comment By: Martin v. Löwis (loewis)
Date: 2007-03-11 18:31
Message:
Logged In: YES
user_id=21627
Originator: NO
It's intentional that they behave differently. StringIO supports Unicode
strings, cStringIO doesn't. This means that you can build up a large
Unicode string with StringIO, but not with cStringIO.
What should happen when you mix them is debatable.
----------------------------------------------------------------------
You can respond by visiting:
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1678411&group_id=5470
More information about the Python-bugs-list
mailing list