[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


-----BEGIN PGP SIGNED MESSAGE-----
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
type.

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
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (FreeBSD)

iQIcBAEBCgAGBQJKkoe8AAoJEHxqfq6Y4O5Na3gP/R2BTdmZpUPn8PrsPhMPaKLf
dmAUAyQ2Ukj1461eiYGAa1zly5bz/rKV8UJXq6zp0cFIIimBHWCYkFlbtCIdCl5k
qclT6y3d5N9/VggZi92ICK4xFe4CCOzLeJCaYkBcVgvbpks9oRJwlS9LrTZAMdOw
WdnaUdNadj2lRcXHwqV7uk5D5CwBdNujgpp+7vJXZbEnPD9diXEbPDUeHznn7cEa
2zwtGK3+kyPEkLpS5F+zE2iPUQK+HOw4r1s7kow9mSUU0n3p+gJj9J0NtBKDa92d
hXGQ6M52jtoyZlv0bWJl8R1YQLnezvNDMu9F/NqB79wmLhJqIZm3Py57rtIaD96J
2a7BN/LcM8fhs+dgTlt6538EKoM5Jj+gv+birSIUwxKFChRpGsj7229cmTzjQc7q
mcXlXPa6aknOWxVlhPSpGDSbZ+HpqGH7s9cOHAAuUt+WRcaafeRpy7K3BXJ+AaJ6
Rz69j2nsOgqGufLlBiDf9aRIrX3A47eE0DGZLwVuolValgmBhgedn43T4XH85wrE
BfXERoIrIlMS8hmcxs6Ao6TayLHmaZjSVaLmP+qsN9qHCs8hCbQBNBfaU1vrsM2u
nppo/+yGepLGZSW35yA8ha7m3RAX1HTyHcKrPcrbTmK5IVjVWjHRbTz4XcqNt1v6
5prWXP8WUIfIr4E2112J
=JjU5
-----END PGP SIGNATURE-----



More information about the Python-list mailing list