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

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:

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 :-)