[Python-Dev] CVS: python/dist/src/Lib xmlrpclib.py,1.11,1.12

Martin v. Loewis martin@loewis.home.cs.tu-berlin.de
Wed, 10 Oct 2001 22:59:09 +0200


> It seems like it ought to handle subclasses of builtin classes like
> string.

That's desirable, indeed. I think Skip's concern is primarily how to
implement that; that is my concern, atleast.

I can think of an implementation that replaces

    def __dump(self, value):
        try:
            f = self.dispatch[type(value)]
        except KeyError:
            raise TypeError, "cannot marshal %s objects" % type(value)
        else:
            f(self, value)

with

    def __dump(self, value):
        for t in type(value).__mro__:
            try:
                f = self.dispatch[t]
            except KeyError:
                pass
            else:
                f(self, value)
                return
        raise TypeError, "cannot marshal %s objects" % type(value)

That has several draw-backs, though:

- it does not work with Py 1.5, which /F still requires for xmlrpclib,
- it may give ambiguous results, in case an object could act as
  either of the XML-RPC types (it works deterministic, but may
  still give the undesired outcome)
- it doesn't work for classic classes and instances

Can you come up with anything better?

Regards,
Martin

P.S. I don't know whether usage of __mro__ itself would be a bug or a
feature. I certainly take pride in coming up with that idea :-)