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()
|