• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

Python jid.internJID函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: resetHistory

 def resetHistory(self, room=None, frm=None):
     if room != None:
         # room needs to be a returned room hash from the backend
         if self.checkAdmin(room, jid.internJID(frm).userhost()):
             self.parent._clean_up_history(True, room['name'])
     elif jid.internJID(frm).userhost() in self.sadmins:
         self.HISTORY = {}
开发者ID:fritteli,项目名称:palaver,代码行数:7,代码来源:groupchat.py


示例2: _onDiscoItems

    def _onDiscoItems(self, iq):
        requestor = jid.internJID(iq["from"])
        target = jid.internJID(iq["to"])
        nodeIdentifier = iq.query.getAttribute("node", '')

        def toResponse(results):
            items = []
            for i in results:
                items.extend(i[1])

            response = domish.Element((NS_ITEMS, 'query'))

            for item in items:
                response.addChild(item)

            return response

        dl = []
        for handler in self.parent:
            if IDisco.providedBy(handler):
                dl.append(handler.getDiscoItems(requestor, target,
                                                nodeIdentifier))

        d = defer.DeferredList(dl, fireOnOneErrback=1, consumeErrors=1)
        d.addCallbacks(toResponse, self._error)
        return d
开发者ID:Urthen,项目名称:Legacy-FritBot,代码行数:26,代码来源:disco.py


示例3: cb

 def cb(subs):
     actual = [a.toElement().toXml() for a in subs]
     expected = [
         ps.Subscription(
             nodeIdentifier='node1',
             subscriber=jid.internJID('[email protected]').userhostJID(),
             state='subscribed'),
         ps.Subscription(
             nodeIdentifier='node2',
             subscriber=jid.internJID('[email protected]').userhostJID(),
             state='subscribed'),
         ps.Subscription(
             nodeIdentifier='node5',
             subscriber=jid.internJID('[email protected]').userhostJID(),
             state='unconfigured'),
         ps.Subscription(
             nodeIdentifier='node6',
             subscriber=jid.internJID('[email protected]').userhostJID(),
             state='subscribed',
             subscriptionIdentifier='123-abc'),
         ps.Subscription(
             nodeIdentifier='node6',
             subscriber=jid.internJID('[email protected]').userhostJID(),
             state='subscribed',
             subscriptionIdentifier='004-yyy'),
         ]
     self.assertEquals(len(actual), 5)
     for ex in expected:
         self.assertIn(ex.toElement().toXml(), actual)
     sendMock.assert_called_once_with(xs)
开发者ID:wyn,项目名称:collab,代码行数:30,代码来源:pubsubRequestWithAffiliationsTests.py


示例4: _onDiscoInfo

    def _onDiscoInfo(self, iq):
        """
        Called for incoming disco info requests.

        @param iq: The request iq element.
        @type iq: L{Element<twisted.words.xish.domish.Element>}
        """
        requestor = jid.internJID(iq["from"])
        target = jid.internJID(iq["to"])
        nodeIdentifier = iq.query.getAttribute("node", '')

        def toResponse(info):
            if nodeIdentifier and not info:
                raise error.StanzaError('item-not-found')
            else:
                response = DiscoInfo()
                response.nodeIdentifier = nodeIdentifier

                for item in info:
                    response.append(item)

            return response.toElement()

        d = self.info(requestor, target, nodeIdentifier)
        d.addCallback(toResponse)
        return d
开发者ID:B-Rich,项目名称:wokkel,代码行数:26,代码来源:disco.py


示例5: _onDiscoInfo

    def _onDiscoInfo(self, iq):
        requestor = jid.internJID(iq["from"])
        target = jid.internJID(iq["to"])
        nodeIdentifier = iq.query.getAttribute("node", '')

        def toResponse(results):
            info = []
            for i in results:
                info.extend(i[1])

            if nodeIdentifier and not info:
                raise error.StanzaError('item-not-found')
            else:
                response = domish.Element((NS_INFO, 'query'))

                for item in info:
                    response.addChild(item)

            return response

        dl = []
        for handler in self.parent:
            if IDisco.providedBy(handler):
                dl.append(handler.getDiscoInfo(requestor, target,
                                               nodeIdentifier))

        d = defer.DeferredList(dl, fireOnOneErrback=1, consumeErrors=1)
        d.addCallbacks(toResponse, self._error)
        return d
