twisted.words.protocols.jabber.jid.JID

Here are the examples of the python api twisted.words.protocols.jabber.jid.JID taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

199 Examples 7

Example 1

Project: idavoll
Source File: test_gateway.py
View license
    def test_basic(self):
        """
        getServiceAndNode parses an XMPP URI with node parameter.
        """
        uri = b'xmpp:pubsub.example.org?;node=test'
        service, nodeIdentifier = gateway.getServiceAndNode(uri)
        self.assertEqual(JID(u'pubsub.example.org'), service)
        self.assertEqual(u'test', nodeIdentifier)

Example 2

Project: idavoll
Source File: test_gateway.py
View license
    def test_queryEmpty(self):
        """
        If there is no query component, the nodeIdentifier is empty.
        """
        uri = b'xmpp:pubsub.example.org'
        service, nodeIdentifier = gateway.getServiceAndNode(uri)

        self.assertEqual(JID(u'pubsub.example.org'), service)
        self.assertEqual(u'', nodeIdentifier)

Example 3

Project: idavoll
Source File: test_gateway.py
View license
    def test_nodeAbsent(self):
        """
        If the node parameter is missing, the nodeIdentifier is empty.
        """
        uri = b'xmpp:pubsub.example.org?'
        service, nodeIdentifier = gateway.getServiceAndNode(uri)

        self.assertEqual(JID(u'pubsub.example.org'), service)
        self.assertEqual(u'', nodeIdentifier)

Example 4

Project: wokkel
Source File: disco.py
View license
    @staticmethod
    def fromElement(element):
        """
        Parse a DOM representation into a L{DiscoItem} instance.

        @param element: Element that represents the disco iitem.
        @type element: L{domish.Element}.
        @rtype L{DiscoItem}.
        """
        try:
            entity = jid.JID(element.getAttribute('jid', ' '))
        except jid.InvalidFormat:
            entity = None
        nodeIdentifier = element.getAttribute('node', '')
        name = element.getAttribute('name')
        feature = DiscoItem(entity, nodeIdentifier, name)
        return feature

Example 5

Project: wokkel
Source File: muc.py
View license
    @classmethod
    def fromElement(Class, element):
        item = Class()

        if element.hasAttribute('jid'):
            item.entity = jid.JID(element['jid'])

        item.nick = element.getAttribute('nick')
        item.affiliation = element.getAttribute('affiliation')
        item.role = element.getAttribute('role')

        for child in element.elements(NS_MUC_ADMIN, 'reason'):
            item.reason = unicode(child)

        return item

Example 6

Project: wokkel
Source File: muc.py
View license
    def nick(self, roomJID, nick):
        """
        Change an entity's nick name in a MUC room.

        See: http://xmpp.org/extensions/xep-0045.html#changenick

        @param roomJID: The JID of the room.
        @type roomJID: L{JID<twisted.words.protocols.jabber.jid.JID>}

        @param nick: The new nick name within the room.
        @type nick: L{unicode}
        """
        occupantJID = jid.JID(tuple=(roomJID.user, roomJID.host, nick))
        presence = BasicPresence(recipient=occupantJID)
        return self._sendDeferred(presence)

Example 7

Project: wokkel
Source File: test_client.py
View license
    def test_jidWhenInitialized(self):
        """
        Make sure that upon login, the JID is updated from the authenticator.
        """
        xs = self.client.factory.buildProtocol(None)
        self.client.factory.authenticator.jid = JID('[email protected]/test')
        xs.dispatch(xs, xmlstream.STREAM_AUTHD_EVENT)
        self.assertEquals(JID('[email protected]/test'), self.client.jid)

Example 8

Project: wokkel
Source File: test_component.py
View license
    def setUp(self):
        self.router = component.Router()
        self.factory = component.XMPPComponentServerFactory(self.router,
                                                            'secret')
        self.xmlstream = self.factory.buildProtocol(None)
        self.xmlstream.thisEntity = JID('component.example.org')

Example 9

