twisted.words.xish.domish.Element

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.

176 Examples 7

Example 1

Project: wokkel Source File: test_data_form.py
    def test_fromElementFormTypeNotHidden(self):
        """
        A non-hidden field named FORM_TYPE does not set the form type.
        """
        element = domish.Element((NS_X_DATA, 'x'))
        field = element.addElement('field')
        field['var'] = 'FORM_TYPE'
        field.addElement('value', content='myns')
        form = data_form.Form.fromElement(element)

        self.assertIn('FORM_TYPE', form.fields)
        self.assertIdentical(None, form.formNamespace)

Example 2

Project: wokkel Source File: test_disco.py
Function: test_from_element
    def test_fromElement(self):
        """
        Test creating L{disco.DiscoFeature} from L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_INFO, u'feature'))
        element['var'] = u'testns'
        feature = disco.DiscoFeature.fromElement(element)
        self.assertEqual(u'testns', feature)

Example 3

Project: wokkel Source File: test_data_form.py
    def test_fromElementValueJID(self):
        """
        Parsed jid-single field values should be of type C{unicode}.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element['type'] = 'jid-single'
        element.addElement('value', content=u'[email protected]')
        field = data_form.Field.fromElement(element)
        self.assertEquals(u'[email protected]', field.value)

Example 4

Project: wokkel Source File: test_data_form.py
    def test_fromElementInstructions2(self):
        element = domish.Element((NS_X_DATA, 'x'))
        element.addElement('instructions', content='instruction 1')
        element.addElement('instructions', content='instruction 2')
        form = data_form.Form.fromElement(element)

        self.assertEquals(['instruction 1', 'instruction 2'], form.instructions)

Example 5

Project: wokkel Source File: test_data_form.py
    def test_fromElementOption(self):
        """
        Field descriptions are in a desc child element.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element.addElement('option').addElement('value', content=u'option1')
        element.addElement('option').addElement('value', content=u'option2')
        field = data_form.Field.fromElement(element)
        self.assertEqual(2, len(field.options))

Example 6

Project: wokkel Source File: test_data_form.py
    def test_fromElement(self):
        """
        An option has a child element with the option value.
        """
        element = domish.Element((NS_X_DATA, 'option'))
        element.addElement('value', content='value')
        option = data_form.Option.fromElement(element)

        self.assertEqual('value', option.value)
        self.assertIdentical(None, option.label)

Example 7

Project: wokkel Source File: test_data_form.py
    def test_noFormTypeCancel(self):
        """
        Cancelled forms don't have a FORM_TYPE field, the first is returned.
        """
        element = domish.Element((None, 'test'))
        cancelledForm = data_form.Form('cancel')
        element.addChild(cancelledForm.toElement())
        form = data_form.findForm(element, 'myns')
        self.assertEqual('cancel', form.formType)

Example 8

Project: wokkel Source File: disco.py
Function: to_element
    def toElement(self):
        """
        Generate a DOM representation.

        This takes the items added with C{append} to create a DOM
        representation of service discovery items.

        @rtype: L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_ITEMS, 'query'))

        if self.nodeIdentifier:
            element['node'] = self.nodeIdentifier

        for item in self:
            element.addChild(item.toElement())

        return element

Example 9

Project: wokkel Source File: test_disco.py
    def test_fromElement(self):
        """
        Test creating L{disco.DiscoItem} from L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_ITEMS, u'item'))
        element[u'jid'] = u'example.org'
        element[u'node'] = u'test'
        element[u'name'] = u'The node'
        item = disco.DiscoItem.fromElement(element)
        self.assertEqual(JID(u'example.org'), item.entity)
        self.assertEqual(u'test', item.nodeIdentifier)
        self.assertEqual(u'The node', item.name)

Example 10

Project: wokkel Source File: server.py
Function: initialize
    def initialize(self):
        self._deferred = defer.Deferred()
        self.xmlstream.addObserver(xmlstream.STREAM_ERROR_EVENT,
                                   self.onStreamError)
        self.xmlstream.addObserver("/verify[@xmlns='%s']" % NS_DIALBACK,
                                   self.onVerify)

        verify = domish.Element((NS_DIALBACK, 'verify'))
        verify['from'] = self.thisHost
        verify['to'] = self.otherHost
        verify['id'] = self.originalStreamID
        verify.addContent(self.key)

        self.xmlstream.send(verify)
        return self._deferred

Example 11

Project: wokkel Source File: test_data_form.py
    def test_fromElementTitle(self):
        element = domish.Element((NS_X_DATA, 'x'))
        element.addElement('title', content='My title')
        form = data_form.Form.fromElement(element)

        self.assertEquals('My title', form.title)

Example 12

Project: wokkel Source File: test_data_form.py
    def test_fromElementChildOtherNamespace(self):
        """
        Child elements from another namespace are ignored.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element['var'] = 'test'
        element.addElement(('myns', 'value'))
        field = data_form.Field.fromElement(element)

        self.assertIdentical(None, field.value)

Example 13

Project: wokkel Source File: test_component.py
    def test_onElement(self):
        """
        We expect a handshake element with a hash.
        """
        handshakes = []

        xs = self.xmlstream
        xs.authenticator.onHandshake = handshakes.append

        handshake = domish.Element(('jabber:component:accept', 'handshake'))
        handshake.addContent('1234')
        xs.authenticator.onElement(handshake)
        self.assertEqual('1234', handshakes[-1])

Example 14

Project: wokkel Source File: test_data_form.py
    def test_fromElementTwoFields(self):
        element = domish.Element((NS_X_DATA, 'x'))
        element.addElement('field')['var'] = 'field1'
        element.addElement('field')['var'] = 'field2'
        form = data_form.Form.fromElement(element)

        self.assertEquals(2, len(form.fieldList))
        self.assertIn('field1', form.fields)
        self.assertEquals('field1', form.fieldList[0].var)
        self.assertIn('field2', form.fields)
        self.assertEquals('field2', form.fieldList[1].var)

Example 15

Project: wokkel Source File: disco.py
Function: to_element
    def toElement(self):
        """
        Generate a DOM representation.

        This takes the items added with C{append} to create a DOM
        representation of service discovery information.

        @rtype: L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_INFO, 'query'))

        if self.nodeIdentifier:
            element['node'] = self.nodeIdentifier

        for item in self:
            element.addChild(item.toElement())

        return element

Example 16

Project: wokkel Source File: test_data_form.py
    def test_findForm(self):
        element = domish.Element((None, 'test'))
        theForm = data_form.Form('submit', formNamespace='myns')
        element.addChild(theForm.toElement())
        form = data_form.findForm(element, 'myns')
        self.assertEqual('myns', form.formNamespace)

Example 17

Project: wokkel Source File: test_data_form.py
    def test_fromElementNoValue(self):
        """
        An option MUST have a value.
        """
        element = domish.Element((NS_X_DATA, 'option'))
        self.assertRaises(data_form.Error,
                          data_form.Option.fromElement, element)

Example 18

Project: wokkel Source File: test_data_form.py
    def test_otherFormTypeCancel(self):
        """
        Cancelled forms with another FORM_TYPE are ignored.
        """
        element = domish.Element((None, 'test'))
        cancelledForm = data_form.Form('cancel', formNamespace='otherns')
        element.addChild(cancelledForm.toElement())
        form = data_form.findForm(element, 'myns')
        self.assertIdentical(None, form)

Example 19

Project: idavoll Source File: gateway.py
def constructFeed(service, nodeIdentifier, entries, title):
    nodeURI = getXMPPURI(service, nodeIdentifier)
    now = strftime("%Y-%m-%dT%H:%M:%SZ", gmtime())

    # Collect the received entries in a feed
    feed = domish.Element((NS_ATOM, 'feed'))
    feed.addElement('title', content=title)
    feed.addElement('id', content=nodeURI)
    feed.addElement('updated', content=now)

    for entry in entries:
        feed.addChild(entry)

    return feed

Example 20

Project: wokkel Source File: test_disco.py
    def test_fromElementWithoutName(self):
        """
        Test creating L{disco.DiscoIdentity} from L{domish.Element}, no name.
        """
        element = domish.Element((NS_DISCO_INFO, u'identity'))
        element['category'] = u'conference'
        element['type'] = u'text'
        identity = disco.DiscoIdentity.fromElement(element)
        self.assertEqual(u'conference', identity.category)
        self.assertEqual(u'text', identity.type)
        self.assertEqual(None, identity.name)

Example 21

Project: wokkel Source File: test_data_form.py
    def test_fromElementValueBoolean(self):
        """
        Parsed boolean field values should be of type C{unicode}.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element['type'] = 'boolean'
        element.addElement('value', content=u'false')
        field = data_form.Field.fromElement(element)
        self.assertEquals(u'false', field.value)

