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


Python client.Client类代码示例

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


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

示例1: __init__

    def __init__(self):
        my_jid = JID(USER+'/Bot')
        self.my_jid = my_jid
        settings = XMPPSettings({
                            "software_name": "qxbot",
                            "software_version": __version__,
                            "software_os": "Linux",
                            "tls_verify_peer": False,
                            "starttls": True,
                            "ipv6":False,
                            "poll_interval": 10,
                            })

        settings["password"] = PASSWORD
        version_provider = VersionProvider(settings)
        event_queue = settings["event_queue"]
        self.webqq = WebQQ(QQ, event_queue)
        self.connected = False
        #self.mainloop = TornadoMainLoop(settings)
        self.mainloop = EpollMainLoop(settings)
        self.client = Client(my_jid, [self, version_provider],
                             settings, self.mainloop)
        self.logger = get_logger()
        self.msg_dispatch = MessageDispatch(self, self.webqq, BRIDGES)
        self.xmpp_msg_queue = Queue.Queue()
开发者ID:DanyPlay,项目名称:qxbot,代码行数:25,代码来源:qxbot.py

示例2: __init__

 def __init__(self):
     self.droid = android.Android()
     settings = XMPPSettings({"software_name": "Say Chat"})
     settings["jid"] = self.droid.dialogGetInput("Google Talk Username").result
     settings["password"] = self.droid.dialogGetInput("Google Talk Password").result
     settings["server"] = "talk.google.com"
     settings["starttls"] = True
     self.client = Client(JID(settings["jid"]), [self, VersionProvider(settings)], settings)
开发者ID:RockySteveJobs,项目名称:python-for-android,代码行数:8,代码来源:say_chat.py

示例3: __init__

 def __init__(self, my_jid, settings, myname, events, text):
     version_provider = VersionProvider(settings)
     self.client = Client(my_jid, [self, version_provider], settings)
     self.myname = myname  # first and last name of user
     self.logs = {}
     self.parser = ttp.Parser()  # twitter text processing lib handler
     self.events = events
     self.do_text = text
     self.last_msg = ""
开发者ID:dsyang,项目名称:rodney,代码行数:9,代码来源:chat-rest.py

示例4: __init__

 def __init__(self, jid, settings):
   if 'software_name' not in settings:
     settings['software_name'] = self.__class__.__name__
   if 'software_version' not in settings:
     settings['software_version'] = __version__
   version_provider = VersionProvider(settings)
   self.client = Client(jid, [self, version_provider], settings)
   self.presence = defaultdict(dict)
   self.subscribes = ExpiringDictionary(default_timeout=5)
   self.invited = {}
开发者ID:firefoxmmx2,项目名称:xmpptalk,代码行数:10,代码来源:main.py

示例5: submit

    def submit(self):
        for admin in settings_file.users['administrators']:
            self.target_jid = settings_file.users['administrators'][admin]
            if sys.version_info.major < 3:
                self.your_jid = self.your_jid.decode("utf-8")
                self.your_password = self.your_password.decode("utf-8")
                self.target_jid = self.target_jid.decode("utf-8")
                self.message = self.message.decode("utf-8")

                handler = MyHandler(JID(self.target_jid), self.message)
                settings = XMPPSettings({
                    u"password": self.your_password,
                    u"starttls": True,
                    u"tls_verify_peer": False,
                })

                client = Client(JID(self.your_jid), [handler], settings)
                client.connect()
                client.run()
开发者ID:keagster,项目名称:ardupy-secsys,代码行数:19,代码来源:alert.py

示例6: start

 def start(self):
     """
     服务开始
     :return:
     """
     logger.warn("XMPPClient::start listen on %s:%s:%s" % (self.protocol, self.JID, self.password))
     self.xmpp_client = Client(self.JID, [self], self.settings)
     self.xmpp_client.connect()
     self.xmpp_client.run()
     self.is_auth = False
开发者ID:duruo850,项目名称:HomeInternet,代码行数:10,代码来源:xmpp.py

示例7: __init__

    def __init__(self, your_jid, your_pass, target_jid, messages):
        self.target_jid = target_jid
        self.messages = messages

        self.connected = False
        self.established = False

        settings = XMPPSettings({
            u"password": your_pass,
            u"starttls": True,
            u"tls_verify_peer": False,
        })
        self.client = Client(JID(your_jid), [self], settings)
        self.client.connect()
开发者ID:jhol,项目名称:churchbot,代码行数:14,代码来源:sms.py

示例8: SayChat

