From 1bb6266c40636838c357062918e4ba0de2670e5b Mon Sep 17 00:00:00 2001 From: Uri Okrent Date: Thu, 9 Jun 2016 10:52:42 -0400 Subject: [PATCH] xmlrpc.client: make Fault pickleable Fault wasn't passing it's arguments up to the BaseException constructor which sets the `args` attribute. As a result attempting to unpickle a Fault would raise: TypeError: __init__() missing 2 required positional arguments: 'faultCode' and 'faultString' Signed-off-by: Uri Okrent --- Lib/test/test_xmlrpc.py | 9 +++++++++ Lib/xmlrpc/client.py | 2 +- 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py index f2fdc44..be593eb 100644 --- a/Lib/test/test_xmlrpc.py +++ b/Lib/test/test_xmlrpc.py @@ -13,6 +13,7 @@ import re import io import contextlib from test import support +import pickle try: import gzip @@ -316,6 +317,14 @@ class FaultTestCase(unittest.TestCase): s = xmlrpclib.Marshaller().dumps(f) self.assertRaises(xmlrpclib.Fault, xmlrpclib.loads, s) + def test_pickle_fault(self): + f = xmlrpclib.Fault(42, 'Test Fault') + s = pickle.dumps(f) + newf = pickle.loads(s) + self.assertIsInstance(newf, xmlrpclib.Fault) + self.assertEqual(newf.faultCode, 42) + self.assertEqual(newf.faultString, 'Test Fault') + def test_dotted_attribute(self): # this will raise AttributeError because code don't want us to use # private methods diff --git a/Lib/xmlrpc/client.py b/Lib/xmlrpc/client.py index 581a3b9..c850d47 100644 --- a/Lib/xmlrpc/client.py +++ b/Lib/xmlrpc/client.py @@ -233,7 +233,7 @@ class ResponseError(Error): class Fault(Error): """Indicates an XML-RPC fault package.""" def __init__(self, faultCode, faultString, **extra): - Error.__init__(self) + Error.__init__(self, faultCode, faultString, **extra) self.faultCode = faultCode self.faultString = faultString def __repr__(self): -- 2.8.2