コード例 #1
0
ファイル: pubsub.py プロジェクト: thomasnet-mc/python-nbxmpp
    def set_access_model(self, node, model):
        task = yield

        if model not in ('open', 'presence'):
            raise ValueError('Invalid access model')

        result = yield self.get_node_configuration(node)

        raise_if_error(result)

        try:
            access_model = result.form['pubsub#access_model'].value
        except Exception:
            yield task.set_error('warning',
                                 condition='access-model-not-supported')

        if access_model == model:
            jid = self._client.get_bound_jid().new_as_bare()
            yield CommonResult(jid=jid)

        result.form['pubsub#access_model'].value = model

        result = yield self.set_node_configuration(node, result.form)

        yield finalize(task, result)
コード例 #2
0
    def set_avatar(self, avatar, public=False):

        task = yield

        access_model = 'open' if public else 'presence'

        if avatar is None:
            result = yield self._publish_avatar_metadata(None, access_model)
            raise_if_error(result)

            result = yield self.delete(Namespace.AVATAR_DATA)
            yield finalize(task, result)

        result = yield self._publish_avatar(avatar, access_model)

        yield finalize(task, result)
コード例 #3
0
    def retract_bookmark(self, bookmark_jid):
        task = yield

        self._log.info('Retract Bookmark: %s', bookmark_jid)

        result = yield self.retract(Namespace.BOOKMARKS_1, str(bookmark_jid))
        yield finalize(task, result)
コード例 #4
0
    def set_access_model(self, public):
        task = yield

        access_model = 'open' if public else 'presence'

        result = yield self._client.get_module('PubSub').set_access_model(
            Namespace.NICK, access_model)

        yield finalize(task, result)
コード例 #5
0
    def set_mood(self, data):
        task = yield

        item = Node('mood', {'xmlns': Namespace.MOOD})
        if data is not None and data.mood:
            item.addChild(data.mood)

            if data.text:
                item.addChild('text', payload=data.text)

        result = yield self.publish(Namespace.MOOD, item, id_='current')

        yield finalize(task, result)
コード例 #6
0
    def set_location(self, data):
        task = yield

        item = Node('geoloc', {'xmlns': Namespace.LOCATION})
        if data is not None:
            data = data._asdict()
            for tag, value in data.items():
                if value is not None:
                    item.addChild(tag, payload=value)

        result = yield self.publish(Namespace.LOCATION, item, id_='current')

        yield finalize(task, result)
コード例 #7
0
    def set_activity(self, data):
        task = yield

        item = Node('activity', {'xmlns': Namespace.ACTIVITY})
        if data is not None and data.activity:
            activity_node = item.addChild(data.activity)
            if data.subactivity:
                activity_node.addChild(data.subactivity)
            if data.text:
                item.addChild('text', payload=data.text)

        result = yield self.publish(Namespace.ACTIVITY, item, id_='current')

        yield finalize(task, result)
コード例 #8
0
    def set_access_model(self, public):
        task = yield

        access_model = 'open' if public else 'presence'

        result = yield self._client.get_module('PubSub').set_access_model(
            Namespace.AVATAR_DATA, access_model)

        raise_if_error(result)

        result = yield self._client.get_module('PubSub').set_access_model(
            Namespace.AVATAR_METADATA, access_model)

        yield finalize(task, result)
コード例 #9
0
    def set_secret_key(self, secret_key):
        task = yield

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': 'whitelist',
        }

        self._log.info('Set secret key')

        result = yield self.publish(Namespace.OPENPGP_SK,
                                    _make_secret_key(secret_key),
                                    id_='current',
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #10
0
    def set_public_key(self, key, fingerprint, date, public=True):
        task = yield

        access_model = 'open' if public else 'presence'

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        result = yield self.publish(f'{Namespace.OPENPGP_PK}:{fingerprint}',
                                    _make_public_key(key, date),
                                    id_='current',
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #11
0
    def request_parameters(self, jid):
        task = yield

        response = yield _make_parameter_request(jid)
        if response.isError():
            raise StanzaError(response)

        search = response.getTag('search', namespace=Namespace.MUCLUMBUS)
        if search is None:
            raise MalformedStanzaError('search node missing', response)

        dataform = search.getTag('x', namespace=Namespace.DATA)
        if dataform is None:
            raise MalformedStanzaError('dataform node missing', response)

        self._log.info('Muclumbus parameters received')
        yield finalize(task, extend_form(node=dataform))
コード例 #12
0
ファイル: omemo.py プロジェクト: thomasnet-mc/python-nbxmpp
    def set_devicelist(self, devicelist=None, public=True):
        task = yield

        access_model = 'open' if public else 'presence'

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        result = yield self.publish(Namespace.OMEMO_TEMP_DL,
                                    _make_devicelist(devicelist),
                                    id_='current',
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #13
0
    def set_keylist(self, keylist, public=True):
        task = yield

        access_model = 'open' if public else 'presence'

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        result = yield self.publish(Namespace.OPENPGP_PK,
                                    _make_keylist(keylist),
                                    id_='current',
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #14
0
    def set_vcard(self, vcard, public=False):
        task = yield

        access_model = 'open' if public else 'presence'

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        result = yield self.publish(Namespace.VCARD4_PUBSUB,
                                    vcard.to_node(),
                                    id_='current',
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #15
0
ファイル: omemo.py プロジェクト: thomasnet-mc/python-nbxmpp
    def set_bundle(self, bundle, device_id, public=True):
        task = yield

        access_model = 'open' if public else 'presence'

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        result = yield self.publish(
            f'{Namespace.OMEMO_TEMP_BUNDLE}:{device_id}',
            _make_bundle(bundle),
            id_='current',
            options=options,
            force_node_options=True)

        yield finalize(task, result)
コード例 #16
0
    def _publish_avatar_metadata(self, metadata, access_model):
        task = yield

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        if metadata is None:
            metadata = AvatarMetaData()

        result = yield self.publish(Namespace.AVATAR_METADATA,
                                    metadata.to_node(),
                                    id_=metadata.default,
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #17
0
    def set_nickname(self, nickname, public=False):
        task = yield

        access_model = 'open' if public else 'presence'

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        item = Node('nick', {'xmlns': Namespace.NICK})
        if nickname is not None:
            item.addData(nickname)

        result = yield self.publish(Namespace.NICK,
                                    item,
                                    id_='current',
                                    options=options,
                                    force_node_options=True)

        yield finalize(task, result)
コード例 #18
0
    def _publish_avatar(self, avatar, access_model):
        task = yield

        options = {
            'pubsub#persist_items': 'true',
            'pubsub#access_model': access_model,
        }

        for info, data in avatar.pubsub_avatar_info():
            item = _make_avatar_data_node(data)

            result = yield self.publish(Namespace.AVATAR_DATA,
                                        item,
                                        id_=info.id,
                                        options=options,
                                        force_node_options=True)

            raise_if_error(result)

        result = yield self._publish_avatar_metadata(avatar.metadata,
                                                     access_model)

        yield finalize(task, result)