7 """Return (params, method) from request body."""
10 return xmlrpclib
.loads(cherrypy
.request
.body
.read())
12 return ('ERROR PARAMS', ), 'ERRORMETHOD'
15 def patched_path(path
):
16 """Return 'path', doctored for RPC."""
17 if not path
.endswith('/'):
19 if path
.startswith('/RPC2/'):
20 # strip the first /rpc2
25 def _set_response(body
):
26 # The XML-RPC spec (http://www.xmlrpc.com/spec) says:
27 # "Unless there's a lower-level error, always return 200 OK."
28 # Since Python's xmlrpclib interprets a non-200 response
29 # as a "Protocol Error", we'll just return 200 every time.
30 response
= cherrypy
.response
31 response
.status
= '200 OK'
33 response
.headers
['Content-Type'] = 'text/xml'
34 response
.headers
['Content-Length'] = len(body
)
37 def respond(body
, encoding
='utf-8', allow_none
=0):
38 from xmlrpclib
import Fault
, dumps
39 if not isinstance(body
, Fault
):
41 _set_response(dumps(body
, methodresponse
=1,
43 allow_none
=allow_none
))
45 def on_error(*args
, **kwargs
):
46 body
= str(sys
.exc_info()[1])
47 from xmlrpclib
import Fault
, dumps
48 _set_response(dumps(Fault(1, body
)))