Project: wokkel
Source File: test_data_form.py
View license
    def test_toElementJID(self):
        """
        A JID value should render to text.
        """
        field = data_form.Field(fieldType='jid-single', var='test',
                                value=jid.JID(u'[email protected]'))
        element = field.toElement()
        self.assertEqual(u'[email protected]', unicode(element.value))

Example 10

Project: wokkel
Source File: test_data_form.py
View license
    def test_toElementJIDTextSingle(self):
        """
        A JID value should render to text if field type is text-single.
        """
        field = data_form.Field(fieldType='text-single', var='test',
                                value=jid.JID(u'[email protected]'))
        element = field.toElement()
        self.assertEqual(u'[email protected]', unicode(element.value))

Example 11

Project: wokkel
Source File: test_data_form.py
View license
    def test_typeCheckJID(self):
        """
        The value of jid field should be a JID or coercable to one.
        """
        field = data_form.Field(fieldType='jid-single', var='test',
                                value=jid.JID('[email protected]'))
        field.typeCheck()

Example 12

Project: wokkel
Source File: test_data_form.py
View license
    def test_typeCheckJIDString(self):
        """
        The string value of jid field should be coercable into a JID.
        """
        field = data_form.Field(fieldType='jid-single', var='test',
                                value='[email protected]')
        field.typeCheck()
        self.assertEquals(jid.JID(u'[email protected]'), field.value)

Example 13

Project: wokkel
Source File: test_data_form.py
View license
    def test_makeFieldsUnknownTypeJID(self):
        """
        Without type, a single JID value sets field type jid-single.
        """
        values = {'pubsub#creator': jid.JID('[email protected]')}
        form = data_form.Form('result')
        form.makeFields(values)

        field = form.fields['pubsub#creator']
        self.assertEqual(None, field.fieldType)
        self.assertEqual(values, form.getValues())

Example 14

Project: wokkel
Source File: test_data_form.py
View license
    def test_makeFieldsUnknownTypeJIDMulti(self):
        """
        Without type, multiple JID values sets field type jid-multi.
        """
        values = {'pubsub#contact': [jid.JID('[email protected]'),
                                     jid.JID('[email protected]')]}
        form = data_form.Form('result')
        form.makeFields(values)

        field = form.fields['pubsub#contact']
        self.assertEqual(None, field.fieldType)
        self.assertEqual(values, form.getValues())

Example 15

Project: wokkel
Source File: test_delay.py
View license
    def test_toElement(self):
        """
        The DOM structure has the serialized timestamp and sender address.
        """
        delay = Delay(stamp=datetime(2002, 9, 10, 23, 8, 25,
                                  tzinfo=dateutil.tz.tzutc()),
                      sender=JID(u'[email protected]'))
        element = delay.toElement()

        self.assertEqual(u'urn:xmpp:delay', element.uri)
        self.assertEqual(u'delay', element.name)
        self.assertEqual(u'2002-09-10T23:08:25Z', element.getAttribute('stamp'))
        self.assertEqual(u'[email protected]', element.getAttribute('from'))

Example 16

Project: wokkel
Source File: test_delay.py
View license
    def test_toElementLegacy(self):
        """
        The legacy format uses C{CCYYMMDDThh:mm:ss} in the old namespace.
        """
        delay = Delay(stamp=datetime(2002, 9, 10, 23, 8, 25,
                                  tzinfo=dateutil.tz.tzutc()),
                      sender=JID(u'[email protected]'))
        element = delay.toElement(legacy=True)

        self.assertEqual(u'jabber:x:delay', element.uri)
        self.assertEqual(u'x', element.name)
        self.assertEqual(u'20020910T23:08:25', element.getAttribute('stamp'))
        self.assertEqual(u'[email protected]', element.getAttribute('from'))

Example 17

Project: wokkel
Source File: test_delay.py
View license
    def test_fromElementSender(self):
        """
        The optional original sender address is parsed as a JID.
        """
        xml = parseXml(u"""
            <delay xmlns="urn:xmpp:delay" stamp="2002-09-10T23:08:25Z"
                                          from="[email protected]"/>
        """)

        delay = Delay.fromElement(xml)
        self.assertEqual(JID(u'[email protected]'), delay.sender)

Example 18

Project: wokkel
Source File: test_disco.py
View license
    def test_init(self):
        """
        Test initialization with a category, type and name.
        """
        item = disco.DiscoItem(JID(u'example.org'), u'test', u'The node')
        self.assertEqual(JID(u'example.org'), item.entity)
        self.assertEqual(u'test', item.nodeIdentifier)
        self.assertEqual(u'The node', item.name)

Example 19

Project: wokkel
Source File: test_disco.py
View license
    def test_toElement(self):
        """
        Test proper rendering to a DOM representation.

        The returned element should be properly named and have C{jid}, C{node},
        and C{name} attributes.
        """
        item = disco.DiscoItem(JID(u'example.org'), u'test', u'The node')
        element = item.toElement()
        self.assertEqual(NS_DISCO_ITEMS, element.uri)
        self.assertEqual(u'item', element.name)
        self.assertEqual(u'example.org', element.getAttribute(u'jid'))
        self.assertEqual(u'test', element.getAttribute(u'node'))
        self.assertEqual(u'The node', element.getAttribute(u'name'))

Example 20

Project: wokkel
Source File: test_disco.py
View license
    def test_toElementWithoutName(self):
        """
        Test proper rendering to a DOM representation without a name.

        The returned element should be properly named and have C{jid}, C{node}
        attributes, no C{name} attribute.
        """
        item = disco.DiscoItem(JID(u'example.org'), u'test')
        element = item.toElement()
        self.assertEqual(NS_DISCO_ITEMS, element.uri)
        self.assertEqual(u'item', element.name)
        self.assertEqual(u'example.org', element.getAttribute(u'jid'))
        self.assertEqual(u'test', element.getAttribute(u'node'))
        self.assertFalse(element.hasAttribute(u'name'))

Example 21

Project: wokkel
Source File: test_disco.py
View license
    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 22

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

Example 23

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

Example 24

Project: wokkel
Source File: test_disco.py
View license
    def test_toElementChildren(self):
        """
        Test C{toElement} creates a DOM with proper childs.
        """
        items = disco.DiscoItems()
        items.append(disco.DiscoItem(JID(u'example.org'), u'test', u'A node'))
        element = items.toElement()

        itemElements = domish.generateElementsQNamed(element.children,
                                                     u'item',
                                                     NS_DISCO_ITEMS)
        self.assertEqual(1, len(list(itemElements)))

Example 25

Project: wokkel
Source File: test_disco.py
View license
    def test_fromElement(self):
        """
        Test creating L{disco.DiscoItems} from L{domish.Element}.
        """
        xml = """<query xmlns='http://jabber.org/protocol/disco#items'>
                   <item jid='example.org' node='test' name='A node'/>
                 </query>"""

        element = parseXml(xml)
        items = disco.DiscoItems.fromElement(element)

        items = list(items)
        self.assertEqual(1, len(items))
        item = items[0]

        self.assertEqual(JID(u'example.org'), item.entity)
        self.assertEqual(u'test', item.nodeIdentifier)
        self.assertEqual(u'A node', item.name)

Example 26

Project: wokkel
Source File: test_disco.py
View license
    def test_requestItemsFrom(self):
        """
        A disco items request can be sent with an explicit sender address.
        """
        d = self.protocol.requestItems(JID(u'example.org'),
                                       sender=JID(u'test.example.org'))

        iq = self.stub.output[-1]
        self.assertEqual(u'test.example.org', iq.getAttribute(u'from'))

        response = toResponse(iq, u'result')
        response.addElement((NS_DISCO_ITEMS, u'query'))

        d.callback(response)
        return d

Example 27

Project: wokkel
Source File: test_disco.py
View license
    def test_requestInfoFrom(self):
        """
        A disco info request can be sent with an explicit sender address.
        """
        d = self.protocol.requestInfo(JID(u'example.org'),
                                      sender=JID(u'test.example.org'))

        iq = self.stub.output[-1]
        self.assertEqual(u'test.example.org', iq.getAttribute(u'from'))

        response = toResponse(iq, u'result')
        response.addElement((NS_DISCO_INFO, u'query'))

        d.callback(response)
        return d

Example 28

Project: wokkel
Source File: test_generic.py
View license
    def test_fromElement(self):
        xml = """
        <message type='chat' from='[email protected]' to='[email protected]'/>
        """

        stanza = generic.Stanza.fromElement(generic.parseXml(xml))
        self.assertEqual('chat', stanza.stanzaType)
        self.assertEqual(JID('[email protected]'), stanza.sender)
        self.assertEqual(JID('[email protected]'), stanza.recipient)

Example 29

Project: wokkel
Source File: test_generic.py
View license
    def test_toElementRecipient(self):
        """
        A request without recipient, has no 'to' attribute.
        """
        self.request = generic.Request(recipient=JID('[email protected]'))
        self.assertEquals(JID('[email protected]'), self.request.recipient)
        element = self.request.toElement()
        self.assertEquals(u'[email protected]', element.getAttribute('to'))

Example 30

Project: wokkel
Source File: test_generic.py
View license
    def test_toElementSender(self):
        """
        A request with sender, has a 'from' attribute.
        """
        self.request = generic.Request(sender=JID('[email protected]'))
        self.assertEquals(JID('[email protected]'), self.request.sender)
        element = self.request.toElement()
        self.assertEquals(u'[email protected]', element.getAttribute('from'))

Example 31

