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


Python Client.send方法代码示例

本文整理汇总了Python中pyxmpp2.client.Client.send方法的典型用法代码示例。如果您正苦于以下问题:Python Client.send方法的具体用法?Python Client.send怎么用?Python Client.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pyxmpp2.client.Client的用法示例。


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

示例1: transmissionRobot

# 需要导入模块: from pyxmpp2.client import Client [as 别名]
# 或者: from pyxmpp2.client.Client import send [as 别名]

#.........这里部分代码省略.........
        seconds for graceful disconnection."""
        self.client.disconnect()
        self.client.run(timeout = 2)

    @presence_stanza_handler("subscribe")
    def handle_presence_subscribe(self, stanza):
        logging.info(u"{0} requested presence subscription"
                                                    .format(stanza.from_jid))
        presence = Presence(to_jid = stanza.from_jid.bare(),
                                                    stanza_type = "subscribe")
        return [stanza.make_accept_response(), presence]

    @presence_stanza_handler("subscribed")
    def handle_presence_subscribed(self, stanza):
        logging.info(u"{0!r} accepted our subscription request"
                                                    .format(stanza.from_jid))
        return True

    @presence_stanza_handler("unsubscribe")
    def handle_presence_unsubscribe(self, stanza):
        logging.info(u"{0} canceled presence subscription"
                                                    .format(stanza.from_jid))
        presence = Presence(to_jid = stanza.from_jid.bare(),
                                                    stanza_type = "unsubscribe")
        return [stanza.make_accept_response(), presence]

    @presence_stanza_handler("unsubscribed")
    def handle_presence_unsubscribed(self, stanza):
        logging.info(u"{0!r} acknowledged our subscrption cancelation"
                                                    .format(stanza.from_jid))
        return True

    @message_stanza_handler()
    def handle_message(self, stanza):
        messagebody='Robot connected.'
        if stanza.body=="connect":
            if not stanza.from_jid.local in self.userlist:
                self.userlist[stanza.from_jid.local]=stanza.from_jid;
            else:
                messagebody="Already connected."
            msg = Message(stanza_type = stanza.stanza_type,
                        from_jid = self.client.jid, to_jid = stanza.from_jid,
                        subject = None, body = messagebody,
                        thread = stanza.thread)
            return msg
        elif stanza.body=="disconnect":
            messagebody="Robot disconnected."
            try:
                del self.userlist[stanza.from_jid.local];
            except:
                messagebody="Already disconnected"
            msg = Message(stanza_type = stanza.stanza_type,
                        from_jid = self.client.jid, to_jid = stanza.from_jid,
                        subject = None, body = messagebody,
                        thread = stanza.thread)
            return msg
        
        if stanza.from_jid.local+'@'+stanza.from_jid.domain in SUBSCRIBERS:
            try:
                #print stanza.body
                torrent=self.rpc.add_torrent(stanza.body,timeout=10)
            except:
                return True
            messagebody="Torrent added: "+str(torrent)
            msg = Message(stanza_type = stanza.stanza_type,
                        from_jid = self.client.jid, to_jid = stanza.from_jid,
                        subject = None, body = messagebody,
                        thread = stanza.thread)
            return msg
        return True

    @event_handler(DisconnectedEvent)
    def handle_disconnected(self, event):
        """Quit the main loop upon disconnection."""
        return QUIT
        
    
    @event_handler()
    def handle_all(self, event):
        """Log all events."""
        logging.info(u"-- {0}".format(event))
        
    @timeout_handler(3,True)
    def handle_transmission_query(self):
        print "Checking transmission daemon."
        torrentlist=self.rpc.get_torrents()
        for torrent in torrentlist:
            if torrent.doneDate>0 and torrent.hashString in self.lastcycle:
                del self.lastcycle[torrent.hashString]
                messagebody="Torrent finished: "+ torrent.name + ". https://cloud.xiw.im/index.php/apps/files?dir=/Transmission"
                print messagebody
                for i in self.userlist:
                    msg = Message(stanza_type = "normal",
                        from_jid = self.client.jid, to_jid = self.userlist[i],
                        subject = None, body = messagebody,
                        thread = None)
                    self.client.send(msg)
            elif torrent.doneDate<=0 and not torrent.hashString in self.lastcycle:
                self.lastcycle[torrent.hashString]=1
        return 3
开发者ID:xiw9,项目名称:transmission-gtalk-bot,代码行数:104,代码来源:transmissionRobot.py


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