[Zope-dev] zope.xmlpickle
Jim Fulton
jim at zope.com
Fri May 26 06:57:24 EDT 2006
Michael Dunstan wrote:
> Hi all,
>
> I have been trying out ``zope.xmlpickle`` as a alternative to
> XMLExportImport in Zope2.
Cool. xmlpickle is really a newer version of the xml pickler used in
Zope 2's export/import. It's main goal is to provide nicer pickles:
- More readable
- More diff friendly. It does this my:
- sorting dictionary items
- eliminating unused memo references
It would be nice to integrate this back into the export/import
machinery. Some care would be needed to make it compatible with
the old xml pickles.
> Seems to do the job just fine. Grab Zope
> 2.9.3 and install zope.xmlpickle by hand using something of the form:
>
> % cd /opt/Zope-2.9/lib/python/zope
> % svn checkout
> svn://svn.zope.org/repos/main/Zope3/trunk/src/zope/xmlpickle
>
> Then using zopectl debug:
>
> >>> from zope.xmlpickle import dumps
>
> Picking on something simple to start with:
>
> >>> xml = dumps(app.acl_users.aq_base)
> >>> print xml
> <?xml version="1.0" encoding="utf-8" ?>
> <pickle>
> <initialized_object>
> <klass>
> <global name="__newobj__" module="copy_reg"/>
> </klass>
> <arguments>
> <tuple>
> <global name="SiteErrorLog"
> module="Products.SiteErrorLog.SiteErrorLog"/>
> </tuple>
> </arguments>
> <state>
> <dictionary>
> <item key="_ignored_exceptions">
> <tuple>
> <string>Unauthorized</string>
> <string>Redirect</string>
> <string>NotFound</string>
> </tuple>
> </item>
> <item key="copy_to_zlog">
> <true/>
> </item>
> <item key="keep_entries">
> <int>20</int>
> </item>
> </dictionary>
> </state>
> </initialized_object>
> </pickle>
>
>
> That looks okay. But I strike problems with ``Missing.Value`` when
> trying this on something that includes a catalog. The simplest way
> to recreate the problem::
>
> >>> import Missing
> >>> dumps(Missing.Value())
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> File "/opt/Zope-2.9/lib/python/zope/xmlpickle/xmlpickle.py", line
> 146, in dumps
> p = _dumpsUsing_PicklerThatSortsDictItems(ob, 1)
> File "/opt/Zope-2.9/lib/python/zope/xmlpickle/xmlpickle.py", line
> 73, in _dumpsUsing_PicklerThatSortsDictItems
> _PicklerThatSortsDictItems(file, bin).dump(object)
> File
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/pickle.py",
>
> line 231, in dump
> self.save(obj)
> File
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/pickle.py",
>
> line 324, in save
> self.save_global(obj, rv)
> File
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/pickle.py",
>
> line 753, in save_global
> module = whichmodule(obj, name)
> File
> "/Library/Frameworks/Python.framework/Versions/2.4/lib/python2.4/pickle.py",
>
> line 825, in whichmodule
> if func in classmap:
> TypeError: unhashable type
>
> Meanwhile, dumps seems to work quite happy with many other examples
> that I tried. Including all the content of a plone site minus a couple
> of the catalogs. And ``zope.xmlpickle.loads`` seems to do the right
> thing too.
>
> Any suggestions on getting a successful dumps of a Missing.Value?
You need someone with pickle zen to look at this. I don't have time
right now myself. If you don't find any other takers, then put an
issue in the Zope 3 collector.
Jim
--
Jim Fulton mailto:jim at zope.com Python Powered!
CTO (540) 361-1714 http://www.python.org
Zope Corporation http://www.zope.com http://www.zope.org
More information about the Zope-Dev
mailing list