I’ve released pyxser-0.1r a few days ago, I’ve been working on the next release of my python-object serializer. Let’s review what’s next ;)
the serialization functions
serialize(...)
Uses the next keyword argumens:
obj -> python object to serialize
enc -> xml serialization encoding
depth -> node navigation depth
Gets any object defined in a Python module as class as argument
and serializes it as XML. The serialization model is based on the
pyxser DTD 1.0. Objects are serialized as pyxs:obj element, collections
are serialized as pyxs:col element (tuples, lists and dictionaries)
and properties are serialized as pyxs:prop elements.
The serialization algorithm is a O(n) one, this means which the
serializer runs over the object tree just one time and cross
refernces are serialized as XML references through the IDREF
attribute pyxs:ref. Also this serialization method is supposed
to support C14N
The serialization model resides in the pyxser public identifier DTD:
<!DOCTYPE pyxs:obj
PUBLIC '-//coder.cl//DTD pyxser 1.0//EN'
'http://projects.coder.cl/pyxser/dtd/pyxser-1.0.dtd'>
serialize_c14n(...)
Uses the next keyword argumens:
obj -> python object to serialize
enc -> xml serialization encoding
depth -> node navigation depth
esc -> exclusive canonization
com -> with comments
Same as serialize(), but uses C14N canonization, to use exclusive
canonization esc argument must differ from zero and to use comments
com must differ from zero
The documentation refers to two functions, serialize() and serialize_c14n(), both of them have keyword arguments and serializes python objects with an O(n) algorithm. Since it’s creation, pyxser supports cross references, and serializes the object tree once, and creates XML references for duplicated objects, by setting ID and IDREF attributes in the document model. I’ve added the serialize_c14n() function to allow you to use the XML document inside Web Services or similar technologies ;)
the deserialization functions
unserialize(...)
Uses the next keyword argumens:
obj -> the serialized python object
enc -> xml serialization encoding
Takes an XML string as arguments to deserialize it and be converted
back to it's original Python object. The deserialization algorithm
supports automatic module loading, but searches for them in the module
dictionary first to reach the original object type. It needs that the
implied modules can be recheable by Python to get back the objects in
it's original form.
The deserialization algorithm is a O(n) one, this means that forward
references are not supported because the first ocurrence of any object
it's serialized once and then referenced, but not referenced and then
serilized.
Every serilized object is validated against the pyxser DTD 1.0
The deserialization function uses a similar O(n) algorithm and always as a previous task on deserialization, it validates the given document. Not many changes since pyxser-0.1r.
utility functions
getdtd(...)
This function returns the pyxser DTD location in your system as string
validate(...)
Uses the next keyword argumens:
obj -> the serialized python object
enc -> xml serialization encoding
Validates the XML input string against the pyxser DTD 1.0 in your
local filesystem.
xmlcleanup(...)
Calls the cleanup function for the libxml2 parser, be carefull using this
function, and try to use it when the parser really isn't in use.
Well, utility functions can be used in other tasks, we have validate(), to validate serialized objects; getdtd(), to let the environment know where is the pyxser-1.0.dtd file, containing the XML serialization model; and xmlcleanup(), which allows you to cleanup the memory consumed by libxml2 and it’s parser. With the last one, you must be really carefull, since you can be using lxml or another libxml2 instance inside python, and you can fall in a huge mistake by using this function.
If you want all those features, you must download the SVN version or wait untill the pyxser-0.2r version ;)



