Fwd: [XML-SIG] xmlpickle.py ?!
Mon, 7 Aug 2000 15:19:06 -0400
I've been working on a somewhat similar project called SPOM (Sax-Pythonic
Object Model). It's not quite as automatic as pickling, and it is somewhat
less general (it's really designed for tree structures that map nicely to
XML), but it requires very little work per element to implement.
The advantage over picking is that the output is a natural looking XML file
that looks as if it were designed manually (i.e. python class instances map
to xml elements and python attributes map to xml attributes, and type
information is external to the xml file). You couldn't tell by looking at
the xml file that it was created using Spom, and you could even use Spom to
work with existing xml files created by other applications and vice-versa.
Beta coming soon. Search for SPOM on parnassus in about a week.
----- Original Message -----
From: "Jim Fulton" <firstname.lastname@example.org>
To: "M.-A. Lemburg" <email@example.com>
Sent: Monday, August 07, 2000 2:39 PM
Subject: Re: Fwd: [XML-SIG] xmlpickle.py ?!
> <note>I don't normally have time to follow the xml sig.
> Someone kindly forwarded Marc-Andre's note to me.
> I haven't seen the rest of this thread.
> "M.-A. Lemburg" <firstname.lastname@example.org> wrote:
> > I'm currently looking into writing a xmlpickle.py module
> > with the intent to be able to pickle (and unpickle) arbitrary
> > Python objects in a way that makes the objects editable through
> > a XML editor or convertible to some other format using the
> > existing XML tools.
> I wonder whether a tool that generated XML for arbitrary Python
> objects would really be that useful for transfer to
> other applications. I suspect not.
> > After looking at the archives of this SIG, I found that the
> > idea was already tossed around a few times, but I couldn't
> > find any downloadble outcome.
> Zope has a facility that I've been meaning to make more
> generally available but haven't had time to. :/
> In my case, I wanted to be able to convert to/from binary
> pickles and xml, so I had an intern write something that
> works from pickles, rather than from objects. It can be used
> to look at existing pickles and can be used, in conjunction with
> pickle or cPickle to convert objects to and from XML.
> If your interested, let me know and I'll provide more details.
> > I've looked at pickle.py a bit and realized that the extensible
> > nature of the pickle mechanism would probably cause trouble
> > because the DTD would have to be generated as well (not a good
> > idea).
> Why would a DTD have to be generated?
> > There are two alternatives to this though:
> > 1. add an element which handles all non-core Python object
> > types (the ones registered through copy_reg)
> > 2. use an abstract DTD altogheter
> > Example for 1:
> > <PythonPickle version="1.0">
> > <Dictionary>
> > <String name="aString">abcdef</String>
> > <List name="aList">
> > <Integer>10</Integer>
> > <String>abc</String>
> > </List>
> > <Instance name="aInstance" module="test" classname="test">
> > <String name="instvar">value</String>
> > </Instance>
> > <Object name="myObject" constructor="mx.DateTime.DateTime">
> > <Tuple>
> > <Integer>2000</Integer>
> > <Integer>8</Integer>
> > <Integer>6</Integer>
> > </Tuple>
> > </Object>
> > </Dictionary>
> > </PythonPickle>
> This is the route I took. Here's an example that's
> probably alot bigger than you want....
> <dictionary id="3046.4">
> <key> <string id="3046.5" encoding="repr">title</string>
> <value> <string encoding="repr"></string> </value>
> <key> <string id="3046.6" encoding="repr">raw</string> </key>
> <value> <string id="3046.7" encoding="cdata"><![CDATA[
> <dtml-var standard_html_header>\n
> <h2><dtml-var title_or_id> <dtml-var document_title></h2>\n
> <dtml-var "\'\\n\\n\'">\n
> This is the <dtml-var document_id> Document \n
> in the <dtml-var title_and_id> Folder.\n
> <dtml-var standard_html_footer>
> ]]></string> </value>
> <key> <string id="3046.8"
> <dictionary id="3046.9">
> <key> <string id="3046.10"
> <list id="3046.11">
> <string id="3046.12"
> <key> <string id="3046.13" encoding="repr">globals</string>
> <dictionary id="3046.14"/>
> <key> <string id="3046.15" encoding="repr">__name__</string>
> <value> <string id="3046.16" encoding="repr">m2</string>
> <key> <string id="3046.17" encoding="repr">_vars</string>
> <dictionary id="3046.18"/>
> Note that this is pretty much a straight translation of
> the Python pickle "schema". :) Note the id attributes
> and reference tags, which allow cyclical data structures.
> (I recently discovered that there is a problem with my id
> values. Does anyone know what it is? ;)
> One other note. I found the XML spec to be a little
> ambigouos (or maybe I'm just too dense) wrt binary data
> and newlines, so I decided to punt and escape newlines and
> binary data. I encode strings as either "repr" which is a
> repr like encoding that escapes things in a way that is
> just a tad more terse than repr. I switch to base64 when
> the escaping penalty exceeds 40%. Since alot of our pickles
> have marked up text, I automatically use CDATA sections when
> I can and where it would help. See the example above.
> I really need to write down a DTD for this......
> Jim Fulton mailto:email@example.com Python Powered!
> Technical Director (888) 344-4332 http://www.python.org
> Digital Creations http://www.digicool.com http://www.zope.org
> Under US Code Title 47, Sec.227(b)(1)(C), Sec.227(a)(2)(B) This email
> address may not be added to any commercial mail list with out my
> permission. Violation of my privacy with advertising or SPAM will
> result in a suit for a MINIMUM of $500 damages/incident, $1500 for
> XML-SIG maillist - XML-SIG@python.org