当前位置: 首页>>代码示例>>Python>>正文


Python client.IQ类代码示例

本文整理汇总了Python中twisted.words.protocols.jabber.client.IQ的典型用法代码示例。如果您正苦于以下问题:Python IQ类的具体用法?Python IQ怎么用?Python IQ使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了IQ类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test

def test(q, bus, conn, stream):
    # This sidecar sends a stanza, and waits for a reply, before being
    # created.
    pattern = EventPattern('stream-iq', to='sidecar.example.com',
        query_ns='http://example.com/sidecar')
    call_async(q, conn.Sidecars1, 'EnsureSidecar', TEST_PLUGIN_IFACE + ".IQ")
    e = q.expect_many(pattern)[0]

    # The server said yes, so we should get a sidecar back!
    acknowledge_iq(stream, e.stanza)
    q.expect('dbus-return', method='EnsureSidecar')

    identities = ["test/app-list//Test"]
    features = ["com.example.test1", "com.example.test2"]
    ver = compute_caps_hash(identities, features, {})

    iq = IQ(stream, "get")
    query = iq.addElement((ns.DISCO_INFO, 'query'))
    query['node'] = ns.GABBLE_CAPS + '#' + ver
    stream.send(iq)
    e = q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info')

    returned_features = [feature['var']
        for feature in xpath.queryForNodes('/iq/query/feature', e.stanza)]
    assertEquals(features, returned_features)

    returned_identities = [identity['category'] + "/" + identity['type']+"//" + identity['name']
        for identity in xpath.queryForNodes('/iq/query/identity', e.stanza)]
    assertEquals(identities, returned_identities)

    new_ver = compute_caps_hash(returned_identities, returned_features, {})
    assertEquals(new_ver, ver)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:32,代码来源:sidecar-own-caps.py

示例2: on_presence

 def on_presence(self, presence):
     print('received presence: %s' % presence.toXml().encode('utf-8'))
     user, host, res = parse(presence['from'])
     jid = '@'.join((user, host))
     if presence.hasAttribute('type'):
         if presence['type'] == 'subscribe':
             if jid in self.users:
                 print('received subscription')
                 if self.users[jid] is False:
                     iq = IQ(self.xmlstream, 'set')
                     query = domish.Element(('jabber:iq:roster', 'query'))
                     item = domish.Element((None, 'item'))
                     item['jid'] = jid
                     item['name'] = jid
                     item.addElement('group', content='controllers')
                     query.addChild(item)
                     iq.addChild(query)
                     iq.addCallback(self.subscribed, jid)
                     self.xmlstream.send(iq)
                     pres = domish.Element((None, 'presence'))
                     pres['type'] = 'subscribed'
                     pres['to'] = jid
                     self.xmlstream.send(pres)
                     
             else:
                 presence = domish.Element((None, 'presence'))
                 presence['type'] = 'unsubscribed'
                 presence['to'] = presence['from']
                 self.xmlstream.send(presence)
开发者ID:bverdu,项目名称:onDemand,代码行数:29,代码来源:xmpp.py

示例3: sync_stream

def sync_stream(q, xmpp_connection):
    """Used to ensure that Salut has processed all stanzas sent to it on this
       xmpp_connection."""

    iq = IQ(None, "get")
    iq.addElement(('http://jabber.org/protocol/disco#info', 'query'))
    xmpp_connection.send(iq)
    q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info')
开发者ID:freedesktop-unofficial-mirror,项目名称:telepathy__telepathy-salut,代码行数:8,代码来源:saluttest.py

示例4: send_roster_push

def send_roster_push(stream, jid, groups):
    iq = IQ(stream, 'set')
    query = iq.addElement((ns.ROSTER, 'query'))
    item = query.addElement('item')
    item['jid'] = jid
    item['subscription'] = 'both'
    for group in groups:
        item.addElement('group', content=group)
    stream.send(iq)
开发者ID:mlundblad,项目名称:telepathy-gabble,代码行数:9,代码来源:groups.py

示例5: send_roster_iq

 def send_roster_iq(stream, jid, subscription):
     iq = IQ(stream, "set")
     iq['id'] = 'push'
     query = iq.addElement('query')
     query['xmlns'] = ns.ROSTER
     item = query.addElement('item')
     item['jid'] = jid
     item['subscription'] = subscription
     stream.send(iq)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:9,代码来源:test-roster-item-deletion.py

示例6: _send_socks5_reply

 def _send_socks5_reply(self, id, stream_used):
     result = IQ(self.stream, 'result')
     result['id'] = id
     result['from'] = self.target
     result['to'] = self.initiator
     query = result.addElement((ns.BYTESTREAMS, 'query'))
     streamhost_used = query.addElement((None, 'streamhost-used'))
     streamhost_used['jid'] = stream_used
     result.send()
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:9,代码来源:bytestream.py

示例7: send_not_found

 def send_not_found(self, id):
     iq = IQ(self.stream, 'error')
     iq['to'] = self.initiator
     iq['from'] = self.target
     iq['id'] = id
     error = iq.addElement(('', 'error'))
     error['type'] = 'cancel'
     error['code'] = '404'
     self.stream.send(iq)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:9,代码来源:bytestream.py

示例8: make_result_iq

def make_result_iq(iq):
    result = IQ(None, "result")
    result["id"] = iq["id"]
    query = iq.firstChildElement()

    if query:
        result.addElement((query.uri, query.name))

    return result
