本文整理汇总了Python中slixmpp.xmlstream.StanzaBase类的典型用法代码示例。如果您正苦于以下问题:Python StanzaBase类的具体用法?Python StanzaBase怎么用?Python StanzaBase使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了StanzaBase类的13个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __init__
def __init__(self, *args, **kwargs):
"""
Initialize a new <presence /> stanza with an optional 'id' value.
Overrides StanzaBase.__init__.
"""
StanzaBase.__init__(self, *args, **kwargs)
if self['id'] == '':
if self.stream is not None and self.stream.use_presence_ids:
self['id'] = self.stream.new_id()
开发者ID:mathieui,项目名称:slixmpp,代码行数:10,代码来源:presence.py
示例2: __init__
def __init__(self, *args, **kwargs):
"""
Initialize a new <message /> stanza with an optional 'id' value.
Overrides StanzaBase.__init__.
"""
StanzaBase.__init__(self, *args, **kwargs)
if self["id"] == "":
if self.stream is not None and self.stream.use_message_ids:
self["id"] = self.stream.new_id()
开发者ID:goutomroy,项目名称:slixmpp,代码行数:10,代码来源:message.py
示例3: set_payload
def set_payload(self, value):
"""
Set the XML contents of the <iq> stanza.
:param value: An XML object or a list of XML objects to use as the <iq>
stanza's contents
:type value: list or XML object
"""
self.clear()
StanzaBase.set_payload(self, value)
return self
开发者ID:poezio,项目名称:slixmpp,代码行数:11,代码来源:iq.py
示例4: __init__
def __init__(self, *args, **kwargs):
"""
Initialize a new <iq> stanza with an 'id' value.
Overrides StanzaBase.__init__.
"""
StanzaBase.__init__(self, *args, **kwargs)
if self["id"] == "":
if self.stream is not None:
self["id"] = self.stream.new_id()
else:
self["id"] = "0"
开发者ID:poezio,项目名称:slixmpp,代码行数:12,代码来源:iq.py
示例5: reply
def reply(self, body=None, clear=True):
"""
Create a message reply.
Overrides StanzaBase.reply.
Sets proper 'to' attribute if the message is from a MUC, and
adds a message body if one is given.
:param str body: Optional text content for the message.
:param bool clear: Indicates if existing content should be removed
before replying. Defaults to True.
:rtype: :class:`~.Message`
"""
new_message = StanzaBase.reply(self, clear)
if self['type'] == 'groupchat':
new_message['to'] = new_message['to'].bare
new_message['thread'] = self['thread']
new_message['parent_thread'] = self['parent_thread']
del new_message['id']
if body is not None:
new_message['body'] = body
return new_message
开发者ID:mathieui,项目名称:slixmpp,代码行数:28,代码来源:message.py
示例6: _set_stanza_values
def _set_stanza_values(self, values):
"""
Set multiple stanza interface values using a dictionary.
Stanza plugin values may be set usind nested dictionaries.
If the interface 'query' is given, then it will be set
last to avoid duplication of the <query /> element.
Overrides ElementBase._set_stanza_values.
Arguments:
values -- A dictionary mapping stanza interface with values.
Plugin interfaces may accept a nested dictionary that
will be used recursively.
"""
query = values.get("query", "")
if query:
del values["query"]
StanzaBase._set_stanza_values(self, values)
self["query"] = query
else:
StanzaBase._set_stanza_values(self, values)
return self
开发者ID:poezio,项目名称:slixmpp,代码行数:24,代码来源:iq.py
示例7: reply
def reply(self, clear=True):
"""
Create a new <iq> stanza replying to ``self``.
Overrides StanzaBase.reply
Sets the 'type' to 'result' in addition to the default
StanzaBase.reply behavior.
:param bool clear: Indicates if existing content should be
removed before replying. Defaults to True.
"""
new_iq = StanzaBase.reply(self, clear=clear)
new_iq["type"] = "result"
return new_iq
开发者ID:poezio,项目名称:slixmpp,代码行数:15,代码来源:iq.py
示例8: reply
def reply(self, clear=True):
"""
Create a new reply <presence/> stanza from ``self``.
Overrides StanzaBase.reply.
:param bool clear: Indicates if the stanza contents should be removed
before replying. Defaults to True.
"""
new_presence = StanzaBase.reply(self, clear)
if self['type'] == 'unsubscribe':
new_presence['type'] = 'unsubscribed'
elif self['type'] == 'subscribe':
new_presence['type'] = 'subscribed'
return new_presence
开发者ID:mathieui,项目名称:slixmpp,代码行数:15,代码来源:presence.py
示例9: setup
def setup(self, xml=None):
"""
Populate the stanza object using an optional XML object.
Overrides ElementBase.setup.
Sets a default error type and condition, and changes the
parent stanza's type to 'error'.
Arguments:
xml -- Use an existing XML object for the stanza's values.
"""
# StanzaBase overrides self.namespace
self.namespace = Failure.namespace
if StanzaBase.setup(self, xml):
#If we had to generate XML then set default values.
self['condition'] = 'not-authorized'
self.xml.tag = self.tag_name()
开发者ID:budlight,项目名称:slixmpp,代码行数:20,代码来源:failure.py
示例10: send
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
开发者ID:poezio,项目名称:slixmpp,代码行数:62,代码来源:iq.py
示例11: setup
def setup(self, xml):
StanzaBase.setup(self, xml)
self.xml.tag = self.tag_name()
开发者ID:mathieui,项目名称:slixmpp,代码行数:3,代码来源:stanza.py
示例12: setup
def setup(self, xml):
StanzaBase.setup(self, xml)
self.values = self.values
开发者ID:budlight,项目名称:slixmpp,代码行数:3,代码来源:stream_features.py
示例13: send
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
开发者ID:mathieui,项目名称:slixmpp,代码行数:85,代码来源:iq.py
注:本文中的slixmpp.xmlstream.StanzaBase类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论