Example 22

Project: wokkel Source File: test_data_form.py
    def test_fromElementDesc(self):
        """
        Field descriptions are in a desc child element.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element.addElement('desc', content=u'My description')
        field = data_form.Field.fromElement(element)
        self.assertEqual(u'My description', field.desc)

Example 23

Project: wokkel Source File: data_form.py
Function: to_element
    def toElement(self):
        """
        Return the DOM representation of this option.

        @rtype: L{domish.Element}.
        """
        option = domish.Element((NS_X_DATA, 'option'))
        option.addElement('value', content=self.value)
        if self.label:
            option['label'] = self.label
        return option

Example 24

Project: wokkel Source File: test_data_form.py
    def test_fromElementRequired(self):
        """
        Required fields have a required child element.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element.addElement('required')
        field = data_form.Field.fromElement(element)
        self.assertTrue(field.required)

Example 25

Project: wokkel Source File: test_component.py
Function: test_send
    def test_send(self):
        """
        A message sent from the component ends up at the router.
        """
        events = []
        fn = lambda obj: events.append(obj)
        message = domish.Element((None, 'message'))

        self.router.route = fn
        self.component.startService()
        self.component.send(message)

        self.assertEquals([message], events)

Example 26

Project: wokkel Source File: test_data_form.py
    def test_fromElementInvalidElementURI(self):
        """
        Bail if the passed element does not have the correct namespace.
        """
        element = domish.Element(('myns', 'x'))
        self.assertRaises(Exception, data_form.Form.fromElement, element)

Example 27

Project: wokkel Source File: test_data_form.py
    def test_fromElement(self):
        """
        C{fromElement} creates a L{data_form.Form} from a DOM representation.
        """
        element = domish.Element((NS_X_DATA, 'x'))
        element['type'] = 'result'
        form = data_form.Form.fromElement(element)

        self.assertEquals('result', form.formType)
        self.assertEquals(None, form.title)
        self.assertEquals([], form.instructions)
        self.assertEquals({}, form.fields)

Example 28

Project: wokkel Source File: test_component.py
Function: test_route
    def test_route(self):
        """
        Test routing of a message.
        """
        component1 = XmlPipe()
        component2 = XmlPipe()
        router = component.Router()
        router.addRoute('component1.example.org', component1.sink)
        router.addRoute('component2.example.org', component2.sink)

        outgoing = []
        component2.source.addObserver('/*',
                                      lambda element: outgoing.append(element))
        stanza = domish.Element((None, 'presence'))
        stanza['from'] = 'component1.example.org'
        stanza['to'] = 'component2.example.org'
        component1.source.send(stanza)
        self.assertEquals([stanza], outgoing)

Example 29

Project: wokkel Source File: test_data_form.py
    def test_fromElementInstructions(self):
        element = domish.Element((NS_X_DATA, 'x'))
        element.addElement('instructions', content='instruction')
        form = data_form.Form.fromElement(element)

        self.assertEquals(['instruction'], form.instructions)

Example 30

