xmlrpclib and carriagereturn (\r)

Jonathan Ballet multani at free.fr
Fri Mar 17 17:13:21 EST 2006


Hello,

I have developped a XMLRPC server, which runs under Gnu/Linux with
python2.3.
This server receives method calls from Windows client. The server got some
parameters which are string, which contains carriage return characters,
just after the line feed character; like "bla\n\rbla".


The problem is, xmlrpclib "eats" those carriage return characters when
loading the XMLRPC request, and replace it by "\n". So I got "bla\n\nbla".

When I sent back those parameters to others Windows clients (they are 
doing some kind of synchronisation throught the XMLRPC server), I send 
to them only "\n\n", which makes problems when rendering strings.



It seems that XMLRPC spec doesn't propose to eat carriage return
characters : (from http://www.xmlrpc.com/spec)
"""
What characters are allowed in strings? Non-printable characters? 
Null characters? Can a "string" be used to hold an arbitrary chunk 
of binary data? 

Any characters are allowed in a string except < and &, which are 
encoded as < and &. A string can be used to encode binary 
data.
"""



Here is an example which described the problem :
$ python
Python 2.3.5 (#2, Sep  4 2005, 22:01:42)
[GCC 3.3.5 (Debian 1:3.3.5-13)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import xmlrpclib
>>> 
>>> data = """<?xml version="1.0" encoding="utf-8"?>\n<methodCall>\n
<methodName>testmethod</methodName>\n
<params>\n    <param>\n      <value>\n        
<string>bla\n\rbla\n\r	bla</string>\n      </value>\n    </param>\n 
</params>\n</methodCall>"""
>>>
>>> xmlrpclib.loads(data)
(('bla\n\nbla\n\n\tbla',), u'testmethod')
>>> 

 ... whereas I expected to have (('bla\n\rbla\n\r\tbla',), u'testmethod')


It seems to be a rather strange comportement from xmlrpclib. Is it known ?
So, what happens here ? How could I solve this problem ?

Thanks for any answers,
Jonathan





More information about the Python-list mailing list