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
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
def body(self, content): """ Build the B{<Body/>} for a SOAP outbound message. @param content: The body content. @type content: L{Element} @return: The SOAP body fragment. @rtype: L{Element} """ body = Element("Body", ns=envns) body.append(content) return body
def header(self, content): """ Build the B{<Body/>} for a SOAP outbound message. @param content: The header content. @type content: L{Element} @return: The SOAP body fragment. @rtype: L{Element} """ header = Element("Header", ns=envns) header.append(content) return header
def startElement(self, name, attrs): top = self.top() node = Element(str(name)) for a in attrs.getNames(): n = str(a) v = str(attrs.getValue(a)) attribute = Attribute(n, v) if self.mapPrefix(node, attribute): continue node.append(attribute) node.charbuffer = [] top.append(node) self.push(node)
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
def envelope(self, header, body): """ Build the B{<Envelope/>} for a 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 = Element("Envelope", ns=envns) env.addPrefix(Namespace.xsins[0], Namespace.xsins[1]) env.append(header) env.append(body) return env
def basic(): xml = "<a>Me && <b>my</b> shadow's <i>dog</i> love to 'play' and sing "la,la,la";</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 && <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