[ANN] pyxser-1.2r --- Python-Object to XML serialization module

Daniel Molina Wegener dmw at coder.cl
Mon Aug 24 14:29:48 CEST 2009

Hash: SHA512

Stefan Behnel <stefan_ml at behnel.de>
on Monday 24 August 2009 03:16
wrote in comp.lang.python:

> Daniel Molina Wegener wrote:
>>         * Added encoded serialization of Unicode strings by using
>>         the user defined encoding as is passed to the serialization
>>         functions as enc parameter
>> As you see, now Unicode strings are serialized as encoded byte string
>> by using the encoding that the user pass as enc parameter to the
>> serialization function. This means that Unicode strings are serialized
>> in a human readable form, regarding a better interoperability with
>> other platforms.
> You mean, the whole XML document is serialised with that encoding, right?

Well, if you call pyxser with:

xmldocstr = pyxser.serialize(obj = someobj, enc = "utf-8", depth = 3)

pyxser will serialize someobj into XML document (xmldocstr) using the
utf-8 encoding with a depth of three levels in the object tree. If the
object tree has unicode objects, those objects will be encoded into
utf-8 too. And yes, it means that unicode objects are encoded into the
encoding that the XML document encoding has, and as you say, the whole
XML document has one encoding. There is no mixing of byte encoded strings
with different encodings in the outout document.

When the object is restored, by using pyxser.unserialize:

pyobj = pyxser.unserialize(obj = xmldocstr, enc = "utf-8")

Unicode objects are restored as unicode objects, by decoding the utf-8
strings on the document. Byte string objects are restored as byte string
objects. And the other types of objects are restored as their original

Another issue is the fact that if you have mixed some encodings in byte
strings objects in your object tree, such as iso-8859-1 and utf-8, and
you try to serialize that object, pyxser will output to stdout the 
serialization errors by trying to handle those mixed encodings which are
not regarding the document encoding.

There are some restrictions, if the class of the object is declared on
the __main__ module, pyxser can not handle it... This is a bug but I'm
expecting to solve it in near future.

A depth level of zero (depth = 0) will serialize the complete object
tree with a fixed limit of 50 levels, pyxser can handle cross referenced
objects and circular references.

Sorry if don't answer more questions until we reach the night --- here
in Chile --- the night, I must go to my job right now, and there I don't
have access to usenet or google groups.

> Stefan

Best regards,
- -- 
 .O. | Daniel Molina Wegener   | FreeBSD & Linux
 ..O | dmw [at] coder [dot] cl | Open Standards
 OOO | http://coder.cl/        | FOSS Developer
Version: GnuPG v1.4.9 (FreeBSD)


More information about the Python-list mailing list