[ python-Bugs-1576443 ] cStringIO misbehaving with unicode

SourceForge.net noreply at sourceforge.net
Fri Oct 13 10:40:35 CEST 2006


Bugs item #1576443, was opened at 2006-10-13 01:40
Message generated for change (Tracker Item Submitted) made by Item Submitter
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1576443&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: Python 2.4
Status: Open
Resolution: None
Priority: 5
Submitted By: Yang Zhang (yangzhang)
Assigned to: Nobody/Anonymous (nobody)
Summary: cStringIO misbehaving with unicode

Initial Comment:
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()

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1576443&group_id=5470


More information about the Python-bugs-list mailing list