开发者ID:freedesktop-unofficial-mirror,项目名称:telepathy__telepathy-salut,代码行数:9,代码来源:saluttest.py

示例9: test

def test(q, bus, conn, stream):
    self_presence = q.expect('stream-presence')

    c = xpath.queryForNodes('/presence/c', self_presence.stanza)[0]

    jid = '[email protected]/omg'

    # Gabble shouldn't send any disco requests to our contact during this test.
    q.forbid_events([
        EventPattern('stream-iq', to=jid, iq_type='get',
            query_ns=ns.DISCO_INFO),
    ])

    # Check that Gabble doesn't disco other clients with the same caps hash.
    p = make_presence(jid,
        caps={'node': c['node'],
              'hash': c['hash'],
              'ver':  c['ver'],
             })
    stream.send(p)
    sync_stream(q, stream)

    # Check that Gabble doesn't disco its own ext='' bundles (well, its own
    # bundles as advertised by Gabbles that don't do hashed caps)
    p = make_presence(jid,
        caps={'node': c['node'],
              'ver':  c['ver'],
              # omitting hash='' so Gabble doesn't ignore ext=''
              'ext':  'voice-v1 video-v1',
            })
    stream.send(p)
    sync_stream(q, stream)

    # Advertise some different capabilities, to change our own caps hash.
    add = [(cs.CHANNEL_TYPE_STREAMED_MEDIA, 2L**32-1),
           (cs.CHANNEL_TYPE_STREAM_TUBE, 2L**32-1),
           (cs.CHANNEL_TYPE_STREAM_TUBE, 2L**32-1)]
    remove = []
    caps = conn.Capabilities.AdvertiseCapabilities(add, remove)

    self_presence = q.expect('stream-presence')
    c_ = xpath.queryForNodes('/presence/c', self_presence.stanza)[0]
    assertNotEquals(c['ver'], c_['ver'])

    # But then someone asks us for our old caps
    iq = IQ(stream, 'get')
    iq['from'] = jid
    query = iq.addElement((ns.DISCO_INFO, 'query'))
    query['node'] = c['node'] + '#' + c['ver']
    stream.send(iq)

    # Gabble should still know what they are, and reply. This is actually quite
    # important: there's a bug in iChat where if you return an error to a disco
    # query, it just asks again, and again, and again...
    reply = q.expect('stream-iq', to=jid)
    assertEquals('result', reply.iq_type)
开发者ID:jku,项目名称:telepathy-gabble,代码行数:56,代码来源:trust-thyself.py

示例10: _cb_bare_jid_disco_iq

 def _cb_bare_jid_disco_iq(self, iq):
     # Additionally, Prosody 0.6.1 doesn't like us discoing our own bare
     # JID, and responds with an error which doesn't have the 'from'
     # attribute. Wocky used to discard this, but now tolerates it.
     result = IQ(self, 'error')
     result['id'] = iq['id']
     error = result.addElement((None, 'error'))
     error['type'] = 'cancel'
     error.addElement((ns.STANZA, 'service-unavailable'))
     self.send(result)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:10,代码来源:pep-support.py

示例11: respondToInitialIq

 def respondToInitialIq(self, iq):
     result = IQ(self.xmlstream, "result")
     result["id"] = iq["id"]
     query = result.addElement('query')
     query["xmlns"] = "jabber:iq:auth"
     query.addElement('username', content='test')
     query.addElement('password')
     query.addElement('digest')
     query.addElement('resource')
     self.xmlstream.send(result)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:10,代码来源:gabbletest.py

示例12: sync_stream

def sync_stream(q, stream):
    """Used to ensure that Gabble has processed all stanzas sent to it."""

    iq = IQ(stream, "get")
    id = iq['id']
    iq.addElement(('http://jabber.org/protocol/disco#info', 'query'))
    stream.send(iq)
    q.expect('stream-iq', query_ns='http://jabber.org/protocol/disco#info',
        predicate=(lambda event:
            event.stanza['id'] == id and event.iq_type == 'result'))
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:10,代码来源:gabbletest.py

示例13: repeat_previous_vcard

def repeat_previous_vcard(stream, iq, previous):
    result = IQ(stream, 'result')
    result['id'] = iq['id']
    to = iq.getAttribute('to')

    if to is not None:
        result["from"] = to

    result.addRawXml(previous.firstChildElement().toXml())
    stream.send(result)
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:10,代码来源:set-contact-info.py

示例14: initialIq

 def initialIq(self, iq):
     result = IQ(self.xmlstream, "result")
     result["id"] = iq["id"]
     query = result.addElement('query')
     query["xmlns"] = "jabber:iq:auth"
     query.addElement('username', content='test')
     query.addElement('password')
     query.addElement('digest')
     query.addElement('resource')
     self.xmlstream.addOnetimeObserver('/iq/query/username', self.secondIq)
     self.xmlstream.send(result)
开发者ID:dfghj44444,项目名称:realxtend-naali-deps,代码行数:11,代码来源:gabbletest.py

示例15: make_result_iq

def make_result_iq(stream, iq, add_query_node=True):
    result = IQ(stream, "result")
    result["id"] = iq["id"]
    to = iq.getAttribute('to')
    if to is not None:
        result["from"] = to
    query = iq.firstChildElement()

    if query and add_query_node:
        result.addElement((query.uri, query.name))

    return result
开发者ID:Thaodan,项目名称:telepathy-gabble,代码行数:12,代码来源:gabbletest.py


注:本文中的twisted.words.protocols.jabber.client.IQ类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。