This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: cStringIO misbehaving with unicode
Type: Stage:
Components: Library (Lib) Versions: Python 2.4
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: georg.brandl, yangzhang
Priority: normal Keywords:

Created on 2006-10-13 08:40 by yangzhang, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg30240 - (view) Author: Yang Zhang (yangzhang) Date: 2006-10-13 08:40
The bug is the following:

StringIO.StringIO(u'abc').getvalue() !=
cStringIO.StringIO(u'abc').getvalue()

It all started with the following code:

# client.py
 
import cPickle as cp
import xmlrpclib as x
p=x.ServerProxy('http://localhost:8082')
msg=u'abc'
print msg
print len(msg)
p.foo(x.Binary(msg))
 
# client output
 
abc
3
 
# server.py
 
from twisted.web import server, xmlrpc
 
class WikiXmlRpc(xmlrpc.XMLRPC):
    def xmlrpc_foo(self, x):
        print x.data
        print len(x.data)
        return 0
 
if __name__ == "__main__":
    import sys
    from twisted.internet import reactor
    siteRoot = WikiXmlRpc()
    reactor.listenTCP(8082, server.Site(siteRoot))
    reactor.run( )
 
# server output
 
abc
12

I wanted both hosts to agree on the length, so I
started digging to find out what was up. Some time
later....

<alus> zeeeee: you found a bug in xmlrpclib
<alus> zeeeee: it's using cStringIO in a place where it
can't
<alus> odd. cStringIO does not react to unicode in a
sane way
<alus> cStringIO.StringIO(u'abc').getvalue()
<alus> #=> 'a\x00b\x00c\x00'
...
<alus> zeeeee: the heart of the matter is that
StringIO.StringIO(u'abc').getvalue() !=
cStringIO.StringIO(u'abc').getvalue()
msg30241 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2006-10-13 19:24
Logged In: YES 
user_id=849994

This was fixed with bug #1548891 a short while ago.
History
Date User Action Args
2022-04-11 14:56:20adminsetgithub: 44126
2006-10-13 08:40:34yangzhangcreate