Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

StringIO / cStringIO inconsistency with unicode #44699

Closed
arigo mannequin opened this issue Mar 11, 2007 · 3 comments
Closed

StringIO / cStringIO inconsistency with unicode #44699

arigo mannequin opened this issue Mar 11, 2007 · 3 comments
Labels
stdlib Python modules in the Lib dir

Comments

@arigo
Copy link
Mannequin

arigo mannequin commented Mar 11, 2007

BPO 1678411
Nosy @loewis, @arigo

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2007-03-12.00:04:16.000>
created_at = <Date 2007-03-11.18:07:00.000>
labels = ['invalid', 'library']
title = 'StringIO / cStringIO inconsistency with unicode'
updated_at = <Date 2007-03-12.00:04:16.000>
user = 'https://github.com/arigo'

bugs.python.org fields:

activity = <Date 2007-03-12.00:04:16.000>
actor = 'arigo'
assignee = 'none'
closed = True
closed_date = None
closer = None
components = ['Library (Lib)']
creation = <Date 2007-03-11.18:07:00.000>
creator = 'arigo'
dependencies = []
files = []
hgrepos = []
issue_num = 1678411
keywords = []
message_count = 3.0
messages = ['31490', '31491', '31492']
nosy_count = 2.0
nosy_names = ['loewis', 'arigo']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = None
status = 'closed'
superseder = None
type = None
url = 'https://bugs.python.org/issue1678411'
versions = []

@arigo
Copy link
Mannequin Author

arigo mannequin commented Mar 11, 2007

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.

@arigo arigo mannequin closed this as completed Mar 11, 2007
@arigo arigo mannequin added invalid stdlib Python modules in the Lib dir labels Mar 11, 2007
@arigo arigo mannequin closed this as completed Mar 11, 2007
@arigo arigo mannequin added invalid stdlib Python modules in the Lib dir labels Mar 11, 2007
@loewis
Copy link
Mannequin

loewis mannequin commented Mar 11, 2007

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.

@arigo
Copy link
Mannequin Author

arigo mannequin commented Mar 12, 2007

I missed the documentation, which already desribes
this difference.

@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
stdlib Python modules in the Lib dir
Projects
None yet
Development

No branches or pull requests

0 participants