开发者ID:Urthen,项目名称:Legacy-FritBot,代码行数:29,代码来源:disco.py


示例6: dispatch

    def dispatch(self, xs, stanza):
        """
        Send a stanza to the router, checking some stuff first.
        """

        log.debug("stanza from %s: %s" % (xs.otherEntity.full(), stanza.toXml()))
        util.resetNamespace(stanza, xs.namespace)
        stanzaFrom = stanza.getAttribute('from')
        stanzaTo = stanza.getAttribute('to')

        if not stanza.bind and not stanzaFrom or not stanzaTo:
            xs.sendStreamError(error.StreamError('improper-addressing'))
        else:
            try:
                sender = jid.internJID(stanzaFrom)
                jid.internJID(stanzaTo)
            except jid.InvalidFormat:
                log.debug("dropping stanza with malformed JID")

            log.debug("sender = %s, otherEntity = %s" % (sender.full(), xs.otherEntity.full()))

            try:
                unused, host = util.jid_component(sender.host)
                if host in self.keyring.hostlist():
                    self.router.send(stanza)
                else:
                    raise Exception()
            except:
                xs.sendStreamError(error.StreamError('invalid-from'))
开发者ID:MilanovicB,项目名称:xmppserver,代码行数:29,代码来源:net.py


示例7: test_identity

 def test_identity(self):
     """
     Test that two interned JIDs yield the same object.
     """
     j1 = jid.internJID("[email protected]")
     j2 = jid.internJID("[email protected]")
     self.assertIdentical(j1, j2)
开发者ID:JohnDoes95,项目名称:project_parser,代码行数:7,代码来源:test_jabberjid.py


示例8: incomingIq

	def incomingIq(self, el):
		itype = el.getAttribute("type")
		fro = el.getAttribute("from")
		froj = internJID(fro)
		to = el.getAttribute("to")
		toj = internJID(to)
		ID = el.getAttribute("id")
开发者ID:anton-ryzhov,项目名称:pyicqt_auto_reconnect,代码行数:7,代码来源:pubsub.py


示例9: dispatch

    def dispatch(self, xs, stanza):
        """
        Send a stanza to the router, checking some stuff first.
        """

        log.debug("stanza from %s: %s" % (xs.otherEntity.full(), stanza.toXml()))
        util.resetNamespace(stanza, xs.namespace)
        stanzaFrom = stanza.getAttribute('from')
        stanzaTo = stanza.getAttribute('to')

        if not stanzaFrom or not stanzaTo:
            xs.sendStreamError(error.StreamError('improper-addressing'))
        else:
            try:
                sender = jid.internJID(stanzaFrom)
                jid.internJID(stanzaTo)
            except jid.InvalidFormat:
                log.debug("dropping stanza with malformed JID")

            log.debug("sender = %s, otherEntity = %s" % (sender.full(), xs.otherEntity.full()))
            if sender.host != xs.otherEntity.host and sender.host != self.defaultDomain:
                xs.sendStreamError(error.StreamError('invalid-from'))
            else:
                # replace to with destination
                destination = stanza.getAttribute('destination')
                if destination:
                    stanza['to'] = destination
                    del stanza['destination']
                self.router.send(stanza)
开发者ID:BillTheBest,项目名称:xmppserver,代码行数:29,代码来源:net.py


