当前位置: 首页>>代码示例>>Python>>正文


Python xmlstream.IQ类代码示例

本文整理汇总了Python中twisted.words.protocols.jabber.xmlstream.IQ的典型用法代码示例。如果您正苦于以下问题:Python IQ类的具体用法?Python IQ怎么用?Python IQ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IQ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: getNodeConfiguration

    def getNodeConfiguration(self, service, nodeIdentifier):

        def cb(result):
            fields = [field
                      for field in result.pubsub.configure.x.children
                      if field[u'type']!=u'hidden']
            result = dict()
            for field in fields:
                value = None
                try:
                    value = field.value.children[0]
                except (AttributeError, IndexError):
                    pass
                result[field['var']] = value
            logger.info("Got node config  %s: %s ." % (nodeIdentifier, result))
            return result

        def error(failure):
            # TODO: Handle gracefully?
            logger.error(failure.getTraceback())
            return []

        iq = IQ(self.xmlstream, 'get')
        iq['to'] = service.full()
        pubsub = iq.addElement((NS_PUBSUB_OWNER, 'pubsub'))
        configure = pubsub.addElement('configure')
        configure['node'] = nodeIdentifier
        d = iq.send()
        d.addCallbacks(cb, error)
        return d
开发者ID:Blaastolen,项目名称:jarn.xmpp.twisted,代码行数:30,代码来源:protocols.py

示例2: _acceptInvitation

 def _acceptInvitation(self, jid, url, conf):
     '''
         Sends IQ message with <session><accept /></session> and opens window with given app
         @param jid: JID of user on the other side
         @param url: URL of app ww are invited in
         @param conf: configuration object
     '''
     iq = IQ(self.main.client.xmlstream, 'set')
     iq['xml:lang'] = self.main.client.xmlLang
     iq['type'] = 'set'
     iq['to'] = jid + '/jabbim'
     q = iq.addElement('query')
     q['xmlns']='http://xawa.vaisar.cz'
     s = q.addElement('session')
     s.addElement('accept')
     s['appUrl'] = url
     self.main.client.disp(iq['id'])
     d = iq.send()
            
     ##open window with app
     self.openWindow()
     self.loadApp(url)
     self.loadConfiguration(conf)
     
     return d
开发者ID:incik,项目名称:XAWA,代码行数:25,代码来源:xawa.py

示例3: modifyAffiliations

    def modifyAffiliations(self, service, nodeIdentifier, delta):
        def cb(result):
            if result["type"] == u"result":
                log.info("Modified affiliations for %s: %s ." % (nodeIdentifier, delta))
                return True
            return False

        def error(failure):
            # TODO: Handle gracefully?
            log.error(failure.getTraceback())
            return False

        iq = IQ(self.xmlstream, "set")
        iq["to"] = service.full()
        pubsub = iq.addElement((NS_PUBSUB_OWNER, "pubsub"))
        affiliations = pubsub.addElement("affiliations")
        affiliations["node"] = nodeIdentifier
        for jid, affiliation in delta:
            el = affiliations.addElement("affiliation")
            el["jid"] = jid.userhost()
            el["affiliation"] = affiliation

        d = iq.send()
        d.addCallbacks(cb, error)
        return d
开发者ID:collective,项目名称:collective.xmpp.core,代码行数:25,代码来源:protocols.py

示例4: resultReceived

        def resultReceived(result):
            items = [item.attributes for item in result.query.children]
            if items[0].has_key('node'):
                for item in reversed(items):
                    iq = IQ(client.admin.xmlstream, 'get')
                    iq['to'] = getXMPPDomain(site)
                    query = iq.addElement((NS_DISCO_ITEMS, 'query'))
                    query['node'] = item['node']
                    iq.send().addCallbacks(resultReceived)
            else:
                subscribe_jids = [item['jid'] for item in items]
                if settings.admin_jid in subscribe_jids:
                    subscribe_jids.remove(settings.admin_jid)

                if subscribe_jids:
                    getJID = lambda uid: JID(
                        "%[email protected]%s" % (escapeNode(uid), settings.xmpp_domain))
                    roster_jids = [getJID(user_id.split('@')[0])
                                   for user_id in subscribe_jids]

                    for member_jid in member_jids:
                        client.chat.sendRosterItemAddSuggestion(member_jid,
                                                                roster_jids,
                                                                site)
                        log.info('Roster suggestion sent for %s' % member_jid)
                    # XXX: Somehow the last user's roster suggestions is
                    # dropped, unless we rest here for a bit.
                    time.sleep(3)
            return result
