summaryrefslogtreecommitdiff
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_xmlrpc.py9
-rw-r--r--Lib/xmlrpclib.py16
2 files changed, 22 insertions, 3 deletions
diff --git a/Lib/test/test_xmlrpc.py b/Lib/test/test_xmlrpc.py
index 64d8fe86bc..ccc1b602ec 100644
--- a/Lib/test/test_xmlrpc.py
+++ b/Lib/test/test_xmlrpc.py
@@ -86,6 +86,15 @@ class XMLRPCTestCase(unittest.TestCase):
s = xmlrpclib.dumps((new_d,), methodresponse=True)
self.assert_(isinstance(s, str))
+ def test_newstyle_class(self):
+ class T(object):
+ pass
+ t = T()
+ t.x = 100
+ t.y = "Hello"
+ ((t2,), dummy) = xmlrpclib.loads(xmlrpclib.dumps((t,)))
+ self.assertEquals(t2, t.__dict__)
+
def test_dump_big_long(self):
self.assertRaises(OverflowError, xmlrpclib.dumps, (2L**99,))
diff --git a/Lib/xmlrpclib.py b/Lib/xmlrpclib.py
index 6fb6c68db5..3864dadc0b 100644
--- a/Lib/xmlrpclib.py
+++ b/Lib/xmlrpclib.py
@@ -630,9 +630,19 @@ class Marshaller:
try:
f = self.dispatch[type(value)]
except KeyError:
- raise TypeError, "cannot marshal %s objects" % type(value)
- else:
- f(self, value, write)
+ # check if this object can be marshalled as a structure
+ try:
+ value.__dict__
+ except:
+ raise TypeError, "cannot marshal %s objects" % type(value)
+ # check if this class is a sub-class of a basic type,
+ # because we don't know how to marshal these types
+ # (e.g. a string sub-class)
+ for type_ in type(value).__mro__:
+ if type_ in self.dispatch.keys():
+ raise TypeError, "cannot marshal %s objects" % type(value)
+ f = self.dispatch[InstanceType]
+ f(self, value, write)
def dump_nil (self, value, write):
if not self.allow_none: