mnot’s blog

Design depends largely on constraints.” — Charles Eames

Friday, 7 May 2004

XopParser.py 0.2

Filed under: Python Web Services XML

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> ./XopParser.py -t
<?xml version="1.0" encoding="iso-8859-1"?>
<soap:Envelope 
 xmlns:soap="http://www.w3.org/2003/05/soap-envelope" 
 xmlns:xop="http://www.w3.org/2003/12/xop/include"
 xmlns:xop-mime="http://www.w3.org/2003/12/xop/mime">
  <soap:Body>
    <m:data xmlns:m="http://example.org/stuff">
      <m:photo xop-mime:content-type="image/png">
        Ly8gYmluYXJ5IG9jdGV0cyBmb3IgcG5nCg=
      </m:photo>
      <m:sig xop-mime:content-type="application/pkcs7-signature">
        Ly8gYmluYXJ5IG9jdGV0cyBmb3Igc2lnbmF0dXJlCg=
      </m:sig>
    </m:data>
  </soap:Body>
</soap:Envelope>

You can also do this with your own XOP Packages:

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

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.


Creative Commons