Ignore:
Timestamp:
16/07/08 14:46:39 (12 years ago)
Author:
pjkersha
Message:

tidying up etree.py and elementtreeproxy.py ElementTree WS-Security signature handler and ZSI interface class respectively.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • TI12-security/trunk/python/Tests/etreewss/client/fred_eg.py

    r4038 r4045  
    77soapNSURI = 'http://schemas.xmlsoap.org/soap/envelope/' 
    88 
    9 env = ElementTree.Element("{%s}Envelope" % soapNSURI)  
    10 env.set("xmlns:SOAP-ENV", soapNSURI) 
     9envElem = ElementTree.Element("{%s}Envelope" % soapNSURI)  
     10envElem.set("xmlns:SOAP-ENV", soapNSURI) 
    1111 
    12 hdr = ElementTree.Element("{%s}Header" % soapNSURI) 
    13 env.set("xmlns:SOAP-ENV", soapNSURI) 
    14 env.append(hdr) 
     12hdrElem = ElementTree.Element("{%s}Header" % soapNSURI) 
     13envElem.set("xmlns:SOAP-ENV", soapNSURI) 
     14envElem.append(hdrElem) 
    1515 
    16 body = ElementTree.Element("{%s}Body" % soapNSURI) 
    17 env.set("xmlns:SOAP-ENV", soapNSURI) 
    18 env.append(body) 
     16bodyElem = ElementTree.Element("{%s}Body" % soapNSURI) 
     17envElem.set("xmlns:SOAP-ENV", soapNSURI) 
     18envElem.append(bodyElem) 
    1919wsuNS='http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd' 
    20 env.set('xmlns:wsu', wsuNS) 
    21 env.set('URI', "http://blah") 
    22 #body.set('wsu:Id', '#body') 
    23 body.set('{%s}Id' % wsuNS, '#body') 
    24 ns = {'wsu': wsuNS} 
    25 print "wsu:Id elements = %s" % env.findall('.//*[@wsu:Id]', namespaces=ns) 
    26 print "Calling C14N 1st time ..." 
     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  ..." 
    2734f = StringIO() 
    28 ElementC14N.write(ElementC14N.build_scoped_tree(env), f) 
     35ElementC14N.write(ElementC14N.build_scoped_tree(envElem), f) 
    2936print f.getvalue() 
    3037 
    31 print "Calling C14N 2nd time ..." 
     38print "Calling Exclusive C14N for body element ..." 
    3239g = StringIO() 
    33 ElementC14N.write(ElementC14N.build_scoped_tree(env), g) 
     40ElementC14N.write(ElementC14N.build_scoped_tree(envElem), g, exclusive=True, 
     41                  subset=bodyElem) 
    3442c14n = g.getvalue() 
    3543print c14n 
    36 filePath = './c14n.xml' 
    37 open(filePath, 'w').write(c14n) 
    38  
    39 env2 = ElementC14N.parse(filePath) 
    40 print "wsu:Id elements = %s" % env2.findall('.//*[@wsu:Id]', namespaces=ns) 
    41  
    42 print "Calling C14N for echo message ..." 
    43 import pdb;pdb.set_trace() 
    44  
    45 etree = ElementC14N.parse('/home/pjkersha/Desktop/soap-etree.xml') 
    46 f = StringIO() 
    47 elem = etree.getroot() 
    48 elem._scope = etree._scope 
    49 ElementC14N.write(ElementC14N.build_scoped_tree(elem), f) 
    50 print f.getvalue() 
    5144 
    5245 
Note: See TracChangeset for help on using the changeset viewer.