示例10: createRoom

    def createRoom(self, room, frm, nick, status = None, show = None, legacy = True, host=None):
        """
        Create and join the room
        """

        def created(rname):
            self.parent.HISTORY[room] = []
            return self.joinRoom(room, frm, nick,
                                 status = status,
                                 show   = show,
                                 legacy = legacy,
                                 host   = host,
                                 do_check = False)

        def create_room(doCreate, error_code=NotAllowed):
            if not doCreate:
                raise error_code

            d = self.parent.storage.createRoom(room, jid.internJID(frm).userhost(), legacy=legacy, host=host)
            d.addCallback(created)
            return d

        if self.create_rooms == 1 or jid.internJID(frm).userhost() in self.sadmins:
            if self.plugins and self.plugins.has_key('create-room'):
                d = self.plugins['create-room'].create(room, jid.internJID(frm).userhost(), legacy=legacy, host=host)
                d.addCallback(create_room, error_code = NotMember)
            else:
                d = create_room(True)

            return d
        else:
            raise NotAllowed
开发者ID:fritteli,项目名称:palaver,代码行数:32,代码来源:groupchat.py


示例11: set_kick

        def set_kick(r, user):
            if self.checkAdmin(r, admin):
                kuser = None
                if self.checkOwner(r, user):
                    raise NotAllowed
                user_check = jid.internJID(user).userhost().lower()
                for u in r['roster'].values():
                    if jid.internJID(u['jid']).userhost().lower() == user_check \
                           or u['nick'] == user:
                        kuser = u['jid']
                        knick = u['nick']
                        if self.checkSelf(user, admin):
                            raise NotAllowed

                        if self.checkAdmin(r, user):
                            raise NotAllowed
                        r['roster'][u['jid'].lower()]['role'] = 'none'
                        r['roster'][u['jid'].lower()]['affiliation'] = 'none'
                        break
                if not kuser:
                    raise RoomNotFound
                d = self.parent.storage.partRoom(room, kuser, knick, host=host)
                d.addCallback(ret_kick, room, r['roster'])
                d.addErrback(lambda x: self.error(NotAllowed, x))
                return d
            else:
                raise NotAllowed
开发者ID:fritteli,项目名称:palaver,代码行数:27,代码来源:groupchat.py


示例12: _check_sadmin

 def _check_sadmin(self, room, user):
     juser = jid.internJID(user).userhost().lower()
     members = self.sadmins
     for m in members:
         if jid.internJID(m).userhost().lower() == juser:
             return True
     return False
开发者ID:fritteli,项目名称:palaver,代码行数:7,代码来源:groupchat.py


示例13: valid

 def valid(xs):
     reply('valid')
     if not self.xmlstream.thisEntity:
         self.xmlstream.thisEntity = jid.internJID(receivingServer)
     self.xmlstream.otherEntity = jid.internJID(originatingServer)
     self.xmlstream.dispatch(self.xmlstream,
                             xmlstream.STREAM_AUTHD_EVENT)
开发者ID:thepaul,项目名称:wokkel,代码行数:7,代码来源:server.py


示例14: incomingRegisterIq

 def incomingRegisterIq(self, incoming):
     # Check what type the Iq is..
     itype = incoming.getAttribute("type")
     LogEvent(INFO)
     if itype == "get":
         if config.authRegister:
             # Check to see if they're registered
             source = internJID(incoming.getAttribute("from")).userhost()
             result = self.pytrans.xdb.getRegistration(source)
             if result:
                 self.sendRegistrationFields(incoming)
             else:
                 # Must first submit local credentials
                 self.sendLocalRegistrationFields(incoming)
         else:
             # Send real registration form
             self.sendRegistrationFields(incoming)
     elif itype == "set":
         if config.authRegister:
             # Check to see if they're registered by local credentials
             source = internJID(incoming.getAttribute("from")).userhost()
             result = self.pytrans.xdb.getRegistration(source)
             username = ""
             password = ""
             if result:
                 username, password = result
             if username == "local" and password == "local":
                 # Update real credentials
                 self.updateRegistration(incoming)
             else:
                 # Must first validate local credentials
                 self.validateLocalRegistration(incoming)
         else:
             # Update real credentials
             self.updateRegistration(incoming)
开发者ID:2mf,项目名称:pyicqt,代码行数:35,代码来源:register.py


