[XML-SIG] WDDX for Python

Paul Prescod paul@prescod.net
Thu, 17 Dec 1998 16:07:03 -0600


The serializer is a little bit more tricky. We should probably discuss
what the right thing here is.

Gabe Wachob wrote:
> 
> Well, I wonder aloud whether its possible (or worth attempting) to write a
> serializer for arbitrary python objects. 

Depends on your definition:

 * arbitrary Python instances and a finite list of builtin types? Yes.
 * transient objects such as file handles and TKinter windows? No.
 * what about objects like compiled regular expressions and AST trees?

According to the Pickle documentation, no C built-ins can be pickled
except the most basic types. I'm surprised that there isn't any way to
make user-defined built-in types (e.g. a C-programmed DOM-node) picklable.
Anyone know more about this? The docs say:

> Classes can further influence how their instances are pickled -- if 
> the class defines the method __getstate__(), it is called and the 
> return state is pickled as the contents for the instance, 

Does this really apply ONLY to classes, or also to built-in types?

Another issue is whether we try to be smart about Python instances that
represent lists of things and mappings. Do we map them to lists and
structs or not?

> Also, I'm not sure what sort of Python objects or data types would map to
> a timeDate WDDX element.

This is a problem I have been discussing in the newsgroup. We would have
to define a WDDX time object and Python programmers could convert
seconds-past-the-epoch integers or time tuple-lists to time objects:
wddx.time( time.gmtime()). It would be nicer to have 1.5.2 contain some
tiny time class but I haven't got any feedback to indicate that that will
happen, so shipping our own is the next best thing.

> I'm thinking that the best thing to do would be to create a WDDXCreator
> object that would work on WDDXObjects (ie WDDXStruct, WDDXdateTime, etc).

That's fine for date/time and for the top-level packets, but you don't
want to force the programmer to convert every item in a list (e.g.) to a
WDDX type. That would be onerous.

> I don't know -- looking at how other languages like Java do it would be
> instructional..

I think that Javascript is a better guide because it is a more dynamic
language like Python.

 Paul Prescod  - ISOGEN Consulting Engineer speaking for only himself
 http://itrc.uwaterloo.ca/~papresco

"Sports utility vehicles are gated communities on wheels" - Anon