This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: xmlrpclib won't marshal new types
Type: Stage:
Components: Library (Lib) Versions: Python 2.2
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: akuchling, jait, phr, skip.montanaro
Priority: normal Keywords:

Created on 2001-10-10 19:36 by skip.montanaro, last changed 2022-04-10 16:04 by admin. This issue is now closed.

Messages (8)
msg6893 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2001-10-10 19:36
Maybe xmlrpclib should be modified to allow it to marshal subclasses of builtin types (ints, strings, etc).  Here's a simple example that demonstrates that it currently won't work with a subclass of str:

>>> import xmlrpclib
>>> class MyString(str):
...   pass
... 
>>> s = MyString("sdfsdfsdf")
>>> s
'sdfsdfsdf'
>>> s.__class__
<class '__main__.MyString'>
>>> xmlrpclib.dumps((s,))
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.2/xmlrpclib.py", line 752, in dumps
    data = m.dumps(params)
  File "/usr/local/lib/python2.2/xmlrpclib.py", line 448, in dumps
    self.__dump(v)
  File "/usr/local/lib/python2.2/xmlrpclib.py", line 459, in __dump
    raise TypeError, "cannot marshal %s objects" % type(value)
TypeError: cannot marshal <class '__main__.MyString'> objects
msg6894 - (view) Author: paul rubin (phr) Date: 2001-10-19 14:16
Logged In: YES 
user_id=72053

1) anything but the base types aren't part of the
xmlrpc spec

2) be very very careful about unmarshalling any but basic
objects, because of possible security attacks.  See
item 471893 for some more info.
msg6895 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2001-10-19 16:00
Logged In: YES 
user_id=44345

I don't think #471893 applies here.  While xmlrpclib will marshal the dict of an instance object, it is seen as a marshalled dict at the other end and would be unmarshalled as a dict without special effort on the part of the programmer.  XML-RPC only supports a small, fixed set of types: ints, booleans, floats, date-time strings, lists and dicts.

My concern with allowing XML-RPC marshalling of a subclass of strings (for example), is that the programmer might be led to believe their extra instance attributes would be marshalled as well.  While I submitted this bug report, I was simply recording someone else's observation.
msg6896 - (view) Author: A.M. Kuchling (akuchling) * (Python committer) Date: 2002-03-08 18:33
Logged In: YES 
user_id=11375

Maybe we should just document that xmlrpclib won't handle 
subclasses?
msg6897 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2002-03-17 23:17
Logged In: YES 
user_id=44345

closing this bug report.  Perhaps in the future 
subclasses of builtins could be marshalled, but extra
instance attributes wouldn't be.

libxmlrpclib.tex v 1.8 adds a note about this limitation
as suggested by Andrew.

msg123870 - (view) Author: Jari Tenhunen (jait) Date: 2010-12-13 11:48
How about revisiting this one? Although this behavior/limitation is documented, it is quite surprising to the user. FWIW, (simple)json module serializes subclasses of builtin types just as expected.
msg123873 - (view) Author: Skip Montanaro (skip.montanaro) * (Python triager) Date: 2010-12-13 13:30
> FWIW, (simple)json module serializes subclasses of builtin types
> just as expected.

Does that round trip properly?  For instance, if you serialize an
instance of a list subclass does it unserialize as a list instance
or as the subclass?

Perhaps JSON has some way of supporting a user-defined set of types.
XML-RPC has no way to do that, and feeding in an instance of a
subtype then getting the base type out on the other end was deemed
a bad thing.
msg123874 - (view) Author: Jari Tenhunen (jait) Date: 2010-12-13 13:46
>> FWIW, (simple)json module serializes subclasses of builtin types
>> just as expected.
> Does that round trip properly?  For instance, if you serialize an
> instance of a list subclass does it unserialize as a list instance
> or as the subclass?

You get a list instance. So, at least without any additional work it does not round trip symmetrically. But IMO this is actually the expected result; subclasses of string should serialize like strings, subclasses of list like lists etc. And when you unserialize those without any additional magic, you get the builtin types, not the subclasses.
History
Date User Action Args
2022-04-10 16:04:31adminsetgithub: 35307
2010-12-13 13:46:14jaitsetmessages: + msg123874
2010-12-13 13:30:23skip.montanarosetmessages: + msg123873
2010-12-13 11:48:38jaitsetnosy: + jait
messages: + msg123870
2001-10-10 19:36:46skip.montanarocreate