Project: wokkel Source File: disco.py
Function: to_element
    def toElement(self):
        """
        Generate a DOM representation.

        @rtype: L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_INFO, 'identity'))
        if self.category:
            element['category'] = self.category
        if self.type:
            element['type'] = self.type
        if self.name:
            element['name'] = self.name
        return element

Example 31

Project: wokkel Source File: test_data_form.py
    def test_fromElementOneField(self):
        element = domish.Element((NS_X_DATA, 'x'))
        element.addElement('field')
        form = data_form.Form.fromElement(element)

        self.assertEquals(1, len(form.fieldList))
        self.assertNotIn('field', form.fields)

Example 32

Project: wokkel Source File: test_component.py
Function: test_onelementnothandshake
    def test_onElementNotHandshake(self):
        """
        Reject elements that are not handshakes
        """
        handshakes = []
        streamErrors = []

        xs = self.xmlstream
        xs.authenticator.onHandshake = handshakes.append
        xs.sendStreamError = streamErrors.append

        element = domish.Element(('jabber:component:accept', 'message'))
        xs.authenticator.onElement(element)
        self.assertFalse(handshakes)
        self.assertEquals('not-authorized', streamErrors[-1].condition)

Example 33

Project: wokkel Source File: test_data_form.py
    def test_fromElementFormType(self):
        """
        The form type is a hidden field named FORM_TYPE.
        """
        element = domish.Element((NS_X_DATA, 'x'))
        field = element.addElement('field')
        field['var'] = 'FORM_TYPE'
        field['type'] = 'hidden'
        field.addElement('value', content='myns')
        form = data_form.Form.fromElement(element)

        self.assertNotIn('FORM_TYPE', form.fields)
        self.assertEqual('myns', form.formNamespace)

Example 34

Project: vumi Source File: xmpp.py
Function: reply
    def reply(self, jid, content):
        message = domish.Element((None, "message"))
        # intentionally leaving from blank, leaving for XMPP server
        # to figure out
        message['to'] = jid
        message['type'] = 'chat'
        message.addUniqueId()
        message.addElement((None, 'body'), content=content)
        self.xmlstream.send(message)

Example 35

Project: wokkel Source File: test_data_form.py
    def test_fromElementChildOtherNamespace(self):
        """
        Child elements from another namespace are ignored.
        """
        element = domish.Element((NS_X_DATA, 'x'))
        element['type'] = 'result'
        field = element.addElement(('myns', 'field'))
        field['var'] = 'test'
        form = data_form.Form.fromElement(element)

        self.assertEqual(0, len(form.fields))

Example 36

Project: wokkel Source File: test_data_form.py
    def test_fromElementLabel(self):
        """
        An option label is an attribute on the option element.
        """

        element = domish.Element((NS_X_DATA, 'option'))
        element.addElement('value', content='value')
        element['label'] = 'label'
        option = data_form.Option.fromElement(element)

        self.assertEqual('label', option.label)

Example 37

Project: wokkel Source File: test_data_form.py
    def test_noFormType(self):
        element = domish.Element((None, 'test'))
        otherForm = data_form.Form('submit')
        element.addChild(otherForm.toElement())
        form = data_form.findForm(element, 'myns')
        self.assertIdentical(None, form)

Example 38

Project: wokkel Source File: disco.py
Function: to_element
    def toElement(self):
        """
        Generate a DOM representation.

        @rtype: L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_ITEMS, 'item'))
        if self.entity:
            element['jid'] = self.entity.full()
        if self.nodeIdentifier:
            element['node'] = self.nodeIdentifier
        if self.name:
            element['name'] = self.name
        return element

Example 39

Project: wokkel Source File: test_data_form.py
    def test_otherFormType(self):
        """
        Forms with other FORM_TYPEs are ignored.
        """
        element = domish.Element((None, 'test'))
        otherForm = data_form.Form('submit', formNamespace='otherns')
        element.addChild(otherForm.toElement())
        form = data_form.findForm(element, 'myns')
        self.assertIdentical(None, form)

Example 40

Project: wokkel Source File: test_data_form.py
    def test_fromElementValueTextSingle(self):
        """
        Parsed text-single field values should be of type C{unicode}.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element['type'] = 'text-single'
        element.addElement('value', content=u'text')
        field = data_form.Field.fromElement(element)
        self.assertEquals('text', field.value)

Example 41

Project: wokkel Source File: test_data_form.py
    def test_noForm(self):
        """
        When no child element is a form, None is returned.
        """
        element = domish.Element((None, 'test'))
        form = data_form.findForm(element, 'myns')
        self.assertIdentical(None, form)

Example 42

Project: vumi Source File: test_xmpp.py
    @inlineCallbacks
    def test_message_without_id(self):
        transport = yield self.mk_transport()

        message = domish.Element((None, "message"))
        message['to'] = self.jid.userhost()
        message['from'] = '[email protected]'
        message.addElement((None, 'body'), content='hello world')
        self.assertFalse(message.hasAttribute('id'))

        protocol = transport.xmpp_protocol
        protocol.onMessage(message)

        [msg] = yield self.tx_helper.wait_for_dispatched_inbound()
        self.assertTrue(msg['message_id'])
        self.assertEqual(msg['transport_metadata']['xmpp_id'], None)

Example 43

Project: wokkel Source File: test_disco.py
    def test_fromElement(self):
        """
        Test creating L{disco.DiscoIdentity} from L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_INFO, u'identity'))
        element['category'] = u'conference'
        element['type'] = u'text'
        element['name'] = u'The chatroom'
        identity = disco.DiscoIdentity.fromElement(element)
        self.assertEqual(u'conference', identity.category)
        self.assertEqual(u'text', identity.type)
        self.assertEqual(u'The chatroom', identity.name)