示例15: handle_action

    def handle_action(self, action):
        self.log.debug('XMPP ACTION : {0!r}'.format(action))

        if action.action_type != 'message':
            return

        body = str(action.meta.get('body'))
        if not body:
            return

        if not action.destination_rooms:
            return

        for room in action.destination_rooms:
            if action.scope == 'public':
                room_jid = jid.internJID(room)
                message = muc.GroupChat(recipient=room_jid, body=body)
                self.client.send(message.toElement())

            if action.scope == 'private':
                if room is not None:
                    msg = xmppim.Message(recipient=jid.internJID(room),
                                         sender=self.bot_jid,
                                         body=body)
                    self.client.send(msg.toElement())
开发者ID:xlcteam,项目名称:brutal-ng,代码行数:25,代码来源:xmpp.py


示例16: postOptions

    def postOptions(self):
        if not self['jid']:
            raise usage.UsageError("Missing client JID")
        else:
            try:
                self['jid'] = jid.internJID(self['jid'])
            except jid.invalidFormat:
                raise usage.UsageError("Invalid client JID")

        if self['secret'] is None:
            raise usage.UsageError("Missing client secret")

        if not self['service']:
            raise usage.UsageError("Missing publish-subscribe service JID")
        else:
            try:
                self['service'] = jid.internJID(self['service'])
            except jid.invalidFormat:
                raise usage.UsageError("Invalid publish-subscribe service JID")

        try:
            self['twitter-oauth-consumer'] = OAuthConsumer(
                key=self['twitter-oauth-consumer-key'],
                secret=self['twitter-oauth-consumer-secret'])
            self['twitter-oauth-token'] = OAuthToken(
                key=self['twitter-oauth-token-key'],
                secret=self['twitter-oauth-token-secret'])
        except KeyError:
            self['twitter-oauth-consumer'] = None
            self['twitter-oauth-token'] = None
            if not self['twitter-user'] or not self['twitter-password']:
                raise usage.UsageError("Missing twitter credentials")
开发者ID:mediamatic,项目名称:ikdisplay,代码行数:32,代码来源:tap.py


示例17: createPurger

def createPurger(domain, service, node, username, password, debug=False):
    
    factory = client.DeferredClientFactory(jid.internJID(username), password)
    factory.streamManager.logTraffic = debug

    purger = Purger(jid.internJID(service), node)
    purger.setHandlerParent(factory.streamManager)

    yield client.clientCreator(factory)
开发者ID:twonds,项目名称:thetofu.com,代码行数:9,代码来源:purge.py


示例18: onActivateStream

    def onActivateStream(self, iq):

        try:
            fromJID = jid.internJID(iq["from"])
            
            # check the sender is authorized
            if self.allowed_domains and fromJID.host not in self.allowed_domains:
                raise UnauthorizedException
            
            activateJID = jid.internJID(unicode(iq.query.activate)).full()
            sid = hashSID(
                iq.query["sid"].encode("utf-8"), fromJID.full().encode("utf-8"), activateJID.encode("utf-8")
            )
            log.msg("Activation requested for: ", sid)

            # Get list of objects for this sid
            olist = self.pendingConns[sid]

            # Remove sid from pending
            del self.pendingConns[sid]

            # Ensure there are the correct # of participants
            if len(olist) != 2:
                log.msg("Activation for %s failed: insufficient participants", sid)
                raise UnauthorizedException
                   
            # Send iq result
            iq.swapAttributeValues("to", "from")
            iq["type"] = "result"
            iq.query.children = []
            self.send(iq)
            
            # Remove sid from pending and mark as active
            assert sid not in self.activeConns
            self.activeConns[sid] = None
        
            # Complete connection
            log.msg("Activating ", sid)
            olist[0].peersock = olist[1]
            olist[1].peersock = olist[0]
            olist[0].transport.registerProducer(olist[1], 0)
            olist[1].transport.registerProducer(olist[0], 0)
        except UnauthorizedException, e:
            # Send an error
            iq.swapAttributeValues("to", "from")
            iq["type"] = "error"
            iq.query.children = []
            e = iq.addElement("error")
            e["code"] = "405"
            e["type"] = "cancel"
            c = e.addElement("not-allowed")
            c["xmlns"] = "urn:ietf:params:xml:ns:xmpp-stanzas"
            self.send(iq)
                
            # Close all connected
            for c in olist:
                c.transport.loseConnection()
