TypeError: can't pickle StringElement objects
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
lxml |
Fix Released
|
Medium
|
Holger Joukl |
Bug Description
Environment info:
{{{
Ubuntu 9.10
lxml.etree: (2, 2, 4, 0)
libxml used: (2, 7, 5)
libxml compiled: (2, 7, 5)
libxslt used: (1, 1, 24)
libxslt compiled: (1, 1, 24)
}}}
How to reproduce:
{{{
import pickle
from lxml import objectify
pickle.
pickle.
pickle.
pickle.
}}}
Example traceback:
{{{
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/lib/
Pickler(file, protocol).dump(obj)
File "/usr/lib/
self.save(obj)
File "/usr/lib/
rv = reduce(self.proto)
File "/usr/lib/
raise TypeError, "can't pickle %s objects" % base.__name__
TypeError: can't pickle StringElement objects
}}}
Changed in lxml: | |
assignee: | nobody → Holger Joukl (jholg) |
importance: | Undecided → Medium |
status: | New → Confirmed |
Changed in lxml: | |
status: | Confirmed → Fix Committed |
milestone: | none → 2.3 |
Fixed on the trunk:
Committed revision 71085.
Changes:
$ svn diff -rCOMMITTED tests/test_ objectify. py ======= ======= ======= ======= ======= ======= ======= ======= ==== tests/test_ objectify. py (revision 71046) tests/test_ objectify. py (working copy)
etree. tostring( new_tree) ,
etree. tostring( tree))
Index: src/lxml/
=======
--- src/lxml/
+++ src/lxml/
@@ -2328,6 +2328,43 @@
+ def test_pickle_ intelement( self): pickle( '<x>42< /x>') pickle( objectify. DataElement( 42)) floattelement( self): pickle( '<x>42. 0</x>') pickle( objectify. DataElement( 42.0)) strelement( self): pickle( '<x>Pickle me!</x>') pickle( objectify. DataElement( 'Pickle me!')) boolelement( self): pickle( '<x>true< /x>') pickle( '<x>false< /x>') pickle( objectify. DataElement( True)) pickle( objectify. DataElement( False)) noneelement( self): pickle( ''' www.w3. org/2001/ XMLSchema- instance" xsi:nil= "true"/ >''') pickle( objectify. DataElement( None)) stringOrElt, (etree._Element, etree._ ElementTree) ): stringOrElt) loads(out. getvalue( )) new_elt) , elt)) ...
+ self._test_
+ self._test_
+
+ def test_pickle_
+ self._test_
+ self._test_
+
+ def test_pickle_
+ self._test_
+ self._test_
+
+ def test_pickle_
+ self._test_
+ self._test_
+ self._test_
+ self._test_
+
+ def test_pickle_
+ self._test_
+<x xmlns:xsi="http://
+ self._test_
+
+ def _test_pickle(self, stringOrElt):
+ import pickle
+ if isinstance(
+ elt = stringOrElt
+ else:
+ elt = self.XML(
+ out = BytesIO()
+ pickle.dump(elt, out)
+
+ new_elt = pickle.
+ self.assertEquals(
+ etree.tostring(
+ etree.tostring(