xmlrpclib and carriagereturn (\r)

Ben Cartwright bencvt at gmail.com
Sat Mar 18 11:17:36 CET 2006


Jonathan Ballet wrote:
> 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.


Whoops, just realized we're talking about "\n\r" here, not "\r\n".
Most of my previous reply doesn't apply to your situation, then.

As far as Python's expat parser is concerned, "\n\r" is two newlines:
one Unix-style and one Mac-style.  It correctly (per XML specs)
normalizes both to Unix-style.

Is "\n\r" being used as a newline by your Windows clients, or is it a
control code?  If the former, I'd sure like to know why.  If the
latter, then you're submitting binary data and you shouldn't be using
<string> to begin with.  Try <base64>.

If worst comes to worst and you have to stick with sending "\n\r"
intact in a <string> param, you'll need to modify xmlrpclib to use a
different (and technically noncompliant) XML parser.  Here's an ugly
hack to do that out of the box:

# In your server code:
import xmlrpclib
# This forces xmlrpclib to fall back on the obsolete xmllib module:
xmlrpclib.ExpatParser = None

xmllib doesn't normalize newlines, so it's noncompliant.  But this is
actually what you want.

--Ben




More information about the Python-list mailing list