class SayChat(EventHandler, XMPPFeatureHandler):
  def __init__(self):
      self.droid = sl4a.Android()
      settings = XMPPSettings({"software_name": "Say Chat"})
      settings["jid"] = self.droid.dialogGetInput("Google Talk Username").result
      settings["password"] = self.droid.dialogGetInput("Google Talk Password").result
      settings["server"] = "talk.google.com"
      settings["starttls"] = True
      self.client = Client(
        JID(settings["jid"]),
        [self, VersionProvider(settings)],
        settings)
      
  def connect(self):
    self.client.connect()
    self.client.run()

  def disconnect(self):
    self.client.disconnect()
    self.client.run(timeout = 2)

  @message_stanza_handler()
  def handle_message(self, stanza):
    self.droid.ttsSpeak(
      "{!s} says {!s}".format(stanza.from_jid.as_unicode(),
      stanza.body))
    return ""
    
  @event_handler(DisconnectedEvent)
  def handle_disconnected(self, event):
    return QUIT
    
  @event_handler()
  def handle_all(self, event):
    """If it's not logged, it didn't happen."""
    logging.info("-- {}".format(event))

  def run(self):
    try:
      self.connect()
    except KeyboardInterrupt:
      self.disconnect()
开发者ID:kaymatrix,项目名称:devcon-scripts,代码行数:42,代码来源:say_chat.py

示例9: __init__

    def __init__(self):
        my_jid = JID(USER+'/Bot')
        self.my_jid = my_jid
        settings = XMPPSettings({
                            "software_name": "Clubot",
                            "software_version": __version__,
                            "software_os": "Linux",
                            "tls_verify_peer": False,
                            "starttls": True,
                            "ipv6":False,
                            })

        settings["password"] = PASSWORD
        version_provider = VersionProvider(settings)
        self.connected = False
        self.client = Client(my_jid, [self, version_provider], settings)
        self.logger = get_logger()
        self.trytimes = 0
        empty_status()
开发者ID:beiliubei,项目名称:clubot,代码行数:19,代码来源:clubot.py

示例10: __init__

  def __init__(self, jid, settings, botsettings=None):
    if 'software_name' not in settings:
      settings['software_name'] = self.__class__.__name__
    if 'software_version' not in settings:
      settings['software_version'] = __version__
    version_provider = VersionProvider(settings)

    handlers = []
    if ReceiptSender:
      self.receipt_sender = rs = ReceiptSender()
      handlers.append(rs)

    handlers.extend([self, version_provider])
    self.client = Client(jid, handlers, settings)

    self.presence = defaultdict(dict)
    self.subscribes = ExpiringDictionary(default_timeout=5)
    self.invited = {}
    self.avatar_hash = None
    self.settings = botsettings
开发者ID:lilydjwg,项目名称:xmpptalk,代码行数:20,代码来源:main.py

示例11: SmsRobotClient

class SmsRobotClient(EventHandler, XMPPFeatureHandler):
    def __init__(self, your_jid, your_pass, target_jid, messages):
        self.target_jid = target_jid
        self.messages = messages

        self.connected = False
        self.established = False

        settings = XMPPSettings({
            u"password": your_pass,
            u"starttls": True,
            u"tls_verify_peer": False,
        })
        self.client = Client(JID(your_jid), [self], settings)
        self.client.connect()

    def run(self):
        while self.messages:
            if self.connected and not self.established:
                print("Connecting...")
                self.client.stream.send(Message(to_jid = self.target_jid,
                    body = "?", stanza_type = 'chat'))
            self.client.run(timeout = 2)

    @event_handler(AuthorizedEvent)
    def handle_authorized(self, event):
        self.connected = True

    @message_stanza_handler()
    def handle_message(self, stanza):
        if not self.established:
            if '"help"' not in stanza.body:
                return
            self.established = True

        if not self.messages:
            self.client.disconnect()
            return None

        body = 'sms:%s:%s' % self.messages.pop()
        print(body)
        return Message(to_jid = self.target_jid,
            body = body, stanza_type = 'chat')

    @event_handler(DisconnectedEvent)
    def handle_disconnected(self, event):
        return QUIT
开发者ID:jhol,项目名称:churchbot,代码行数:47,代码来源:sms.py

示例12: send

    def send(self, req_id, stanzas):
        self.req_id = req_id
        self.stanzas = stanzas
        logging.debug(u"XmppClient start sending messages for request #%s", self.req_id)
        try:
            settings = XMPPSettings({
                            u"password": self.password,
                            u"starttls": self.use_tls,
                            u"tls_verify_peer": self.tls_verify_peer,
                            u"server" : self.host,
                            u"port": self.port,
                            u"default_stanza_timeout": self.timeout,
                        })

            self.client = Client(self.from_jid, [self], settings)
            self.client.connect()
            self.client.run( timeout = self.timeout )
        except Exception, e:
            logging.error("Error sending XMPP notification for request #%s: %s",
                      req_id,
                      e,
                      exc_info=1)
开发者ID:paperlessreceipts,项目名称:rb-xmpp-notification,代码行数:22,代码来源:xmpp.py

