[Medusa-dev] Patch for medusa's XML-RPC handler

Stephane Bortzmeyer bortzmeyer@nic.fr
Fri, 26 Jul 2002 10:04:44 +0200


---------------------- multipart/mixed attachment
Hello,

Thank you for taking over the maintenance of this very useful tool. I
send you a small patch which fixes two things in Medusa's XML-RPC
handler, xmlrpc_handler.py:

1) it adds the Content-length header which is mandatory, according to
the XML-RPC specification. (The current version of Medusa fails
validation, see <URL:http://www.dscpl.com.au/xmlrpc-debugger.php>)

2) it does not wrap the exception in an xmlrpllib.Fault if the
exception is already such a Fault. It allows applications to raise
their own xmlrpllib.Fault, with their own faultCode.

Thanks again and good luck.













---------------------- multipart/mixed attachment
*** /usr/lib/python2.1/site-packages/medusa/xmlrpc_handler.py	Wed Mar 20 18:37:48 2002
--- ./xmlrpc_handler.py	Fri Jul 26 09:59:30 2002
***************
*** 5,13 ****
  
  # Based on "xmlrpcserver.py" by Fredrik Lundh (fredrik@pythonware.com)
  
! VERSION = "$Id: xmlrpc_handler.py,v 1.4 2002/03/20 17:37:48 amk Exp $"
  
! import http_server
  import xmlrpclib
  
  import string
--- 5,15 ----
  
  # Based on "xmlrpcserver.py" by Fredrik Lundh (fredrik@pythonware.com)
  
! # This version modified and maintained byStephane Bortzmeyer <bortzmeyer@nic.fr>
  
! VERSION = "$Id: xmlrpc_handler.py,v 1.2 2002/07/26 07:59:30 bortzmeyer Exp $"
! 
! from medusa import http_server
  import xmlrpclib
  
  import string
***************
*** 38,47 ****
                  response = self.call (method, params)
                  if type(response) != type(()):
                      response = (response,)
              except:
!                 # report exception back to server
                  response = xmlrpclib.dumps (
!                         xmlrpclib.Fault (1, "%s:%s" % (sys.exc_type, sys.exc_value))
                          )
              else:
                  response = xmlrpclib.dumps (response, methodresponse=1)
--- 40,51 ----
                  response = self.call (method, params)
                  if type(response) != type(()):
                      response = (response,)
+             except xmlrpclib.Fault, e:
+                 response = xmlrpclib.dumps (sys.exc_value)
              except:
!                 # report exception back to client
                  response = xmlrpclib.dumps (
!                         xmlrpclib.Fault (500, "%s:%s" % (sys.exc_type, sys.exc_value))
                          )
              else:
                  response = xmlrpclib.dumps (response, methodresponse=1)
***************
*** 51,56 ****
--- 55,61 ----
          else:
              # got a valid XML RPC response
              request['Content-Type'] = 'text/xml'
+             request['Content-Length'] = len(str(response))
              request.push (response)
              request.done()
  

---------------------- multipart/mixed attachment--