source: TI12-security/trunk/NDGSecurity/python/Tests/etreewss/client/fred_eg.py @ 7080

Subversion URL: http://proj.badc.rl.ac.uk/svn/ndg/TI12-security/trunk/NDGSecurity/python/Tests/etreewss/client/fred_eg.py@7080
Revision 7080, 1.3 KB checked in by pjkersha, 9 years ago (diff)
  • Property svn:keywords set to Id
Line 
1#!/usr/bin/env python
2import re
3from elementtree import ElementTree, ElementC14N
4from StringIO import StringIO
5
6   
7soapNSURI = 'http://schemas.xmlsoap.org/soap/envelope/'
8
9envElem = ElementTree.Element("{%s}Envelope" % soapNSURI) 
10envElem.set("xmlns:SOAP-ENV", soapNSURI)
11
12hdrElem = ElementTree.Element("{%s}Header" % soapNSURI)
13envElem.set("xmlns:SOAP-ENV", soapNSURI)
14envElem.append(hdrElem)
15
16bodyElem = ElementTree.Element("{%s}Body" % soapNSURI)
17envElem.set("xmlns:SOAP-ENV", soapNSURI)
18envElem.append(bodyElem)
19wsuNS='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd'
20envElem.set('xmlns:wsu', wsuNS)
21envElem.set('URI', "http://blah")
22bodyElem.set('{%s}Id' % wsuNS, '#body')
23
24ndgSecNS = "urn:ndg:security:test:wssecurity"
25echoElem = ElementTree.Element("{%s}Echo" % ndgSecNS)
26echoElem.set('xmlns:ns0', ndgSecNS)
27bodyElem.append(echoElem)
28
29echoInElem = ElementTree.Element("{%s}EchoIn" % ndgSecNS)
30echoInElem.text = "hello"
31echoElem.append(echoInElem)
32
33print "Calling Inclusive C14N  ..."
34f = StringIO()
35ElementC14N.write(ElementC14N.build_scoped_tree(envElem), f)
36print f.getvalue()
37
38print "Calling Exclusive C14N for body element ..."
39g = StringIO()
40ElementC14N.write(ElementC14N.build_scoped_tree(envElem), g, exclusive=True,
41                  subset=bodyElem)
42c14n = g.getvalue()
43print c14n
44
45
46
Note: See TracBrowser for help on using the repository browser.