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


Python xmlstream.toResponse函数代码示例

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


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

示例1: _continue

            def _continue(userid):
                pkey = base64.b64decode(var_pkey.value.__str__().encode('utf-8'))
                signed_pkey = manager.link_public_key(pkey, userid)
                if signed_pkey:
                    iq = xmlstream.toResponse(stanza, 'result')
                    query = iq.addElement((xmlstream2.NS_IQ_REGISTER, 'query'))

                    form = query.addElement(('jabber:x:data', 'x'))
                    form['type'] = 'form'

                    hidden = form.addElement((None, 'field'))
                    hidden['type'] = 'hidden'
                    hidden['var'] = 'FORM_TYPE'
                    hidden.addElement((None, 'value'), content='http://kontalk.org/protocol/register#code')

                    signed = form.addElement((None, 'field'))
                    signed['type'] = 'text-single'
                    signed['label'] = 'Signed public key'
                    signed['var'] = 'publickey'
                    signed.addElement((None, 'value'), content=base64.b64encode(signed_pkey))

                    return manager.send(iq, True)

                else:
                    e = error.StanzaError('bad-request', 'modify', 'Invalid public key.')
                    iq = xmlstream.toResponse(stanza, 'error')
                    iq.addChild(e.getElement())
                    manager.send(iq, True)
开发者ID:bratischki,项目名称:xmppserver,代码行数:28,代码来源:register.py

示例2: _onGetShadowCopyIQ

 def _onGetShadowCopyIQ(self, iq):
     node = iq.shadowcopy['node']
     sender = iq['from']
     try:
         if node not in self.node_participants or \
             sender not in self.node_participants[node]:
             raise DSCException("Unauthorized")
         response = toResponse(iq, u'result')
         sc = response.addElement((NS_CE, u'shadowcopy'), content=self.shadow_copies[node])
         sc['node'] = node
     except DSCException, reason:
         response = toResponse(iq, u'error')
         response.addElement((NS_CE, u'error'), content=reason.message)
开发者ID:jean,项目名称:jarn.xmpp.collaboration,代码行数:13,代码来源:protocol.py

示例3: onMessage

    def onMessage(self, message):
        # Ignore empty messages
        if not message.body or not unicode(message.body):
            return
        if message["type"] != "chat":
            return

        jid = message["from"].split("/")[0]
        if jid not in self.parent.authorized:
            # User is not authorized! Is it telling us the password?
            if unicode(message.body).strip() == self.parent.getPassword():
                self.parent.authorized.append(jid)
                answer = "Welcome!"
                log.msg("Accepting JID %s with the right password" % jid)
                self.parent.presence.subscribed(JID(jid))
                self.parent.presence.subscribe(JID(jid))
            else:
                answer = "Tell me the password or I won't speak to you."
            response = toResponse(message, "chat")
            response.addElement("body", content=unicode(answer))
            self.send(response)
            return

        # Tell the user we are building an answer
        response = toResponse(message, "chat")
        response.addElement("composing", "http://jabber.org/protocol/chatstates")
        self.send(response)

        # Get an answer from the first one able to answer
        answers = None
        for bot in self.bots:
            try:
                answers = yield bot.ask(message["from"], unicode(message.body).encode("ascii", "ignore"))
            except Exception as e:
                log.msg("Catch exception for bot %r: %s\n%s" % (bot, e, traceback.format_exc()))
                continue
            if answers:
                break
        if not answers:
            answers = ["Seven amazing hamsters make your day!"]

        for answer in answers:
            response = toResponse(message, message["type"])
            if not isinstance(answer, MixedMessage):
                response.addElement("body", content=unicode(answer))
            else:
                response.addElement("body", content=unicode(answer.plain))
                response.addElement("html", "http://jabber.org/protocol/xhtml-im").addChild(answer.html)
            yield self.send(response)
开发者ID:pombredanne,项目名称:ipoo,代码行数:49,代码来源:message.py

示例4: test_modifyAffiliations

    def test_modifyAffiliations(self):
        d = self.protocol.modifyAffiliations(JID(u'pubsub.example.com'),
            u'foo_node', [(JID(u'[email protected]'), 'none')])
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.failIf(iq.pubsub is None)
        self.assertEqual(protocols.NS_PUBSUB_OWNER, iq.pubsub.uri)
        self.failIf(iq.pubsub.affiliations is None)
        self.assertEqual('foo_node',
                         iq.pubsub.affiliations['node'])
        affiliation = iq.pubsub.affiliations.affiliation
        self.assertEqual('[email protected]', affiliation['jid'])
        self.assertEqual('none', affiliation['affiliation'])

        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        self.stub.send(response)

        def cb(result):
            self.assertEqual(result, True)

        d.addCallback(cb)
        return d
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:25,代码来源:test_pubsub.py

示例5: cancel_page

 def cancel_page(self, iq, s):
     self.reset()
     response = xmlstream.toResponse(stanza=iq, stanzaType='result')
     cmd = getCommand(iq)
     cmd.status = 'canceled'
     response.addChild(cmd.toElement())
     return defer.succeed(response)
开发者ID:wyn,项目名称:collab,代码行数:7,代码来源:pageManager.py

示例6: test_removeItem

    def test_removeItem(self):
        """
        Removing a roster item is setting an item with subscription C{remove}.
        """
        d = self.protocol.removeItem(JID('[email protected]'))

        # Inspect outgoing iq request

        iq = self.stub.output[-1]
        self.assertEquals('set', iq.getAttribute('type'))
        self.assertNotIdentical(None, iq.query)
        self.assertEquals(NS_ROSTER, iq.query.uri)

        children = list(domish.generateElementsQNamed(iq.query.children,
                                                      'item', NS_ROSTER))
        self.assertEquals(1, len(children))
        child = children[0]
        self.assertEquals('[email protected]', child['jid'])
        self.assertEquals('remove', child['subscription'])

        # Fake successful response

        response = toResponse(iq, 'result')
        self.stub.send(response)
        return d
开发者ID:thepaul,项目名称:wokkel,代码行数:25,代码来源:test_xmppim.py

示例7: onVCardGet

    def onVCardGet(self, stanza):
        log.debug("%s requested vCard for %s" % (stanza['from'], stanza['to']))
        jid_from = jid.JID(stanza['from'])
        jid_to = jid.JID(stanza['to'])
        try:
            # are we requesting vCard for a user we have blocked?
            if self.parent.is_presence_allowed(jid_to, jid_from) == -1:
                log.debug("requesting vCard for a blocked user, bouncing error")
                e = error.StanzaError('not-acceptable', 'cancel')
                errstanza = e.toResponse(stanza)
                errstanza.error.addElement((xmlstream2.NS_IQ_BLOCKING_ERRORS, 'blocked'))
                self.send(errstanza)

            else:
                fpr = self.parent.is_presence_allowed(jid_from, jid_to)
                log.debug("is_presence_allowed: %d" % (fpr, ))
                if fpr != 1:
                    raise Exception()

                fpr = self.parent.keyring.get_fingerprint(jid_to.user)
                keydata = self.parent.keyring.get_key(jid_to.user, fpr)

                iq = xmlstream.toResponse(stanza, 'result')
                # add vcard
                vcard = iq.addElement((xmlstream2.NS_XMPP_VCARD4, 'vcard'))
                vcard_key = vcard.addElement((None, 'key'))
                vcard_data = vcard_key.addElement((None, 'uri'))
                vcard_data.addContent(xmlstream2.DATA_PGP_PREFIX + base64.b64encode(keydata))
                self.send(iq)

        except:
            self.parent.error(stanza)
开发者ID:carriercomm,项目名称:xmppserver,代码行数:32,代码来源:resolver.py

示例8: presence

    def presence(self, stanza):
        """Presence stanza received."""
        ptype = stanza.getAttribute('type')
        if ptype == 'subscribe':
            # sign received public key
            for child in stanza.pubkey.children:
                if child.name == 'print':
                    fpr = str(child)
                    break
            myfpr = str(self.config['publickey']['fingerprint'])

            ctx = gpgme.Context()
            ctx.signers = [ctx.get_key(myfpr, True)]
            gpgme.editutil.edit_sign(ctx, ctx.get_key(fpr), check=0)

            keydata = BytesIO()
            ctx.export(fpr, keydata)

            r = xmlstream.toResponse(stanza, 'subscribed')
            pubkey = r.addElement(('urn:xmpp:pubkey:2', 'pubkey'))
            key = pubkey.addElement((None, 'key'))
            key.addContent(base64.b64encode(keydata.getvalue()))
            fprint = pubkey.addElement((None, 'print'))
            fprint.addContent(fpr)
            self.client.send(r)
开发者ID:BillTheBest,项目名称:xmppserver,代码行数:25,代码来源:bot.py

示例9: test_noID

 def test_noID(self):
     """
     Test that a proper response is generated without id attribute.
     """
     stanza = domish.Element(('jabber:client', 'message'))
     response = xmlstream.toResponse(stanza)
     self.failIf(response.hasAttribute('id'))
开发者ID:axray,项目名称:dataware.dreamplug,代码行数:7,代码来源:test_jabberxmlstream.py

示例10: onVersion

    def onVersion(self, iq):
        response = toResponse(iq, "result")

        query = response.addElement((NS_VERSION, "query"))
        name = query.addElement("name", content=self.name)
        version = query.addElement("version", content=self.version)
        self.send(response)
开发者ID:GunioRobot,项目名称:wokkel,代码行数:7,代码来源:generic.py

示例11: test_getRoster

    def test_getRoster(self):
        """
        A request for the roster is sent out and the response is parsed.
        """
        def cb(roster):
            self.assertIn(JID('[email protected]'), roster)
            self.assertIdentical(None, getattr(roster, 'version'))

        d = self.service.getRoster()
        d.addCallback(cb)

        # Inspect outgoing iq request

        iq = self.stub.output[-1]
        self.assertEqual('get', iq.getAttribute('type'))
        self.assertNotIdentical(None, iq.query)
        self.assertEqual(NS_ROSTER, iq.query.uri)
        self.assertFalse(iq.query.hasAttribute('ver'))

        # Fake successful response
        response = toResponse(iq, 'result')
        query = response.addElement((NS_ROSTER, 'query'))
        item = query.addElement('item')
        item['jid'] = '[email protected]'

        d.callback(response)
        return d
开发者ID:Gandi,项目名称:wokkel,代码行数:27,代码来源:test_xmppim.py

示例12: test_getAffiliations

    def test_getAffiliations(self):
        d = self.protocol.getAffiliations(JID(u'pubsub.example.com'),
                                          u'foo_node')
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'get', iq.getAttribute(u'type'))
        self.failIf(iq.pubsub is None)
        self.assertEqual(protocols.NS_PUBSUB_OWNER, iq.pubsub.uri)
        self.failIf(iq.pubsub.affiliations is None)
        self.assertEqual('foo_node',
                         iq.pubsub.affiliations['node'])
        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        pubsub = response.addElement((protocols.NS_PUBSUB_OWNER, u'pubsub'))

        affiliations = pubsub.addElement(u'affiliations')
        affiliations['node'] = u'foo_node'
        user = affiliations.addElement(u'affiliation')
        user['jid'] = '[email protected]'
        user['affiliation'] = 'owner'
        foo = affiliations.addElement(u'affiliation')
        foo['jid'] = '[email protected]'
        foo['affiliation'] = 'publisher'
        self.stub.send(response)

        def cb(result):
            self.assertEqual(result,
            [(JID(u'[email protected]'), 'owner'),
             (JID(u'[email protected]'), 'publisher')])

        d.addCallback(cb)
        return d
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:33,代码来源:test_pubsub.py