开发者ID:BackupGGCode,项目名称:proxy65,代码行数:57,代码来源:proxy65.py


示例19: set_member

 def set_member(r, user):
     mjid = None
     if r == None:
         raise RoomNotFound
     
     if self.checkAdmin(r, admin):
         juser = jid.internJID(user)
         
         # TODO - clean this up
         roster = r['roster']
         set_role = False
         
         for m in roster.values():
             idx = m['jid'].lower()
             rjid = jid.internJID(m['jid'])
             if juser.resource:
                 mjids = rjid.full().lower()
             else:
                 mjids = rjid.userhost().lower()
                 
             if mjids == user.lower() or m['nick'].lower() == user.lower():
                 if self.checkSelf(m['jid'], admin):
                     raise NotAllowed
                 
                 # if self.checkAdmin(r, m['jid']):
                 #    raise NotAllowed
                 mjid = m['jid']
                 if roster[idx]['role'] == 'none' or \
                    roster[idx]['role'] == 'visitor' or \
                    roster[idx]['role'] == 'player':
                     roster[idx]['role'] = 'participant'
                     set_role = True
                 roster[idx]['affiliation'] = 'member'
                 break
         
         dlist = []
         if user:
             # This sets it in storage
             dm = self.parent.storage.setMember(room, user, host = host)
             
             dlist.append(dm)
             
         if mjid and set_role:
             # This sets it in the roster
             dr = self.parent.storage.setRole(room, mjid, 'participant', host=host)
             
             dlist.append(dr)
             
             
         d = defer.DeferredList(dlist)
         d.addErrback(lambda x: self.error(NotAllowed, x))
         d.addCallback(lambda _: roster)
         return d
         
     else:
         raise NotAllowed
开发者ID:fritteli,项目名称:palaver,代码行数:56,代码来源:groupchat.py


示例20: sendPresence

def sendPresence(pytrans, to, fro, show=None, status=None, priority=None, ptype=None, avatarHash=None, nickname=None, payload=[], url=None):
    if ptype in ["subscribe", "subscribed", "unsubscribe", "unsubscribed"]:
        to = internJID(to).userhost()
        fro = internJID(fro).userhost()

    el = Element((None, "presence"))
    el.attributes["to"] = to
    el.attributes["from"] = fro
    if ptype:
        el.attributes["type"] = ptype
    if show:
        s = el.addElement("show")
        s.addContent(utils.xmlify(show))
    if status:
        s = el.addElement("status")
        s.addContent(utils.xmlify(status))
    if priority:
        s = el.addElement("priority")
        s.addContent(priority)
    if url:
        s = el.addElement("x")
        s.attributes["xmlns"] = globals.XOOB
        s = el.addElement("url")
        s.addContent(url)

    if not ptype:
        if avatarHash and not config.disableAvatars and not config.disableVCardAvatars:
            x = el.addElement("x")
            x.attributes["xmlns"] = globals.VCARDUPDATE
            p = x.addElement("photo")
            p.addContent(avatarHash)

        if nickname:
            x = el.addElement("x")
            x.attributes["xmlns"] = globals.VCARDUPDATE
            n = x.addElement("nickname")
            n.addContent(nickname)

        if avatarHash and not config.disableAvatars and not config.disableIQAvatars:
            x = el.addElement("x")
            x.attributes["xmlns"] = globals.XAVATAR
            h = x.addElement("hash")
            h.addContent(avatarHash)

        if nickname and ptype == "subscribe":
            n = el.addElement("nick")
            n.attributes["xmlns"] = globals.NICK
            n.addContent(nickname)

    if payload:
        for p in payload:
            el.addChild(p)

    pytrans.send(el)
开发者ID:2mf,项目名称:pyicqt,代码行数:54,代码来源:jabw.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python jid.JID类代码示例发布时间:2022-05-27
下一篇:
Python error.exceptionFromStanza函数代码示例发布时间:2022-05-27
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap