Exemplo n.º 1
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)
     if self.password_digest:
         p.set("Type", wsdigest)
         p.setText(self.password_digest)
     root.append(p)
     if self.nonce is not None:
         n = Element('Nonce', ns=wssens)
         if self.nonce_has_encoding:
             n.set("EncodingType", nonce_encoding_type)
         n.setText(self.nonce)
         root.append(n)
     if self.created is not None:
         n = Element('Created', ns=wsuns)
         n.setText(str(DateTime(self.created)))
         root.append(n)
     return root
Exemplo n.º 2
0
 def xml(self):
     root = Element("Timestamp", ns=wsuns)
     created = Element('Created', ns=wsuns)
     created.setText(str(DateTime(self.created)))
     expires = Element('Expires', ns=wsuns)
     expires.setText(str(DateTime(self.expires)))
     root.append(created)
     root.append(expires)
     return root
Exemplo n.º 3
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