示例13: test_associateNodeToCollection

    def test_associateNodeToCollection(self):
        d = self.protocol.associateNodeWithCollection(
            JID(u'pubsub.example.com'),
            u'foo_node',
            u'collection_node')
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.failIf(iq.pubsub is None)
        self.assertEqual(protocols.NS_PUBSUB_OWNER, iq.pubsub.uri)
        self.failIf(iq.pubsub.collection is None)
        self.assertEqual('collection_node',
                         iq.pubsub.collection['node'])
        self.failIf(iq.pubsub.collection.associate is None)
        self.assertEqual('foo_node',
                         iq.pubsub.collection.associate['node'])

        response = toResponse(iq, u'result')
        response['to'] = \
         self.protocol.xmlstream.factory.authenticator.jid.full()

        self.stub.send(response)

        def cb(result):
            self.assertEqual(True, result)

        d.addCallback(cb)
        return d
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:28,代码来源:test_pubsub.py

示例14: test_configureNode

    def test_configureNode(self):
        d = self.protocol.configureNode(JID(u'pubsub.example.com'),
                                        u'foo_node',
                                        {u'pubsub#collection': u'bar_node'})
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'set', iq.getAttribute(u'type'))
        self.failIf(iq.pubsub is None)
        self.assertEqual(protocols.NS_PUBSUB_OWNER, iq.pubsub.uri)
        self.failIf(iq.pubsub.configure is None)
        self.assertEqual(u'foo_node',
                         iq.pubsub.configure.getAttribute(u'node'))
        self.failIf(iq.pubsub.configure.x is None)
        x = iq.pubsub.configure.x
        self.assertEqual(data_form.NS_X_DATA, x.uri)
        self.assertEqual(u'submit', x.getAttribute('type'))
        self.assertEqual(2, len(x.children))
        fields = x.children
        self.failIf(fields[0].value is None)
        self.assertEqual([protocols.NS_PUBSUB_NODE_CONFIG],
                         fields[0].value.children)
        self.assertEqual(u'pubsub#collection', fields[1].getAttribute(u'var'))
        self.failIf(fields[1].value is None)
        self.assertEqual([u'bar_node'], fields[1].value.children)
        self.assertEqual(fields[0].value.children,
            [protocols.NS_PUBSUB_NODE_CONFIG])

        response = toResponse(iq, u'result')
        self.stub.send(response)

        def cb(result):
            self.assertEqual(True, result)

        d.addCallback(cb)
        return d
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:35,代码来源:test_pubsub.py

示例15: test_getNodes

    def test_getNodes(self):
        d = self.protocol.getNodes(JID(u'pubsub.example.com'),
                                   u'foo_node')
        iq = self.stub.output[-1]
        self.assertEqual(u'pubsub.example.com', iq.getAttribute(u'to'))
        self.assertEqual(u'get', iq.getAttribute(u'type'))
        self.failIf(iq.query is None)
        self.assertEqual(protocols.NS_DISCO_ITEMS, iq.query.uri)
        self.assertEqual(u'foo_node', iq.query.getAttribute(u'node'))
        response = toResponse(iq, u'result')
        response['to'] = \
            self.protocol.xmlstream.factory.authenticator.jid.full()
        query = response.addElement((protocols.NS_DISCO_ITEMS, u'query'))
        query[u'node'] = u'foo_node'
        child1 = query.addElement('item')
        child1['node'] = 'foodoo_child_1'
        child1['name'] = 'Foodoo child one'
        child1['jid'] = u'pubsub.example.com'
        child2 = query.addElement('item')
        child2['node'] = 'foodoo_child_2'
        child2['jid'] = u'pubsub.example.com'

        self.stub.send(response)

        def cb(result):
            self.assertEqual(
                [{'node': 'foodoo_child_1',
                  'jid': u'pubsub.example.com',
                  'name': 'Foodoo child one'},
                 {'node': 'foodoo_child_2',
                  'jid': u'pubsub.example.com'}],
                 result)

        d.addCallback(cb)
        return d
开发者ID:Anup888,项目名称:collective.xmpp.core,代码行数:35,代码来源:test_pubsub.py


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