xmlrpclib and carriagereturn (\r)

Jonathan Ballet multani at free.fr
Sat Mar 18 14:52:51 CET 2006

Le Sat, 18 Mar 2006 02:17:36 -0800, Ben Cartwright a écrit :

> 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.

[Just replying to this message. See F. Lundh reply too]

> 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. 

We are developping the Windows client. I think my teammates keep \n\r,
which is the defaut line terminator they had when getting string from text
input, and because ".net framework does the right things for you, etc. etc."

> 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.

Well, I thought to use something like that. Currently, we are stucking
with the kind ugly hack you sent in your previous message (replace("\n",
However, now that I know that xmlrpclib handle line terminator correctly
(regarding XML spec. ), I will try to see if we can handle line feed
correctly in our Windows application.
I think it should be the better solution.

Anyway, thanks a lot for your answers (both of them ;)

> --Ben


More information about the Python-list mailing list