开发者ID:collective,项目名称:collective.xmpp.core,代码行数:29,代码来源:setup.py

示例5: resultReceived

        def resultReceived(result):
            items = [item.attributes for item in result.query.children]
            if 'node' in items[0]:
                for item in reversed(items):
                    iq = IQ(client.admin.xmlstream, 'get')
                    iq['to'] = settings.xmpp_domain
                    query = iq.addElement((NS_DISCO_ITEMS, 'query'))
                    query['node'] = item['node']
                    iq.send().addCallbacks(resultReceived)
            else:
                member_jids = [item['jid'] for item in items]
                if settings.admin_jid in member_jids:
                    member_jids.remove(settings.admin_jid)
                registered_member_dicts = \
                    [d for d in member_dicts if d['jabberid'] in member_jids]

                @newzodbconnection(portal=portal)
                def updateVCard():
                    mdict = registered_member_dicts.pop()
                    setup.setVCard(
                        mdict,
                        mdict['jid_obj'],
                        mdict['pass'],
                        updateVCard)

                if len(registered_member_dicts):
                    zr = getUtility(IZopeReactor)
                    zr.reactor.callInThread(updateVCard)
            return
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:29,代码来源:controlpanel.py

示例6: getNodeConfiguration

    def getNodeConfiguration(self, service, nodeIdentifier):
        def cb(result):
            fields = [field for field in result.pubsub.configure.x.children if field[u"type"] != u"hidden"]
            result = dict()
            for field in fields:
                value = None
                try:
                    value = field.value.children[0]
                except (AttributeError, IndexError):
                    pass
                result[field["var"]] = value
            log.info("Got node config  %s: %s ." % (nodeIdentifier, result))
            return result

        def error(failure):
            # TODO: Handle gracefully?
            log.error(failure.getTraceback())
            return []

        iq = IQ(self.xmlstream, "get")
        iq["to"] = service.full()
        pubsub = iq.addElement((NS_PUBSUB_OWNER, "pubsub"))
        configure = pubsub.addElement("configure")
        configure["node"] = nodeIdentifier
        d = iq.send()
        d.addCallbacks(cb, error)
        return d
开发者ID:collective,项目名称:collective.xmpp.core,代码行数:27,代码来源:protocols.py

示例7: createIQ

 def createIQ(self, udict):
     """ <FN>Jeremie Miller</FN>
         <NICKNAME>jer</NICKNAME>
         <EMAIL><INTERNET/><PREF/><USERID>[email protected]</USERID></EMAIL>
         <URL>http://www.xmpp.org/xsf/people</URL>
         <JABBERID>[email protected]</JABBERID>
         <PHOTO>
             <TYPE>image/jpeg</TYPE>
             <BINVAL>
                 Base64-encoded-avatar-file-here!
             </BINVAL>
         </PHOTO>
     """
     iq = IQ(self.xmlstream, "set")
     vcard = iq.addElement((NS_VCARD_TEMP, "vCard"))
     vcard["version"] = "3.0"
     vcard.addElement("FN", content=udict.get("fullname"))
     vcard.addElement("NICKNAME", content=udict.get("nickname"))
     email = vcard.addElement("EMAIL", content=udict.get("email"))
     email.addElement("INTERNET")
     email.addElement("PREF")
     email.addElement("USERID", content=udict.get("userid"))
     vcard.addElement("JABBERID", content=udict.get("jabberid"))
     vcard.addElement("URL", content=udict.get("url"))
     photo = vcard.addElement("PHOTO")
     if udict.get("image_type") and udict.get("raw_image"):
         photo.addElement("TYPE", content=udict.get("image_type"))
         photo.addElement("BINVAL", content=base64.b64encode(udict["raw_image"]))
     return iq