Example 44

Project: wokkel Source File: test_data_form.py
    def test_fromElementValueJIDMalformed(self):
        """
        Parsed jid-single field values should be of type C{unicode}.

        No validation should be done at this point, so invalid JIDs should
        also be passed as-is.
        """
        element = domish.Element((NS_X_DATA, 'field'))
        element['type'] = 'jid-single'
        element.addElement('value', content=u'@@')
        field = data_form.Field.fromElement(element)
        self.assertEquals(u'@@', field.value)

Example 45

Project: wokkel Source File: server.py
Function: initialize
    def initialize(self):
        self._deferred = defer.Deferred()
        self.xmlstream.addObserver(xmlstream.STREAM_ERROR_EVENT,
                                   self.onStreamError)
        self.xmlstream.addObserver("/result[@xmlns='%s']" % NS_DIALBACK,
                                   self.onResult)

        key = generateKey(self.secret, self.otherHost,
                          self.thisHost, self.xmlstream.sid)

        result = domish.Element((NS_DIALBACK, 'result'))
        result['from'] = self.thisHost
        result['to'] = self.otherHost
        result.addContent(key)

        self.xmlstream.send(result)

        return self._deferred

Example 46

Project: vumi Source File: test_xmpp.py
Function: test_inbound_message
    @inlineCallbacks
    def test_inbound_message(self):
        transport = yield self.mk_transport()

        message = domish.Element((None, "message"))
        message['to'] = self.jid.userhost()
        message['from'] = '[email protected]'
        message.addUniqueId()
        message.addElement((None, 'body'), content='hello world')
        protocol = transport.xmpp_protocol
        protocol.onMessage(message)
        [msg] = yield self.tx_helper.wait_for_dispatched_inbound()
        self.assertEqual(msg['to_addr'], self.jid.userhost())
        self.assertEqual(msg['from_addr'], '[email protected]')
        self.assertEqual(msg['transport_name'], self.tx_helper.transport_name)
        self.assertNotEqual(msg['message_id'], message['id'])
        self.assertEqual(msg['transport_metadata']['xmpp_id'], message['id'])
        self.assertEqual(msg['content'], 'hello world')

Example 47

Project: vumi Source File: test_xmpp.py
    @inlineCallbacks
    def test_normalizing_from_addr(self):
        transport = yield self.mk_transport()

        message = domish.Element((None, "message"))
        message['to'] = self.jid.userhost()
        message['from'] = '[email protected]/some_xmpp_id'
        message.addUniqueId()
        message.addElement((None, 'body'), content='hello world')
        protocol = transport.xmpp_protocol
        protocol.onMessage(message)
        [msg] = yield self.tx_helper.wait_for_dispatched_inbound()
        self.assertEqual(msg['from_addr'], '[email protected]')
        self.assertEqual(msg['transport_metadata']['xmpp_id'], message['id'])

Example 48

Project: wokkel Source File: disco.py
Function: to_element
    def toElement(self):
        """
        Render to a DOM representation.

        @rtype: L{domish.Element}.
        """
        element = domish.Element((NS_DISCO_INFO, 'feature'))
        element['var'] = unicode(self)
        return element

Example 49

Project: wokkel Source File: test_component.py
Function: test_add_route
    def test_addRoute(self):
        """
        Test route registration and routing on incoming stanzas.
        """
        router = component.Router()
        routed = []
        router.route = lambda element: routed.append(element)

        pipe = XmlPipe()
        router.addRoute('example.org', pipe.sink)
        self.assertEquals(1, len(router.routes))
        self.assertEquals(pipe.sink, router.routes['example.org'])

        element = domish.Element(('testns', 'test'))
        pipe.source.send(element)
        self.assertEquals([element], routed)

Example 50

Project: wokkel Source File: test_data_form.py
    def test_fromElementInvalidElementName(self):
        """
        Bail if the passed element does not have the correct name.
        """
        element = domish.Element((NS_X_DATA, 'form'))
        self.assertRaises(Exception, data_form.Form.fromElement, element)
See More Examples - Go to Next Page
Page 1 Selected Page 2 Page 3 Page 4