本文整理汇总了Python中slixmpp.xmlstream.StanzaBase.send方法的典型用法代码示例。如果您正苦于以下问题:Python StanzaBase.send方法的具体用法?Python StanzaBase.send怎么用?Python StanzaBase.send使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类slixmpp.xmlstream.StanzaBase
的用法示例。
在下文中一共展示了StanzaBase.send方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: send
# 需要导入模块: from slixmpp.xmlstream import StanzaBase [as 别名]
# 或者: from slixmpp.xmlstream.StanzaBase import send [as 别名]
def send(self, callback=None, timeout=None, timeout_callback=None):
"""Send an <iq> stanza over the XML stream.
A callback handler can be provided that will be executed when the Iq
stanza's result reply is received.
Returns a future which result will be set to the result Iq if it is of type 'get' or 'set'
(when it is received), or a future with the result set to None if it has another type.
Overrides StanzaBase.send
:param function callback: Optional reference to a stream handler
function. Will be executed when a reply
stanza is received.
:param int timeout: The length of time (in seconds) to wait for a
response before the timeout_callback is called,
instead of the regular callback
:param function timeout_callback: Optional reference to a stream handler
function. Will be executed when the
timeout expires before a response has
been received for the originally-sent
IQ stanza.
:rtype: asyncio.Future
"""
if self.stream.session_bind_event.is_set():
matcher = MatchIDSender({"id": self["id"], "self": self.stream.boundjid, "peer": self["to"]})
else:
matcher = MatcherId(self["id"])
future = asyncio.Future()
def callback_success(result):
if result["type"] == "error":
future.set_exception(IqError(result))
else:
future.set_result(result)
if timeout is not None:
self.stream.cancel_schedule("IqTimeout_%s" % self["id"])
if callback is not None:
callback(result)
def callback_timeout():
future.set_exception(IqTimeout(self))
self.stream.remove_handler("IqCallback_%s" % self["id"])
if timeout_callback is not None:
timeout_callback(self)
if self["type"] in ("get", "set"):
handler_name = "IqCallback_%s" % self["id"]
if asyncio.iscoroutinefunction(callback):
constr = CoroutineCallback
else:
constr = Callback
if timeout is not None:
self.stream.schedule("IqTimeout_%s" % self["id"], timeout, callback_timeout, repeat=False)
handler = constr(handler_name, matcher, callback_success, once=True)
self.stream.register_handler(handler)
else:
future.set_result(None)
StanzaBase.send(self)
return future
示例2: send
# 需要导入模块: from slixmpp.xmlstream import StanzaBase [as 别名]
# 或者: from slixmpp.xmlstream.StanzaBase import send [as 别名]
def send(self, callback=None, timeout=None, timeout_callback=None):
"""Send an <iq> stanza over the XML stream.
A callback handler can be provided that will be executed when the Iq
stanza's result reply is received.
Returns a future which result will be set to the result Iq if it is of type 'get' or 'set'
(when it is received), or a future with the result set to None if it has another type.
Overrides StanzaBase.send
:param function callback: Optional reference to a stream handler
function. Will be executed when a reply
stanza is received.
:param int timeout: The length of time (in seconds) to wait for a
response before the timeout_callback is called,
instead of the regular callback
:param function timeout_callback: Optional reference to a stream handler
function. Will be executed when the
timeout expires before a response has
been received for the originally-sent
IQ stanza.
:rtype: asyncio.Future
"""
if self.stream.session_bind_event.is_set():
matcher = MatchIDSender({
'id': self['id'],
'self': self.stream.boundjid,
'peer': self['to']
})
else:
matcher = MatcherId(self['id'])
future = asyncio.Future()
# Prevents handlers from existing forever.
if timeout is None:
timeout = 120
def callback_success(result):
type_ = result['type']
if type_ == 'result':
future.set_result(result)
elif type_ == 'error':
future.set_exception(IqError(result))
else:
# Most likely an iq addressed to ourself, rearm the callback.
handler = constr(handler_name,
matcher,
callback_success,
once=True)
self.stream.register_handler(handler)
return
if timeout is not None:
self.stream.cancel_schedule('IqTimeout_%s' % self['id'])
if callback is not None:
callback(result)
def callback_timeout():
future.set_exception(IqTimeout(self))
self.stream.remove_handler('IqCallback_%s' % self['id'])
if timeout_callback is not None:
timeout_callback(self)
if self['type'] in ('get', 'set'):
handler_name = 'IqCallback_%s' % self['id']
if asyncio.iscoroutinefunction(callback):
constr = CoroutineCallback
else:
constr = Callback
if timeout is not None:
self.stream.schedule('IqTimeout_%s' % self['id'],
timeout,
callback_timeout,
repeat=False)
handler = constr(handler_name,
matcher,
callback_success,
once=True)
self.stream.register_handler(handler)
else:
future.set_result(None)
StanzaBase.send(self)
return future