1. cherrypy
  2. CherryPy

Commits

Robert Brewer  committed 1cedf90

Test and fix for #791 (cherrypy.lib.xmlrpc.respond cannot marshal xmlrpclib.Fault objects).

  • Participants
  • Parent commits ff59eb9
  • Branches default

Comments (0)

Files changed (2)

File cherrypy/lib/xmlrpc.py

View file
 
 def respond(body, encoding='utf-8', allow_none=0):
     import xmlrpclib
-    _set_response(xmlrpclib.dumps((body,), methodresponse=1,
+    if not isinstance(body, xmlrpclib.Fault):
+        body = (body,)
+    _set_response(xmlrpclib.dumps(body, methodresponse=1,
                                   encoding=encoding,
                                   allow_none=allow_none))
 

File cherrypy/test/test_xmlrpc.py

View file
             return num * 2
         test_argument_passing.exposed = True
 
+        def test_returning_Fault(self):
+            return xmlrpclib.Fault(1, "custom Fault response")
+        test_returning_Fault.exposed = True
+
     root = Root()
     root.xmlrpc = XmlRpc()
     cherrypy.tree.mount(root, config={'/': {
                                              "for *: 'dict' and 'int'"))
         else:
             self.fail("Expected xmlrpclib.Fault")
-
+        
         # http://www.cherrypy.org/ticket/533
         # if a method is not found, an xmlrpclib.Fault should be raised
         try:
             self.assertEqual(x.faultString, 'method "non_method" is not supported')
         else:
             self.fail("Expected xmlrpclib.Fault")
+        
+        # Test returning a Fault from the page handler.
+        try:
+            proxy.test_returning_Fault()
+        except Exception, x:
+            self.assertEqual(x.__class__, xmlrpclib.Fault)
+            self.assertEqual(x.faultString, ("custom Fault response"))
+        else:
+            self.fail("Expected xmlrpclib.Fault")
 
 
 if __name__ == '__main__':