Re: xmlrpclib and carriagereturn (\r)



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.

Did you develop the Windows client, too? If so, the client-side fix is
trivial: replace \n with \r\n in all renderable strings. Or update
both the client and the server to encode the strings, also trivial
using the base64 module.

If not, and you're in the unfortunate position of being forced to
support buggy third-party clients, read on.

It seems that XMLRPC spec doesn't propose to eat carriage return
characters : (from http://www.xmlrpc.com/spec)
(snip)
It seems to be a rather strange comportement from xmlrpclib. Is it known ?
So, what happens here ? How could I solve this problem ?

The XMLRPC spec doesn't say anything about CRs one way or the other.
Newline handling is necessarily left to the XML parser implementation.
In Python's case, xmlrpclib uses the xml.parsers.expat module, which
reads universal newlines and writes Unix-style newlines (\n). There's
no option to disable this feature.

You could modify xmlrpclib to use a different parser, but it would be
much easier to just hack the XML response right before it's sent out.
I'm assuming you used the SimpleXMLRPCServer module. Example:

from SimpleXMLRPCServer import *

class MyServer(SimpleXMLRPCServer):
def _marshaled_dispatch(self, data, dm=None):
response = SimpleXMLRPCDispatcher._marshaled_dispatch(self,
data, dm)
return response.replace('\n', '\r\n')

server = MyServer(('localhost', 8000))
server.register_introspection_functions()
server.register_function(lambda x: x, 'echo')
server.serve_forever()

Hope that helps,
--Ben

.



Relevant Pages

  • Re: OS Authentication with winXP client Linux Server
    ... OS Authentication does actually work on clients aswell. ... SQLNET.AUTHENTICATION_SERVICES= on both the server and the ... authentication from Windows clients and it works quite well. ... it's no wonder "Windows clients authenticate without issue": ...
    (comp.databases.oracle.server)
  • Re: OS Authentication with winXP client Linux Server
    ... OS Authentication does actually work on clients aswell. ... SQLNET.AUTHENTICATION_SERVICES= on both the server and the ... authentication from Windows clients and it works quite well. ...
    (comp.databases.oracle.server)
  • Re: OS Authentication with winXP client Linux Server
    ... OS Authentication does actually work on clients aswell. ... SQLNET.AUTHENTICATION_SERVICES= on both the server and the ... authentication from Windows clients and it works quite well. ...
    (comp.databases.oracle.server)
  • TPCServer and xdrlib
    ... I would like to do session management (authentication, then store session info on server site) which is also hard with xmlrpc. ... the server should not receive anything from the clients that is dangerous. ... Is there another higher level framework that I can try? ...
    (comp.lang.python)
  • Yep!... Still a Newbie
    ... I set up a pc at home as a file server and printer server (to print from both ... FreeBSD/ Linux clients as well as windows clients), and thanks to a lot of ...
    (freebsd-newbies)