示例#1
0
 def xml(self):
     root = Element("Timestamp", ns=wsuns)
     created = Element('Created', ns=wsuns)
     created.setText(str(UTC(self.created)))
     expires = Element('Expires', ns=wsuns)
     expires.setText(str(UTC(self.expires)))
     root.append(created)
     root.append(expires)
     return root
示例#2
0
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('Security', ns=wssens)
     root.set('mustUnderstand', str(self.mustUnderstand).lower())
     for t in self.tokens:
         root.append(t.xml())
     return root
示例#3
0
 def body(self, content):
     """
     Build the B{<Body/>} for an soap outbound message.
     @param content: The body content.
     @type content: L{Element}
     @return: the soap body fragment.
     @rtype: L{Element}
     """
     env_ns = self.wsdl.options.envns
     body = Element('Body', ns=env_ns)
     body.append(content)
     return body
示例#4
0
 def header(self, content):
     """
     Build the B{<Body/>} for an soap outbound message.
     @param content: The header content.
     @type content: L{Element}
     @return: the soap body fragment.
     @rtype: L{Element}
     """
     env_ns = self.wsdl.options.envns
     header = Element('Header', ns=env_ns)
     header.append(content)
     return header
示例#5
0
 def startElement(self, name, attrs):
     top = self.top()
     node = Element(unicode(name), parent=top)
     for a in attrs.getNames():
         n = unicode(a)
         v = unicode(attrs.getValue(a))
         attribute = Attribute(n,v)
         if self.mapPrefix(node, attribute):
             continue
         node.append(attribute)
     node.charbuffer = []
     top.append(node)
     self.push(node)
示例#6
0
 def envelope(self, header, body):
     """
     Build the B{<Envelope/>} for an soap outbound message.
     @param header: The soap message B{header}.
     @type header: L{Element}
     @param body: The soap message B{body}.
     @type body: L{Element}
     @return: The soap envelope containing the body and header.
     @rtype: L{Element}
     """
     env_ns = self.wsdl.options.envns
     env = Element('Envelope', ns=env_ns)
     env.addPrefix(Namespace.xsins[0], Namespace.xsins[1])
     env.append(header)
     env.append(body)
     return env
示例#7
0
def basic():
    xml = "<a>Me &amp;&amp; &lt;b&gt;my&lt;/b&gt; shadow&apos;s &lt;i&gt;dog&lt;/i&gt; love to &apos;play&apos; and sing &quot;la,la,la&quot;;</a>"
    p = Parser()
    d = p.parse(string=xml)
    a = d.root()
    print 'A(parsed)=\n%s' % a
    assert str(a) == xml
    b = Element('a')
    b.setText('Me &&amp; &lt;b>my</b> shadow\'s <i>dog</i> love to \'play\' and sing "la,la,la";')
    print 'B(encoded)=\n%s' % b
    assert str(b) == xml
    print 'A(text-decoded)=\n%s' % a.getText()
    print 'B(text-decoded)=\n%s' % b.getText()
    assert a.getText() == b.getText()
    print 'test pruning'
    j = Element('A')
    j.set('n', 1)
    j.append(Element('B'))
    print j
    j.prune()
    print j
示例#8
0
 def xml(self):
     """
     Get xml representation of the object.
     @return: The root node.
     @rtype: L{Element}
     """
     root = Element('UsernameToken', ns=wssens)
     u = Element('Username', ns=wssens)
     u.setText(self.username)
     root.append(u)
     p = Element('Password', ns=wssens)
     p.setText(self.password)
     root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=wssens)
         n.setText(self.nonce)
         root.append(n)
     if self.created is not None:
         n = Element('Created', ns=wsuns)
         n.setText(str(UTC(self.created)))
         root.append(n)
     return root