| 492 | return result |
| 493 | |
| 494 | def __dump(self, value, write): |
| 495 | try: |
| 496 | f = self.dispatch[type(value)] |
| 497 | except KeyError: |
| 498 | # check if this object can be marshalled as a structure |
| 499 | if not hasattr(value, '__dict__'): |
| 500 | raise TypeError("cannot marshal %s objects" % type(value)) |
| 501 | # check if this class is a sub-class of a basic type, |
| 502 | # because we don't know how to marshal these types |
| 503 | # (e.g. a string sub-class) |
| 504 | for type_ in type(value).__mro__: |
| 505 | if type_ in self.dispatch.keys(): |
| 506 | raise TypeError("cannot marshal %s objects" % type(value)) |
| 507 | # XXX(twouters): using "_arbitrary_instance" as key as a quick-fix |
| 508 | # for the p3yk merge, this should probably be fixed more neatly. |
| 509 | f = self.dispatch["_arbitrary_instance"] |
| 510 | f(self, value, write) |
| 511 | |
| 512 | def dump_nil (self, value, write): |
| 513 | if not self.allow_none: |