开发者ID:collective,项目名称:collective.xmpp.core,代码行数:29,代码来源:protocols.py

示例8: publishNode

    def publishNode(self, nodeName, lock=True):
        if self.xmlStream is None:
            # We lost our connection
            self.unlockNode(None, nodeName)
            return

        try:
            if lock and not self.lockNode(nodeName):
                return

            iq = IQ(self.xmlStream)
            pubsubElement = iq.addElement('pubsub', defaultUri=self.pubsubNS)
            publishElement = pubsubElement.addElement('publish')
            publishElement['node'] = nodeName
            if self.settings["NodeConfiguration"]["pubsub#deliver_payloads"] == '1':
                itemElement = publishElement.addElement('item')
                itemElement.addElement('plistfrag', defaultUri='plist-apple')

            self.sendDebug("Publishing (%s)" % (nodeName,), iq)
            d = iq.send(to=self.settings['ServiceAddress'])
            d.addCallback(self.publishNodeSuccess, nodeName)
            d.addErrback(self.publishNodeFailure, nodeName)
        except:
            self.unlockNode(None, nodeName)
            raise
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:25,代码来源:notify.py

示例9: requestRoster

 def requestRoster(self):
     if self.doRoster:
         self.roster = {}
         rosterIq = IQ(self.xmlStream, 'get')
         rosterIq.addElement("query", "jabber:iq:roster")
         d = rosterIq.send()
         d.addCallback(self.handleRoster)
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:7,代码来源:notify.py

示例10: modifyAffiliations

    def modifyAffiliations(self, service, nodeIdentifier, delta):

        def cb(result):
            if result['type']==u'result':
                logger.info("Modified affiliations for %s: %s ." % \
                    (nodeIdentifier, delta))
                return True
            return False

        def error(failure):
            # TODO: Handle gracefully?
            logger.error(failure.getTraceback())
            return False

        iq = IQ(self.xmlstream, 'set')
        iq['to'] = service.full()
        pubsub = iq.addElement((NS_PUBSUB_OWNER, 'pubsub'))
        affiliations = pubsub.addElement('affiliations')
        affiliations['node']=nodeIdentifier
        for jid, affiliation in delta:
            el = affiliations.addElement('affiliation')
            el['jid'] = jid.userhost()
            el['affiliation'] = affiliation

        d = iq.send()
        d.addCallbacks(cb, error)
        return d
开发者ID:Blaastolen,项目名称:jarn.xmpp.twisted,代码行数:27,代码来源:protocols.py

示例11: getAffiliations

    def getAffiliations(self, service, nodeIdentifier):

        def cb(result):
            affiliations = result.pubsub.affiliations
            result = []
            for affiliate in affiliations.children:
                result.append((JID(affiliate['jid']),
                               affiliate['affiliation'], ))
            logger.info("Got affiliations for %s: %s ." % \
                (nodeIdentifier, result))
            return result

        def error(failure):
            # TODO: Handle gracefully?
            logger.error(failure.getTraceback())
            return []

        iq = IQ(self.xmlstream, 'get')
        iq['to'] = service.full()
        pubsub = iq.addElement((NS_PUBSUB_OWNER, 'pubsub'))
        affiliations = pubsub.addElement('affiliations')
        affiliations['node']=nodeIdentifier
        d = iq.send()
        d.addCallbacks(cb, error)
        return d
开发者ID:Blaastolen,项目名称:jarn.xmpp.twisted,代码行数:25,代码来源:protocols.py

示例12: ping

    def ping(self, entity, sender=None):
        """
        Send out a ping request and wait for a response.

        @param entity: Entity to be pinged.
        @type entity: L{JID<twisted.words.protocols.jabber.jid.JID>}

        @return: A deferred that fires upon receiving a response.
        @rtype: L{Deferred<twisted.internet.defer.Deferred>}

        @param sender: Optional sender address.
        @type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
        """
        def cb(response):
            return None

        def eb(failure):
            failure.trap(StanzaError)
            exc = failure.value
            if exc.condition == 'service-unavailable':
                return None
            else:
                return failure

        request = IQ(self.xmlstream, 'get')
        request.addElement((NS_PING, 'ping'))

        if sender is not None:
            request['from'] = sender.full()

        d = request.send(entity.full())
        d.addCallbacks(cb, eb)
        return d
