本文整理汇总了Python中twisted.words.protocols.jabber.xmlstream.IQ.send方法的典型用法代码示例。如果您正苦于以下问题:Python IQ.send方法的具体用法?Python IQ.send怎么用?Python IQ.send使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类twisted.words.protocols.jabber.xmlstream.IQ
的用法示例。
在下文中一共展示了IQ.send方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: resultReceived
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def resultReceived(result):
items = [item.attributes for item in result.query.children]
if items[0].has_key('node'):
for item in reversed(items):
iq = IQ(client.admin.xmlstream, 'get')
iq['to'] = getXMPPDomain(site)
query = iq.addElement((NS_DISCO_ITEMS, 'query'))
query['node'] = item['node']
iq.send().addCallbacks(resultReceived)
else:
subscribe_jids = [item['jid'] for item in items]
if settings.admin_jid in subscribe_jids:
subscribe_jids.remove(settings.admin_jid)
if subscribe_jids:
getJID = lambda uid: JID(
"%[email protected]%s" % (escapeNode(uid), settings.xmpp_domain))
roster_jids = [getJID(user_id.split('@')[0])
for user_id in subscribe_jids]
for member_jid in member_jids:
client.chat.sendRosterItemAddSuggestion(member_jid,
roster_jids,
site)
log.info('Roster suggestion sent for %s' % member_jid)
# XXX: Somehow the last user's roster suggestions is
# dropped, unless we rest here for a bit.
time.sleep(3)
return result
示例2: resultReceived
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def resultReceived(result):
items = [item.attributes for item in result.query.children]
if 'node' in items[0]:
for item in reversed(items):
iq = IQ(client.admin.xmlstream, 'get')
iq['to'] = settings.xmpp_domain
query = iq.addElement((NS_DISCO_ITEMS, 'query'))
query['node'] = item['node']
iq.send().addCallbacks(resultReceived)
else:
member_jids = [item['jid'] for item in items]
if settings.admin_jid in member_jids:
member_jids.remove(settings.admin_jid)
registered_member_dicts = \
[d for d in member_dicts if d['jabberid'] in member_jids]
@newzodbconnection(portal=portal)
def updateVCard():
mdict = registered_member_dicts.pop()
setup.setVCard(
mdict,
mdict['jid_obj'],
mdict['pass'],
updateVCard)
if len(registered_member_dicts):
zr = getUtility(IZopeReactor)
zr.reactor.callInThread(updateVCard)
return
示例3: handlePresence
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def handlePresence(self, iq):
self.log_debug("Presence IQ: %s" %
(iq.toXml().encode('ascii', 'replace')),)
presenceType = iq.getAttribute('type')
if presenceType == 'subscribe':
frm = JID(iq['from']).userhost()
if self.allowedInRoster(frm):
self.roster[frm] = { 'debug' : False, 'available' : True }
response = domish.Element(('jabber:client', 'presence'))
response['to'] = iq['from']
response['type'] = 'subscribed'
self.xmlStream.send(response)
# request subscription as well
subscribe = domish.Element(('jabber:client', 'presence'))
subscribe['to'] = iq['from']
subscribe['type'] = 'subscribe'
self.xmlStream.send(subscribe)
else:
self.log_info("JID not allowed in roster: %s" % (frm,))
# Reject
response = domish.Element(('jabber:client', 'presence'))
response['to'] = iq['from']
response['type'] = 'unsubscribed'
self.xmlStream.send(response)
elif presenceType == 'unsubscribe':
frm = JID(iq['from']).userhost()
if self.roster.has_key(frm):
del self.roster[frm]
response = domish.Element(('jabber:client', 'presence'))
response['to'] = iq['from']
response['type'] = 'unsubscribed'
self.xmlStream.send(response)
# remove from roster as well
# XXX This codepath is not unit tested
removal = IQ(self.xmlStream, 'set')
query = removal.addElement("query", "jabber:iq:roster")
query.addElement("item")
query.item["jid"] = iq["from"]
query.item["subscription"] = "remove"
removal.send()
elif presenceType == 'unavailable':
frm = JID(iq['from']).userhost()
if self.roster.has_key(frm):
self.roster[frm]['available'] = False
else:
frm = JID(iq['from']).userhost()
if self.allowedInRoster(frm):
if self.roster.has_key(frm):
self.roster[frm]['available'] = True
else:
self.roster[frm] = { 'debug' : False, 'available' : True }
else:
self.log_info("JID not allowed in roster: %s" % (frm,))
示例4: modifyAffiliations
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def modifyAffiliations(self, service, nodeIdentifier, delta):
def cb(result):
if result['type']==u'result':
logger.info("Modified affiliations for %s: %s ." % \
(nodeIdentifier, delta))
return True
return False
def error(failure):
# TODO: Handle gracefully?
logger.error(failure.getTraceback())
return False
iq = IQ(self.xmlstream, 'set')
iq['to'] = service.full()
pubsub = iq.addElement((NS_PUBSUB_OWNER, 'pubsub'))
affiliations = pubsub.addElement('affiliations')
affiliations['node']=nodeIdentifier
for jid, affiliation in delta:
el = affiliations.addElement('affiliation')
el['jid'] = jid.userhost()
el['affiliation'] = affiliation
d = iq.send()
d.addCallbacks(cb, error)
return d
示例5: getAffiliations
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def getAffiliations(self, service, nodeIdentifier):
def cb(result):
affiliations = result.pubsub.affiliations
result = []
for affiliate in affiliations.children:
result.append((JID(affiliate['jid']),
affiliate['affiliation'], ))
logger.info("Got affiliations for %s: %s ." % \
(nodeIdentifier, result))
return result
def error(failure):
# TODO: Handle gracefully?
logger.error(failure.getTraceback())
return []
iq = IQ(self.xmlstream, 'get')
iq['to'] = service.full()
pubsub = iq.addElement((NS_PUBSUB_OWNER, 'pubsub'))
affiliations = pubsub.addElement('affiliations')
affiliations['node']=nodeIdentifier
d = iq.send()
d.addCallbacks(cb, error)
return d
示例6: ping
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def ping(self, entity, sender=None):
"""
Send out a ping request and wait for a response.
@param entity: Entity to be pinged.
@type entity: L{JID<twisted.words.protocols.jabber.jid.JID>}
@return: A deferred that fires upon receiving a response.
@rtype: L{Deferred<twisted.internet.defer.Deferred>}
@param sender: Optional sender address.
@type sender: L{JID<twisted.words.protocols.jabber.jid.JID>}
"""
def cb(response):
return None
def eb(failure):
failure.trap(StanzaError)
exc = failure.value
if exc.condition == 'service-unavailable':
return None
else:
return failure
request = IQ(self.xmlstream, 'get')
request.addElement((NS_PING, 'ping'))
if sender is not None:
request['from'] = sender.full()
d = request.send(entity.full())
d.addCallbacks(cb, eb)
return d
示例7: requestRoster
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def requestRoster(self):
if self.doRoster:
self.roster = {}
rosterIq = IQ(self.xmlStream, 'get')
rosterIq.addElement("query", "jabber:iq:roster")
d = rosterIq.send()
d.addCallback(self.handleRoster)
示例8: _acceptInvitation
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def _acceptInvitation(self, jid, url, conf):
'''
Sends IQ message with <session><accept /></session> and opens window with given app
@param jid: JID of user on the other side
@param url: URL of app ww are invited in
@param conf: configuration object
'''
iq = IQ(self.main.client.xmlstream, 'set')
iq['xml:lang'] = self.main.client.xmlLang
iq['type'] = 'set'
iq['to'] = jid + '/jabbim'
q = iq.addElement('query')
q['xmlns']='http://xawa.vaisar.cz'
s = q.addElement('session')
s.addElement('accept')
s['appUrl'] = url
self.main.client.disp(iq['id'])
d = iq.send()
##open window with app
self.openWindow()
self.loadApp(url)
self.loadConfiguration(conf)
return d
示例9: sendInvite
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def sendInvite(self,jid,appInfo):
'''
Sends IQ message with invitation
@param jid: JID of the user on the other side
@param appInfo: basic info about app
'''
iq = IQ(self.main.client.xmlstream, 'set')
iq['xml:lang'] = self.main.client.xmlLang
iq['type'] = 'set'
iq['to'] = jid + '/jabbim'
q = iq.addElement('query')
q['xmlns']='http://xawa.vaisar.cz'
s = q.addElement('session')
if (appInfo != None):
s['appName'] = appInfo['appName']
s['appUrl'] = appInfo['appUrl']
s.addElement('invite')
conf = s.addElement('configuration')
conf.addChild(json.dumps(appInfo)) # puts whole string inside the tag
self.main.client.disp(iq['id'])
d = iq.send()
return d
示例10: getNodeConfiguration
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def getNodeConfiguration(self, service, nodeIdentifier):
def cb(result):
fields = [field
for field in result.pubsub.configure.x.children
if field[u'type']!=u'hidden']
result = dict()
for field in fields:
value = None
try:
value = field.value.children[0]
except (AttributeError, IndexError):
pass
result[field['var']] = value
logger.info("Got node config %s: %s ." % (nodeIdentifier, result))
return result
def error(failure):
# TODO: Handle gracefully?
logger.error(failure.getTraceback())
return []
iq = IQ(self.xmlstream, 'get')
iq['to'] = service.full()
pubsub = iq.addElement((NS_PUBSUB_OWNER, 'pubsub'))
configure = pubsub.addElement('configure')
configure['node'] = nodeIdentifier
d = iq.send()
d.addCallbacks(cb, error)
return d
示例11: publishNode
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def publishNode(self, nodeName, lock=True):
if self.xmlStream is None:
# We lost our connection
self.unlockNode(None, nodeName)
return
try:
if lock and not self.lockNode(nodeName):
return
iq = IQ(self.xmlStream)
pubsubElement = iq.addElement('pubsub', defaultUri=self.pubsubNS)
publishElement = pubsubElement.addElement('publish')
publishElement['node'] = nodeName
if self.settings["NodeConfiguration"]["pubsub#deliver_payloads"] == '1':
itemElement = publishElement.addElement('item')
itemElement.addElement('plistfrag', defaultUri='plist-apple')
self.sendDebug("Publishing (%s)" % (nodeName,), iq)
d = iq.send(to=self.settings['ServiceAddress'])
d.addCallback(self.publishNodeSuccess, nodeName)
d.addErrback(self.publishNodeFailure, nodeName)
except:
self.unlockNode(None, nodeName)
raise
示例12: modifyAffiliations
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def modifyAffiliations(self, service, nodeIdentifier, delta):
def cb(result):
if result["type"] == u"result":
log.info("Modified affiliations for %s: %s ." % (nodeIdentifier, delta))
return True
return False
def error(failure):
# TODO: Handle gracefully?
log.error(failure.getTraceback())
return False
iq = IQ(self.xmlstream, "set")
iq["to"] = service.full()
pubsub = iq.addElement((NS_PUBSUB_OWNER, "pubsub"))
affiliations = pubsub.addElement("affiliations")
affiliations["node"] = nodeIdentifier
for jid, affiliation in delta:
el = affiliations.addElement("affiliation")
el["jid"] = jid.userhost()
el["affiliation"] = affiliation
d = iq.send()
d.addCallbacks(cb, error)
return d
示例13: getNodeConfiguration
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def getNodeConfiguration(self, service, nodeIdentifier):
def cb(result):
fields = [field for field in result.pubsub.configure.x.children if field[u"type"] != u"hidden"]
result = dict()
for field in fields:
value = None
try:
value = field.value.children[0]
except (AttributeError, IndexError):
pass
result[field["var"]] = value
log.info("Got node config %s: %s ." % (nodeIdentifier, result))
return result
def error(failure):
# TODO: Handle gracefully?
log.error(failure.getTraceback())
return []
iq = IQ(self.xmlstream, "get")
iq["to"] = service.full()
pubsub = iq.addElement((NS_PUBSUB_OWNER, "pubsub"))
configure = pubsub.addElement("configure")
configure["node"] = nodeIdentifier
d = iq.send()
d.addCallbacks(cb, error)
return d
示例14: retrieveSubscriptions
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def retrieveSubscriptions(self):
# This isn't supported by Apple's pubsub service
iq = IQ(self.xmlStream)
pubsubElement = iq.addElement("pubsub", defaultUri=self.pubsubNS)
pubsubElement.addElement("subscriptions")
print "Requesting list of subscriptions"
try:
yield iq.send(to=self.service)
except Exception, e:
print "Subscription list failure: %s" % (e,)
示例15: getRegisteredUsers
# 需要导入模块: from twisted.words.protocols.jabber.xmlstream import IQ [as 别名]
# 或者: from twisted.words.protocols.jabber.xmlstream.IQ import send [as 别名]
def getRegisteredUsers(self, portal=None):
""" XXX: This is ejabberd specific. ejabberd does not implement
the #get-registered-users-list command, instead does it with an iq/get.
"""
iq = IQ(self.xmlstream, "get")
iq["to"] = users.getXMPPDomain(portal)
query = iq.addElement((NS_DISCO_ITEMS, "query"))
query["node"] = "all users"
d = iq.send()
return d