summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Brewer <fumanchu@aminus.org>2008-04-27 01:19:53 +0000
committerRobert Brewer <fumanchu@aminus.org>2008-04-27 01:19:53 +0000
commit9799e60b9016490133edf22c7874255a8ce4508a (patch)
treee58e91b9ead89c0004702bcb7cbe36c9dc60ddba
parent9c0f2371d4b65537c31e19458d6df7621f7525df (diff)
downloadcherrypy-9799e60b9016490133edf22c7874255a8ce4508a.tar.gz
Test and fix for #791 (cherrypy.lib.xmlrpc.respond cannot marshal xmlrpclib.Fault objects).
-rw-r--r--cherrypy/lib/xmlrpc.py4
-rw-r--r--cherrypy/test/test_xmlrpc.py15
2 files changed, 17 insertions, 2 deletions
diff --git a/cherrypy/lib/xmlrpc.py b/cherrypy/lib/xmlrpc.py
index 959feba9..c95970f2 100644
--- a/cherrypy/lib/xmlrpc.py
+++ b/cherrypy/lib/xmlrpc.py
@@ -36,7 +36,9 @@ def _set_response(body):
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))
diff --git a/cherrypy/test/test_xmlrpc.py b/cherrypy/test/test_xmlrpc.py
index 29689bee..bc81989c 100644
--- a/cherrypy/test/test_xmlrpc.py
+++ b/cherrypy/test/test_xmlrpc.py
@@ -60,6 +60,10 @@ def setup_server():
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={'/': {
@@ -153,7 +157,7 @@ class XmlRpcTest(helper.CPWebCase):
"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:
@@ -163,6 +167,15 @@ class XmlRpcTest(helper.CPWebCase):
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__':