开发者ID:ralphm,项目名称:wokkel,代码行数:33,代码来源:ping.py

示例13: sendInvite

 def sendInvite(self,jid,appInfo):
     '''
         Sends IQ message with invitation
         @param jid: JID of the user on the other side
         @param appInfo: basic info about app                        
     '''
     iq = IQ(self.main.client.xmlstream, 'set')
     iq['xml:lang'] = self.main.client.xmlLang
     iq['type'] = 'set'
     iq['to'] = jid + '/jabbim'
     q = iq.addElement('query')
     q['xmlns']='http://xawa.vaisar.cz'
     s = q.addElement('session')
     if (appInfo != None):
         s['appName'] = appInfo['appName']
         s['appUrl'] = appInfo['appUrl']
     s.addElement('invite')
     
     conf = s.addElement('configuration')
     conf.addChild(json.dumps(appInfo)) # puts whole string inside the tag
     
     self.main.client.disp(iq['id'])
     d = iq.send()
     
     return d
开发者ID:incik,项目名称:XAWA,代码行数:25,代码来源:xawa.py

示例14: handlePresence

    def handlePresence(self, iq):
        self.log_debug("Presence IQ: %s" %
            (iq.toXml().encode('ascii', 'replace')),)
        presenceType = iq.getAttribute('type')

        if presenceType == 'subscribe':
            frm = JID(iq['from']).userhost()
            if self.allowedInRoster(frm):
                self.roster[frm] = { 'debug' : False, 'available' : True }
                response = domish.Element(('jabber:client', 'presence'))
                response['to'] = iq['from']
                response['type'] = 'subscribed'
                self.xmlStream.send(response)

                # request subscription as well
                subscribe = domish.Element(('jabber:client', 'presence'))
                subscribe['to'] = iq['from']
                subscribe['type'] = 'subscribe'
                self.xmlStream.send(subscribe)
            else:
                self.log_info("JID not allowed in roster: %s" % (frm,))
                # Reject
                response = domish.Element(('jabber:client', 'presence'))
                response['to'] = iq['from']
                response['type'] = 'unsubscribed'
                self.xmlStream.send(response)

        elif presenceType == 'unsubscribe':
            frm = JID(iq['from']).userhost()
            if self.roster.has_key(frm):
                del self.roster[frm]
            response = domish.Element(('jabber:client', 'presence'))
            response['to'] = iq['from']
            response['type'] = 'unsubscribed'
            self.xmlStream.send(response)

            # remove from roster as well
            # XXX This codepath is not unit tested
            removal = IQ(self.xmlStream, 'set')
            query = removal.addElement("query", "jabber:iq:roster")
            query.addElement("item")
            query.item["jid"] = iq["from"]
            query.item["subscription"] = "remove"
            removal.send()

        elif presenceType == 'unavailable':
            frm = JID(iq['from']).userhost()
            if self.roster.has_key(frm):
                self.roster[frm]['available'] = False

        else:
            frm = JID(iq['from']).userhost()
            if self.allowedInRoster(frm):
                if self.roster.has_key(frm):
                    self.roster[frm]['available'] = True
                else:
                    self.roster[frm] = { 'debug' : False, 'available' : True }
            else:
                self.log_info("JID not allowed in roster: %s" % (frm,))
开发者ID:svn2github,项目名称:calendarserver-raw,代码行数:59,代码来源:notify.py

示例15: retrieveSubscriptions

 def retrieveSubscriptions(self):
     # This isn't supported by Apple's pubsub service
     iq = IQ(self.xmlStream)
     pubsubElement = iq.addElement("pubsub", defaultUri=self.pubsubNS)
     pubsubElement.addElement("subscriptions")
     print "Requesting list of subscriptions"
     try:
         yield iq.send(to=self.service)
     except Exception, e:
         print "Subscription list failure: %s" % (e,)
开发者ID:azbarcea,项目名称:calendarserver,代码行数:10,代码来源:notifications.py


注:本文中的twisted.words.protocols.jabber.xmlstream.IQ类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。