mnot’s blog

Design depends largely on constraints.” — Charles Eames

Friday, 7 May 2004

Python Web Services XML 0.2

To help inform discussion of XOP (and to save Sam the trouble ;), I’ve put together a quick-and-dirty (we’re talking two hours) XOP parser in Python. It isn’t particularly efficient, nor is it well-tested or robust; it’s only to demonstrate how a XOP parser might behave.

On the command line, it can regurgitate XOP Packages as XML 1.0 serialisations of the Infoset;

mnot-laptop:~/Desktop> ./ -t
<?xml version="1.0" encoding="iso-8859-1"?>
    <m:data xmlns:m="">
      <m:photo xop-mime:content-type="image/png">
      <m:sig xop-mime:content-type="application/pkcs7-signature">

You can also do this with your own XOP Packages:

mnot-laptop:~/Desktop> cat test.xop | ./

Alternatively, you can use it as a drop-in xml.sax parser. If you do, you can define a new method on your ContentHandler, binary(content), that gets binary data from attachments fed to it directly, when available.

Be sure to read the caveats in the header, and leave any bugs, suggestions, patches, etc. below.