[Lxml-checkins] r39386 - in lxml/trunk: . src/lxml src/lxml/tests

scoder at codespeak.net scoder at codespeak.net
Sun Feb 25 14:57:43 CET 2007


Author: scoder
Date: Sun Feb 25 14:57:39 2007
New Revision: 39386

Modified:
   lxml/trunk/CHANGES.txt
   lxml/trunk/src/lxml/objectify.pyx
   lxml/trunk/src/lxml/tests/test_objectify.py
Log:
support for pickeling ObjectifiedElement's

Modified: lxml/trunk/CHANGES.txt
==============================================================================
--- lxml/trunk/CHANGES.txt	(original)
+++ lxml/trunk/CHANGES.txt	Sun Feb 25 14:57:39 2007
@@ -8,6 +8,8 @@
 Features added
 --------------
 
+* Support for pickeling ``objectify.ObjectifiedElement`` objects to XML
+
 * ``update()`` method on Element.attrib
 
 * Optimised replacement for libxml2's _xmlReconsiliateNs(). This allows lxml

Modified: lxml/trunk/src/lxml/objectify.pyx
==============================================================================
--- lxml/trunk/src/lxml/objectify.pyx	(original)
+++ lxml/trunk/src/lxml/objectify.pyx	Sun Feb 25 14:57:39 2007
@@ -984,6 +984,20 @@
 
 
 ################################################################################
+# Pickle support
+
+cdef void _setupPickle(reduceFunction):
+    import copy_reg
+    copy_reg.constructor(fromstring)
+    copy_reg.pickle(ObjectifiedElement, reduceFunction, fromstring)
+
+def pickleReduce(obj):
+    return (fromstring, (etree.tostring(obj),))
+
+_setupPickle(pickleReduce)
+del pickleReduce
+
+################################################################################
 # Element class lookup
 
 cdef class ObjectifyElementClassLookup(ElementClassLookup):

Modified: lxml/trunk/src/lxml/tests/test_objectify.py
==============================================================================
--- lxml/trunk/src/lxml/tests/test_objectify.py	(original)
+++ lxml/trunk/src/lxml/tests/test_objectify.py	Sun Feb 25 14:57:39 2007
@@ -842,6 +842,18 @@
              'root.{objectified}c1.{}c2'],
             root.c1.descendantpaths('root'))
 
+    def test_pickle(self):
+        import pickle
+
+        root = self.XML(xml_str)
+        out = StringIO()
+        pickle.dump(root, out)
+
+        new_root = pickle.loads(out.getvalue())
+        self.assertEquals(
+            etree.tostring(new_root),
+            etree.tostring(root))
+
 
 def test_suite():
     suite = unittest.TestSuite()


More information about the lxml-checkins mailing list