示例13: __init__

    def __init__(self, QQ, QQ_PWD, xmpp_account, xmpp_pwd, control_account,
                 debug=True, command=None):
        self.input_queue = InputQueue(self.send_control_msg)
        self.qq = QQClient(QQ, QQ_PWD, debug)
        self.qq.set_control_msg(self.send_control_msg, self)
        self.command = command or Command(self, self.qq)
        self.jid = JID(xmpp_account + '/Bridge')
        self.control_account = control_account

        settings = XMPPSettings(
            {"software_name": "Magpie",
             "software_version": ".".join(str(x) for x in __version__),
             "software_os": "Linux",
             "tls_verify_peer": False,
             "starttls": True,
             "ipv6": False,
             "password": xmpp_pwd,
             "poll_interval": 10})

        version_provider = VersionProvider(settings)
        mainloop = TornadoMainLoop(settings)
        self.client = Client(self.jid, [self, version_provider],
                             settings, mainloop)
开发者ID:FashtimeDotCom,项目名称:magpie,代码行数:23,代码来源:client.py

示例14: __init__

    def __init__(self):
        my_jid = JID(USER+'/Bot')
        self.my_jid = my_jid
        settings = XMPPSettings({
                            "software_name": "Clubot",
                            "software_version": __version__,
                            "software_os": "Linux",
                            "tls_verify_peer": False,
                            "starttls": True,
                            "ipv6":False,
                            "poll_interval": 10,
                            })

        settings["password"] = PASSWORD
        version_provider = VersionProvider(settings)
        self.connected = False
        mainloop = TornadoMainLoop(settings)
        self.client = Client(my_jid, [self, version_provider], settings, mainloop)
        #self.client = Client(my_jid, [self, version_provider], settings)
        self.logger = get_logger()
        self.trytimes = 0
        self.sended = []
        Logics.empty_status()
开发者ID:Jack1007,项目名称:clubot,代码行数:23,代码来源:clubot.py

示例15: QXBot

class QXBot(EventHandler, XMPPFeatureHandler):
    def __init__(self):
        my_jid = JID(USER+'/Bot')
        self.my_jid = my_jid
        settings = XMPPSettings({
                            "software_name": "qxbot",
                            "software_version": __version__,
                            "software_os": "Linux",
                            "tls_verify_peer": False,
                            "starttls": True,
                            "ipv6":False,
                            "poll_interval": 10,
                            })

        settings["password"] = PASSWORD
        version_provider = VersionProvider(settings)
        event_queue = settings["event_queue"]
        self.webqq = WebQQ(QQ, event_queue)
        self.connected = False
        #self.mainloop = TornadoMainLoop(settings)
        self.mainloop = EpollMainLoop(settings)
        self.client = Client(my_jid, [self, version_provider],
                             settings, self.mainloop)
        self.logger = get_logger()
        self.msg_dispatch = MessageDispatch(self, self.webqq, BRIDGES)
        self.xmpp_msg_queue = Queue.Queue()

    def run(self, timeout = None):
        self.client.connect()
        self.client.run(timeout)

    def disconnect(self):
        self.client.disconnect()
        while True:
            try:
                self.run(2)
            except:
                pass
            else:
                break

    @presence_stanza_handler("subscribe")
    def handle_presence_subscribe(self, stanza):
        self.logger.info(u"{0} join us".format(stanza.from_jid))
        return stanza.make_accept_response()

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

    @presence_stanza_handler("unsubscribe")
    def handle_presence_unsubscribe(self, stanza):
        self.logger.info(u"{0} canceled presence subscription"
                                                    .format(stanza.from_jid))
        return stanza.make_accept_response()

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

    @presence_stanza_handler(None)
    def handle_presence_available(self, stanza):
        self.logger.info(r"{0} has been online".format(stanza.from_jid))

    @presence_stanza_handler("unavailable")
    def handle_presence_unavailable(self, stanza):
        self.logger.info(r"{0} has been offline".format(stanza.from_jid))

    @message_stanza_handler()
    def handle_message(self, stanza):
        if self.webqq.connected:
            self.msg_dispatch.dispatch_xmpp(stanza)
        else:
            self.xmpp_msg_queue.put(stanza)

    @event_handler(DisconnectedEvent)
    def handle_disconnected(self, event):
        return QUIT

    @event_handler(ConnectedEvent)
    def handle_connected(self, event):
        pass

    @event_handler(RosterReceivedEvent)
    def handle_roster_received(self, event):
        """ 此处代表xmpp已经连接
        开始连接QQ, 先将检查是否需要验证码的handler加入到mainloop
        """
        checkhandler = CheckHandler(self.webqq)
        self.mainloop.add_handler(checkhandler)
        self.connected = True

    @event_handler(CheckedEvent)
    def handle_webqq_checked(self, event):
        """ 第一步已经完毕, 删除掉检查的handler, 将登录前handler加入mainloop"""
        bloginhandler = BeforeLoginHandler(self.webqq, password = QQ_PWD)
        self.mainloop.remove_handler(event.handler)
#.........这里部分代码省略.........
开发者ID:DanyPlay,项目名称:qxbot,代码行数:101,代码来源:qxbot.py


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