예제 #1
0
파일: mam.py 프로젝트: 2M1R/SleekXMPP
    def retrieve(self, jid=None, start=None, end=None, with_jid=None, ifrom=None,
                 block=True, timeout=None, callback=None, iterator=False):
        iq = self.xmpp.Iq()
        query_id = iq['id']

        iq['to'] = jid
        iq['from'] = ifrom
        iq['type'] = 'get'
        iq['mam']['queryid'] = query_id
        iq['mam']['start'] = start
        iq['mam']['end'] = end
        iq['mam']['with'] = with_jid

        collector = Collector(
            'MAM_Results_%s' % query_id,
            StanzaPath('message/mam_result@queryid=%s' % query_id))
        self.xmpp.register_handler(collector)

        if iterator:
            return self.xmpp['xep_0059'].iterate(iq, 'mam', 'results')
        elif not block and callback is not None:
            def wrapped_cb(iq):
                results = collector.stop()
                if iq['type'] == 'result':
                    iq['mam']['results'] = results
                callback(iq)
            return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
        else:
            try:
                resp = iq.send(block=block, timeout=timeout, callback=callback)
                resp['mam']['results'] = collector.stop()
                return resp
            except XMPPError as e:
                collector.stop()
                raise e
예제 #2
0
    def view(self, nodes, ifrom=None, block=True, timeout=None, callback=None):
        if not isinstance(nodes, (list, set)):
            nodes = [nodes]

        iq = self.xmpp.Iq()
        iq['type'] = 'get'
        iq['from'] = ifrom
        offline = iq['offline']
        for node in nodes:
            item = stanza.Item()
            item['node'] = node
            item['action'] = 'view'
            offline.append(item)

        collector = Collector(
            'Offline_Results_%s' % iq['id'],
            StanzaPath('message/offline'))
        self.xmpp.register_handler(collector)

        if not block and callback is not None:
            def wrapped_cb(iq):
                results = collector.stop()
                if iq['type'] == 'result':
                    iq['offline']['results'] = results
                callback(iq)
            return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
        else:
            try:
                resp = iq.send(block=block, timeout=timeout, callback=callback)
                resp['offline']['results'] = collector.stop()
                return resp
            except XMPPError as e:
                collector.stop()
                raise e
예제 #3
0
    def fetch(self, ifrom=None, block=True, timeout=None, callback=None):
        iq = self.xmpp.Iq()
        iq['type'] = 'set'
        iq['from'] = ifrom
        iq['offline']['fetch'] = True

        collector = Collector(
            'Offline_Results_%s' % iq['id'],
            StanzaPath('message/offline'))
        self.xmpp.register_handler(collector)

        if not block and callback is not None:
            def wrapped_cb(iq):
                results = collector.stop()
                if iq['type'] == 'result':
                    iq['offline']['results'] = results
                callback(iq)
            return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
        else:
            try:
                resp = iq.send(block=block, timeout=timeout, callback=callback)
                resp['offline']['results'] = collector.stop()
                return resp
            except XMPPError as e:
                collector.stop()
                raise e
예제 #4
0
    def retrieve(self,
                 jid=None,
                 start=None,
                 end=None,
                 with_jid=None,
                 ifrom=None,
                 block=True,
                 timeout=None,
                 callback=None,
                 iterator=False):
        iq = self.xmpp.Iq()
        query_id = iq['id']

        iq['to'] = jid
        iq['from'] = ifrom
        iq['type'] = 'get'
        iq['mam']['queryid'] = query_id
        iq['mam']['start'] = start
        iq['mam']['end'] = end
        iq['mam']['with'] = with_jid

        collector = Collector(
            'MAM_Results_%s' % query_id,
            StanzaPath('message/mam_result@queryid=%s' % query_id))
        self.xmpp.register_handler(collector)

        if iterator:
            return self.xmpp['xep_0059'].iterate(iq, 'mam', 'results')
        elif not block and callback is not None:

            def wrapped_cb(iq):
                results = collector.stop()
                if iq['type'] == 'result':
                    iq['mam']['results'] = results
                callback(iq)

            return iq.send(block=block, timeout=timeout, callback=wrapped_cb)
        else:
            try:
                resp = iq.send(block=block, timeout=timeout, callback=callback)
                resp['mam']['results'] = collector.stop()
                return resp
            except XMPPError as e:
                collector.stop()
                raise e