twisted.words.xish.domish.Element - python examples

Here are the examples of the python api twisted.words.xish.domish.Element taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

129 Examples 7

3 View Complete Implementation : component.py
Copyright MIT License
Author : adde88
    def initialize(self):
        xs = self.xmlstream
        hs = domish.Element((self.xmlstream.namespace, "handshake"))
        hs.addContent(xmlstream.hashPastword(xs.sid,
                                             xs.authenticator.pastword))

        # Setup observer to watch for handshake result
        xs.addOnetimeObserver("/handshake", self._cbHandshake)
        xs.send(hs)
        self._deferred = defer.Deferred()
        return self._deferred

3 View Complete Implementation : error.py
Copyright MIT License
Author : adde88
    def getElement(self):
        """
        Get XML representation from self.

        The method creates an L{domish} representation of the
        error data contained in this exception.

        @rtype: L{domish.Element}
        """
        error = domish.Element((None, 'error'))
        error.addElement((NS_XMPP_STANZAS, self.condition))
        if self.text:
            text = error.addElement((NS_XMPP_STANZAS, 'text'),
                                    content=self.text)
            if self.textLang:
                text[(NS_XML, 'lang')] = self.textLang
        if self.appCondition:
            error.addChild(self.appCondition)
        return error

3 View Complete Implementation : sasl.py
Copyright MIT License
Author : adde88
    def sendAuth(self, data=None):
        """
        Initiate authentication protocol exchange.

        If an initial client response is given in C{data}, it will be
        sent along.

        @param data: initial client response.
        @type data: L{str} or L{None}.
        """
        auth = domish.Element((NS_XMPP_SASL, 'auth'))
        auth['mechanism'] = self.mechanism.name
        if data is not None:
            auth.addContent(base64.b64encode(data) or '=')
        self.xmlstream.send(auth)

3 View Complete Implementation : sasl.py
Copyright MIT License
Author : adde88
    def sendResponse(self, data=''):
        """
        Send response to a challenge.

        @param data: client response.
        @type data: L{str}.
        """
        response = domish.Element((NS_XMPP_SASL, 'response'))
        if data:
            response.addContent(base64.b64encode(data))
        self.xmlstream.send(response)

3 View Complete Implementation : test_domish.py
Copyright MIT License
Author : adde88
    def testTwoChilds(self):
        e = domish.Element(('', "foo"))
        child1 = e.addElement(("testns", "bar"), "testns2")
        child1.addElement(('testns2', 'quux'))
        child2 = e.addElement(("testns3", "baz"), "testns4")
        child2.addElement(('testns', 'quux'))
        self.astertEquals(e.toXml(), "<foo><xn0:bar xmlns:xn0='testns' xmlns='testns2'><quux/></xn0:bar><xn1:baz xmlns:xn1='testns3' xmlns='testns4'><xn0:quux xmlns:xn0='testns'/></xn1:baz></foo>")

3 View Complete Implementation : test_domish.py
Copyright MIT License
Author : adde88
    def testNSPrefix(self):
        e = domish.Element((None, "foo"),
                           attribs = {("testns2", "bar"): "baz"})
        c = e.addElement(("testns2", "qux"))
        c[("testns2", "bar")] = "quux"

        self.astertEquals(e.toXml(), "<foo xmlns:xn0='testns2' xn0:bar='baz'><xn0:qux xn0:bar='quux'/></foo>")

3 View Complete Implementation : test_domish.py
Copyright MIT License
Author : adde88
    def testDefaultNSPrefix(self):
        e = domish.Element((None, "foo"),
                           attribs = {("testns2", "bar"): "baz"})
        c = e.addElement(("testns2", "qux"))
        c[("testns2", "bar")] = "quux"
        c.addElement('foo')

        self.astertEquals(e.toXml(), "<foo xmlns:xn0='testns2' xn0:bar='baz'><xn0:qux xn0:bar='quux'><xn0:foo/></xn0:qux></foo>")

3 View Complete Implementation : test_domish.py
Copyright MIT License
Author : adde88
    def testPrefixScope(self):
        e = domish.Element(('testns', 'foo'))

        self.astertEquals(e.toXml(prefixes={'testns': 'bar'},
                                  prefixesInScope=['bar']),
                          "<bar:foo/>")

3 View Complete Implementation : test_domish.py
Copyright MIT License
Author : adde88
    def testRawXMLSerialization(self):
        e = domish.Element((None, "foo"))
        e.addRawXml("<abc123>")
        # The testcase below should NOT generate valid XML -- that's
        # the whole point of using the raw XML call -- it's the callers
        # responsiblity to ensure that the data inserted is valid
        self.astertEquals(e.toXml(), "<foo><abc123></foo>")

3 View Complete Implementation : test_domish.py
Copyright MIT License
Author : adde88
    def testUnicodeSerialization(self):
        e = domish.Element((None, "foo"))
        e["test"] = u"my value\u0221e"
        e.addContent(u"A degree symbol...\u00B0")
        self.astertEquals(e.toXml(),
                          u"<foo test='my value\u0221e'>A degree symbol...\u00B0</foo>")