dict->XML->dict? Or, passing small hashes through text?
mackstann
mack at incise.org
Fri Aug 15 23:23:03 EDT 2003
On Fri, Aug 15, 2003 at 09:24:10AM +0200, Fredrik Lundh wrote:
> > xmsg would now be a string such as:
> > '<?xml version="1.0"?><foo>1</foo><bar>hello</bar><abc>text</abc></xml>'
>
> (that's not valid XML: there can be only one toplevel element in an
> XML document. that's easy to fix, of course)
Yes, I am nowhere near an XML expert, and heh, now that I look at it, I
have no idea why it made sense to me to have <?xml?> ... </xml>, but it
was just a mockup. :)
> here's a minimal implementation, based on my ElementTree module:
>
<snip>
>
> you can get the elementtree source code via this page:
>
> http://effbot.org/zone/element-index.htm
I actually had downloaded the elementtree source and was looking through
it, but had not had time to work out any test or prototype yet.
> if the XML format doesn't really matter, you can use Python's
> standard xmlrpclib module:
>
> import xmlrpclib
>
> def xmlMessage(dict):
> # dumps requires a tuple
> return xmlrpclib.dumps((dict,))
>
> def xmlMessage2dict(message):
> result, method = xmlrpclib.loads(message)
> return result[0] # unwrap
This is perfect! I am now using this, and it works pretty much exactly
how I want it to work. Days and days of googling, reading, looking
through code, etc.. and it comes down to a 6 line answer. :)
I came to the conclusion that SimpleXMLRPCServer didn't fit well within
my program, since the server basically just reads the messages into a
queue (a Queue.Queue to be precise), and the program clears them out
every so often and takes action in its own way. The server is pretty
passive, and I saw no point in changing that.
Thanks, everyone that replied!
--
m a c k s t a n n mack @ incise.org http://incise.org
Murphy's Law of Research:
Enough research will tend to support your theory.
More information about the Python-list
mailing list