Project: wokkel
Source File: test_ping.py
View license
    def test_ping(self):
        """
        Pinging a service should fire a deferred with None
        """
        def cb(result):
            self.assertIdentical(None, result)

        d = self.protocol.ping(JID("example.com"))
        d.addCallback(cb)

        iq = self.stub.output[-1]
        self.assertEqual(u'example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'get', iq.getAttribute(u'type'))
        self.assertEqual('urn:xmpp:ping', iq.ping.uri)

        response = toResponse(iq, u'result')
        self.stub.send(response)

        return d

Example 32

Project: wokkel
Source File: test_ping.py
View license
    def test_pingWithSender(self):
        """
        Pinging a service with a sender address should include that address.
        """
        d = self.protocol.ping(JID("example.com"),
                               sender=JID('[email protected]'))

        iq = self.stub.output[-1]
        self.assertEqual(u'[email protected]', iq.getAttribute(u'from'))

        response = toResponse(iq, u'result')
        self.stub.send(response)

        return d

Example 33

Project: wokkel
Source File: test_ping.py
View license
    def test_pingNotSupported(self):
        """
        Pinging a service should fire a deferred with None if not supported.
        """
        def cb(result):
            self.assertIdentical(None, result)

        d = self.protocol.ping(JID("example.com"))
        d.addCallback(cb)

        iq = self.stub.output[-1]

        exc = StanzaError('service-unavailable')
        response = exc.toResponse(iq)
        self.stub.send(response)

        return d

Example 34

Project: wokkel
Source File: test_ping.py
View license
    def test_pingStanzaError(self):
        """
        Pinging a service should errback a deferred on other (stanza) errors.
        """
        def cb(exc):
            self.assertEquals('item-not-found', exc.condition)

        d = self.protocol.ping(JID("example.com"))
        self.assertFailure(d, StanzaError)
        d.addCallback(cb)

        iq = self.stub.output[-1]

        exc = StanzaError('item-not-found')
        response = exc.toResponse(iq)
        self.stub.send(response)

        return d

Example 35

Project: wokkel
Source File: test_ping.py
View license
    def test_getDiscoInfo(self):
        """
        The ping namespace should be returned as a supported feature.
        """
        def cb(info):
            discoInfo = disco.DiscoInfo()
            for item in info:
                discoInfo.append(item)
            self.assertIn('urn:xmpp:ping', discoInfo.features)

        d = defer.maybeDeferred(self.protocol.getDiscoInfo,
                                JID('[email protected]/home'),
                                JID('pubsub.example.org'),
                                '')
        d.addCallback(cb)
        return d

Example 36

Project: wokkel
Source File: test_ping.py
View license
    def test_getDiscoInfoNode(self):
        """
        The ping namespace should not be returned for a node.
        """
        def cb(info):
            discoInfo = disco.DiscoInfo()
            for item in info:
                discoInfo.append(item)
            self.assertNotIn('urn:xmpp:ping', discoInfo.features)

        d = defer.maybeDeferred(self.protocol.getDiscoInfo,
                                JID('[email protected]/home'),
                                JID('pubsub.example.org'),
                                'test')
        d.addCallback(cb)
        return d

Example 37

Project: wokkel
Source File: test_ping.py
View license
    def test_getDiscoItems(self):
        """
        Items are not supported by this handler, so an empty list is expected.
        """
        def cb(items):
            self.assertEquals(0, len(items))

        d = defer.maybeDeferred(self.protocol.getDiscoItems,
                                JID('[email protected]/home'),
                                JID('pubsub.example.org'),
                                '')
        d.addCallback(cb)
        return d

Example 38

Project: wokkel
Source File: test_server.py
View license
    def test_streamToOtherLocalHost(self):
        """
        The authenticator supports XMPP 1.0 streams.
        """
        self.xmlstream.connectionMade()
        self.xmlstream.dataReceived(
            "<stream:stream xmlns:stream='http://etherx.jabber.org/streams' "
                           "xmlns:db='jabber:server:dialback' "
                           "xmlns='jabber:server' "
                           "to='pubsub.xmpp.example.com' "
                           "version='1.0'>")

        self.assertEqual(2, len(self.output))
        self.assertEqual(jid.JID('pubsub.xmpp.example.com'),
                         self.xmlstream.thisEntity)

Example 39

Project: wokkel
Source File: test_server.py
View license
    def setUp(self):
        self.service = FakeService()
        self.factory = server.XMPPS2SServerFactory(self.service)
        self.xmlstream = self.factory.buildProtocol(None)
        self.transport = StringTransport()
        self.xmlstream.thisEntity = jid.JID('example.org')
        self.xmlstream.otherEntity = jid.JID('example.com')

Example 40

Project: wokkel
Source File: test_server.py
View license
    def setUp(self):
        self.output = []

        self.xmlstream = xmlstream.XmlStream(xmlstream.Authenticator())
        self.xmlstream.thisEntity = jid.JID('example.org')
        self.xmlstream.otherEntity = jid.JID('example.com')
        self.xmlstream.send = self.output.append

        self.router = component.Router()
        self.service = server.ServerService(self.router,
                                            secret='mysecret',
                                            domain='example.org')
        self.service.xmlstream = self.xmlstream

Example 41

Project: wokkel
Source File: test_xmppim.py
View license
    def test_unavailableDirected(self):
        """
        Test sending of directed unavailable presence broadcast.
        """

        self.protocol.unavailable(JID('[email protected]'))
        presence = self.output[-1]
        self.assertEquals("presence", presence.name)
        self.assertEquals(None, presence.uri)
        self.assertEquals("[email protected]", presence.getAttribute('to'))
        self.assertEquals("unavailable", presence.getAttribute('type'))

Example 42

Project: wokkel
Source File: test_xmppim.py
View license
    def test_unavailableWithStatus(self):
        """
        Test sending of directed unavailable presence broadcast with status.
        """

        self.protocol.unavailable(JID('[email protected]'),
                                  {None: 'Disconnected'})
        presence = self.output[-1]
        self.assertEquals("presence", presence.name)
        self.assertEquals(None, presence.uri)
        self.assertEquals("[email protected]", presence.getAttribute('to'))
        self.assertEquals("unavailable", presence.getAttribute('type'))
        self.assertEquals("Disconnected", unicode(presence.status))

Example 43

Project: wokkel
Source File: test_xmppim.py
View license
    def test_fromElement(self):
        xml = """<presence from='[email protected]' to='[email protected]'>
                   <show>chat</show>
                   <status>Let's chat!</status>
                   <priority>50</priority>
                 </presence>
              """

        presence = xmppim.AvailabilityPresence.fromElement(parseXml(xml))
        self.assertEquals(JID('[email protected]'), presence.sender)
        self.assertEquals(JID('[email protected]'), presence.recipient)
        self.assertTrue(presence.available)
        self.assertEquals('chat', presence.show)
        self.assertEquals({None: "Let's chat!"}, presence.statuses)
        self.assertEquals(50, presence.priority)

Example 44

Project: wokkel
Source File: test_xmppim.py
View license
    def test_available(self):
        """
        It should be possible to pass a sender address.
        """
        self.protocol.available(JID('[email protected]'),
                                show=u'chat',
                                status=u'Talk to me!',
                                priority=50)
        element = self.output[-1]
        self.assertEquals("[email protected]", element.getAttribute('to'))
        self.assertIdentical(None, element.getAttribute('type'))
        self.assertEquals(u'chat', unicode(element.show))
        self.assertEquals(u'Talk to me!', unicode(element.status))
        self.assertEquals(u'50', unicode(element.priority))

Example 45

Project: wokkel
Source File: test_xmppim.py
View license
    def test_availableSender(self):
        """
        It should be possible to pass a sender address.
        """
        self.protocol.available(JID('[email protected]'),
                                sender=JID('[email protected]'))
        element = self.output[-1]
        self.assertEquals("[email protected]", element.getAttribute('from'))

Example 46

Project: wokkel
Source File: test_xmppim.py
View license
    def test_unavailableDirected(self):
        """
        Test sending of directed unavailable presence broadcast.
        """

        self.protocol.unavailable(JID('[email protected]'))
        element = self.output[-1]
        self.assertEquals("presence", element.name)
        self.assertEquals(None, element.uri)
        self.assertEquals("[email protected]", element.getAttribute('to'))
        self.assertEquals("unavailable", element.getAttribute('type'))

Example 47

Project: wokkel
Source File: test_xmppim.py
View license
    def test_unavailableWithStatus(self):
        """
        Test sending of directed unavailable presence broadcast with status.
        """

        self.protocol.unavailable(JID('[email protected]'),
                                  {None: 'Disconnected'})
        element = self.output[-1]
        self.assertEquals("presence", element.name)
        self.assertEquals(None, element.uri)
        self.assertEquals("[email protected]", element.getAttribute('to'))
        self.assertEquals("unavailable", element.getAttribute('type'))
        self.assertEquals("Disconnected", unicode(element.status))

Example 48

Project: wokkel
Source File: test_xmppim.py
View license
    def test_unavailableSender(self):
        """
        It should be possible to pass a sender address.
        """
        self.protocol.unavailable(JID('[email protected]'),
                                  sender=JID('[email protected]'))
        element = self.output[-1]
        self.assertEquals("[email protected]", element.getAttribute('from'))

Example 49

Project: wokkel
Source File: test_xmppim.py
View license
    def test_subscribeSender(self):
        """
        It should be possible to pass a sender address.
        """
        self.protocol.subscribe(JID('[email protected]'),
                                sender=JID('[email protected]'))
        element = self.output[-1]
        self.assertEquals("[email protected]", element.getAttribute('from'))

Example 50

Project: wokkel
Source File: test_xmppim.py
View license
    def test_unsubscribeSender(self):
        """
        It should be possible to pass a sender address.
        """
        self.protocol.unsubscribe(JID('[email protected]'),
                                  sender=JID('[email protected]'))
        element = self.output[-1]
        self.assertEquals("[email protected]", element.getAttribute('from'))