How to use nbxmpp - 10 common examples

To help you get started, we’ve selected a few nbxmpp examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github gajim / gajim / gajim / common / modules / bytestream.py View on Github external
"""
        if not app.account_is_available(self._account):
            return
        file_props = FilesProp.getFileProp(self._account, sid)
        if file_props is None:
            log.error('can not send iq error on failed transfer')
            return
        if file_props.type_ == 's':
            to = file_props.receiver
        else:
            to = file_props.sender
        iq = nbxmpp.Iq(to=to, typ='error')
        iq.setAttr('id', file_props.request_id)
        err = iq.setTag('error')
        err.setAttr('type', error_type)
        err.setTag(error, namespace=Namespace.STANZAS)
        self._con.connection.send(iq)
        if msg:
            self.disconnect_transfer(file_props)
            file_props.error = -3
            app.nec.push_incoming_event(
                NetworkEvent('file-request-error',
                             conn=self._con,
                             jid=app.get_jid_without_resource(to),
                             file_props=file_props,
                             error_msg=msg))
github gajim / gajim / gajim / common / modules / bytestream.py View on Github external
def _connect_error(self, sid, error, error_type, msg=None):
        """
        Called when there is an error establishing BS connection, or when
        connection is rejected
        """
        if not app.account_is_available(self._account):
            return
        file_props = FilesProp.getFileProp(self._account, sid)
        if file_props is None:
            log.error('can not send iq error on failed transfer')
            return
        if file_props.type_ == 's':
            to = file_props.receiver
        else:
            to = file_props.sender
        iq = nbxmpp.Iq(to=to, typ='error')
        iq.setAttr('id', file_props.request_id)
        err = iq.setTag('error')
        err.setAttr('type', error_type)
        err.setTag(error, namespace=Namespace.STANZAS)
        self._con.connection.send(iq)
        if msg:
            self.disconnect_transfer(file_props)
            file_props.error = -3
            app.nec.push_incoming_event(
                NetworkEvent('file-request-error',
                             conn=self._con,
                             jid=app.get_jid_without_resource(to),
                             file_props=file_props,
                             error_msg=msg))
github gajim / gajim / test / gtk / dataform.py View on Github external
def __init__(self):
        Gtk.Window.__init__(self, title="Data Form Test")
        self.set_default_size(600, 600)
        options = {
            'left-width': 100,
            'form-width': 435,
        }
        self._widget = DataFormWidget(
            extend_form(node=nbxmpp.Node(node=FORM)), options)
        self.add(self._widget)
        self.show()
github gajim / gajim / gajim / common / modules / bytestream.py View on Github external
BaseModule.__init__(self, con)

        self.handlers = [
            StanzaHandler(name='iq',
                          typ='result',
                          ns=Namespace.BYTESTREAM,
                          callback=self._on_bytestream_result),
            StanzaHandler(name='iq',
                          typ='error',
                          ns=Namespace.BYTESTREAM,
                          callback=self._on_bytestream_error),
            StanzaHandler(name='iq',
                          typ='set',
                          ns=Namespace.BYTESTREAM,
                          callback=self._on_bytestream_set),
            StanzaHandler(name='iq',
                          typ='result',
                          callback=self._on_result),
        ]

        self.no_gupnp_reply_id = None
        self.ok_id = None
        self.fail_id = None
github gajim / gajim / gajim / common / modules / bytestream.py View on Github external
def _on_result(self, _con, iq_obj, _properties):
        # if we want to respect xep-0065 we have to check for proxy
        # activation result in any result iq
        real_id = iq_obj.getAttr('id')
        if real_id is None:
            log.warning('Invalid IQ without id attribute:\n%s', iq_obj)
            raise nbxmpp.NodeProcessed
        if real_id is None or not real_id.startswith('au_'):
            return
        frm = self._ft_get_from(iq_obj)
        id_ = real_id[3:]
        file_props = FilesProp.getFilePropByTransportSid(self._account, id_)
        if file_props.streamhost_used:
            for host in file_props.proxyhosts:
                if host['initiator'] == frm and 'idx' in host:
                    app.socks5queue.activate_proxy(host['idx'])
                    raise nbxmpp.NodeProcessed
github gajim / gajim / test / broken / no_gui / test_protocol_caps.py View on Github external
def test_capsPresenceCB(self):
        fjid = "user@server.com/a"

        xml = """
            
            
        """ % (fjid)
        msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
        self.module._presence_received(None, msg)
github gajim / gajim / test / broken / integration / test_gui_event_integration.py View on Github external
def contact_goes_offline(self, account, jid, resource, prio,
    still_exists = True):
        '''a remote contact goes offline.'''
        xml = """
            %s
            
            Goodbye!
            
        """ % (jid, resource, prio)
        msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
        gajim.connections[account]._presenceCB(None, msg)

        contact = None
        for c in gajim.contacts.get_contacts(account, jid):
            if c.resource == resource:
                contact = c
                break

        if not still_exists:
            self.assertTrue(contact is None)
            return

        self.assertEqual('offline', contact.show)
        self.assertEqual('Goodbye!', contact.status)
        self.assertEqual(prio, contact.priority)
github gajim / gajim / test / broken / unit / test_sessions.py View on Github external
def receive_chat_msg(self, jid, msgtxt):
        '''simulate receiving a chat message from jid'''
        msg = nbxmpp.Message()
        msg.setBody(msgtxt)
        msg.setType('chat')

        xml = """%s
            123""" % (jid, msgtxt)
        stanza = nbxmpp.protocol.Message(node=nbxmpp.simplexml.XML2Node(xml))
        self.conn._messageCB(None, stanza)
github gajim / gajim / test / broken / integration / test_gui_event_integration.py View on Github external
def contact_comes_online(self, account, jid, resource, prio,
    should_popup=True):
        '''a remote contact comes online'''
        xml = """%s
            
            I'm back!
            
        """ % (jid, resource, prio)
        msg = nbxmpp.protocol.Presence(node=nbxmpp.simplexml.XML2Node(xml))
        gajim.connections[account]._presenceCB(None, msg)

        contact = None
        for c in gajim.contacts.get_contacts(account, jid):
            if c.resource == resource:
                contact = c
                break

        self.assertEqual('online', contact.show)
        self.assertEqual("I'm back!", contact.status)
        self.assertEqual(prio, contact.priority)

        # the most recent notification is that the contact connected
        if should_popup:
            self.assertEqual('Contact Signed In',
                notify.notifications[-1].popup_event_type)
github gajim / gajim / gajim / application.py View on Github external
return

        for uri in uris:
            app.log('uri_handler').info('open %s', uri)
            if not uri.startswith('xmpp:'):
                continue
            # remove xmpp:
            uri = uri[5:]
            try:
                jid, cmd = uri.split('?')
            except ValueError:
                # No query argument
                jid, cmd = uri, 'message'

            try:
                jid = JID(jid)
            except InvalidJid as error:
                app.log('uri_handler').warning('Invalid JID %s: %s', uri, error)
                continue

            if cmd == 'join' and jid.getResource():
                app.log('uri_handler').warning('Invalid MUC JID %s', uri)
                continue

            jid = str(jid)

            if cmd == 'join':
                if len(accounts) == 1:
                    self.activate_action(
                        'groupchat-join',
                        GLib.Variant('as', [accounts[0], jid]))
                else: