Now `xml.deserialize' can convert loaded object to any class.

portnov [2009-02-24 20:04:54]
Now `xml.deserialize' can convert loaded object to any class.
Filename
xmlserialize.py
diff --git a/xmlserialize.py b/xmlserialize.py
index 390de1d..f6ca068 100644
--- a/xmlserialize.py
+++ b/xmlserialize.py
@@ -40,7 +40,7 @@ def serialize(ob):
     return r


-def deserialize(text):
+def deserialize(text,cls=None):
     def parse_text(t):
         try:
             return int(t)
@@ -70,7 +70,11 @@ def deserialize(text):
             print "Unknown tag:", node.tag

     xml = etree.parse(StringIO(text))
-    return work(xml.getroot())
+    ob = work(xml.getroot())
+    if cls:
+        return convert(ob,cls)
+    else:
+        return ob

 def convert(ob,cls):
     "Convert object (loaded from xml) to given class"
ViewGit