本文整理汇总了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()
示例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)
示例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 = ""
示例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 = {}
示例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()
示例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
示例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()
示例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()
示例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()
示例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
示例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
示例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)
示例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)
示例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()
示例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)
#.........这里部分代码省略.........