本文整理汇总了Python中twisted.words.protocols.jabber.xmlstream.IQ.toXml方法的典型用法代码示例。如果您正苦于以下问题:Python IQ.toXml方法的具体用法?Python IQ.toXml怎么用?Python IQ.toXml使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.protocols.jabber.xmlstream.IQ
的用法示例。
在下文中一共展示了IQ.toXml方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: publish_mood
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import toXml [as 别名]
def publish_mood(self, mood_str, text):
iq = IQ(self.xmlstream, 'set')
iq['from'] = config.SCREEN_NAME
pubsub = iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
moodpub = pubsub.addElement('publish')
moodpub['node'] = 'http://jabber.org/protocol/mood'
item = moodpub.addElement('item')
mood = item.addElement(('http://jabber.org/protocol/mood', 'mood'))
mood.addElement(mood_str)
mood.addElement('text').addContent(text)
def _doLog(x):
log.msg("Delivered mood: %s (%s)" % (mood_str, text))
d = iq.send()
d.addErrback(log.err)
d.addCallback(_doLog)
log.msg("Delivering mood: %s" % iq.toXml())
self.send(iq)
示例2: publish_mood
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import toXml [as 别名]
def publish_mood(self, mood_str, text):
iq = IQ(self.xmlstream, 'set')
iq['from'] = self.jid
pubsub = iq.addElement(('http://jabber.org/protocol/pubsub', 'pubsub'))
moodpub = pubsub.addElement('publish')
moodpub['node'] = 'http://jabber.org/protocol/mood'
item = moodpub.addElement('item')
mood = item.addElement(('http://jabber.org/protocol/mood', 'mood'))
mood.addElement(mood_str)
mood.addElement('text').addContent(text)
def _doLog(x):
log.msg("Delivered mood: %s (%s)" % (mood_str, text))
def _hasError(x):
log.err(x)
log.msg("Error delivering mood, disabling for %s." % self.jid)
self.pubsub = False
log.msg("Delivering mood: %s" % iq.toXml())
d = iq.send()
d.addCallback(_doLog)
d.addErrback(_hasError)