web developer & system programmer

coder . cl

ramblings and thoughts on programming...


incomming changes for pyxser-1.4

published: 22-12-2009 / updated: 22-12-2009
posted in: programming, projects, python, pyxser
by Daniel Molina Wegener

pyxser, my Python-Object to XML serializer is suffering few changes, but important ones. The main change is the fact that I will add a type map optional parameter for deserialization functions. How should it work?


def create_string_from_string(mystr, myroot):
    return str(mystr)

my_typemap = {'java.lang.String': create_string_from_string,
              'String': create_string_from_string,
              'string': create_string_from_string}

unserialized = pyxser.unserialize(obj = serialized, 
                                  enc = "utf-8", 
                                  typemap = my_typemap)

This will allow you to create the proper instance of non standard objects in Python. For example if there exists a third party class which needs a special instantation, like the ones which are using sockets or files, this will allow you to create the instance with a custom function, specially if the serialized object comes from other languages.

The type map callbacks will be called using my_typemap['maptype'](python_string, root_object), where python_string is the node content as Python String and root_object is the deserialized root object — the pointed by the root element. About the error occurrences, I will clear each error produced inside the type map function, by call PyErr_Clear(), then you must control those errors produced inside your callback, and return Py_None (None) on each one.

I will be writing this feature this week and the weekend, if you want a change over this feature, this is the time to get some feedback. I think that pyxser-1.4r will be launched on 2010-01-01.


one comment to “incomming changes for pyxser-1.4”

  1. [...] you have seen in my last post, I’ve been working on some strong changes on pyxser. Today I’ve released pyxser-1.4r and the announcement [...]

post a comment

XHTML: You can use these tags: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>