當前位置: 首頁>>代碼示例>>Python>>正文


Python StreamBase.set_peer_authenticated方法代碼示例

本文整理匯總了Python中pyxmpp2.streambase.StreamBase.set_peer_authenticated方法的典型用法代碼示例。如果您正苦於以下問題:Python StreamBase.set_peer_authenticated方法的具體用法?Python StreamBase.set_peer_authenticated怎麽用?Python StreamBase.set_peer_authenticated使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在pyxmpp2.streambase.StreamBase的用法示例。


在下文中一共展示了StreamBase.set_peer_authenticated方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: TestBindingReceiver

# 需要導入模塊: from pyxmpp2.streambase import StreamBase [as 別名]
# 或者: from pyxmpp2.streambase.StreamBase import set_peer_authenticated [as 別名]
class TestBindingReceiver(ReceiverSelectTestCase):
    def test_bind_no_resource(self):
        handler = EventRecorder()
        handlers = [ResourceBindingHandler(), handler]
        processor = StanzaProcessor()
        self.start_transport(handlers)
        self.stream = StreamBase(u"jabber:client", processor, handlers)
        processor.uplink = self.stream
        self.stream.receive(self.transport, self.addr[0])
        self.stream.set_peer_authenticated(JID("[email protected]"))
        processor.setup_stanza_handlers(handlers, "post-auth")
        self.client.write(C2S_CLIENT_STREAM_HEAD)
        features = self.wait(
                expect = re.compile(br".*<stream:features>"
                        br"(.*<bind.*urn:ietf:params:xml:ns:xmpp-bind.*)"
                                                    br"</stream:features>"))
        self.assertIsNotNone(features)
        self.client.write(BIND_GENERATED_REQUEST)
        resource = self.wait(
                expect = re.compile(br".*<iq.*id=(?:\"42\"|'42').*>"
                            br"<bind.*<jid>[email protected]/(.*)</jid>.*</bind>"))
        self.assertTrue(resource)
        self.client.write(STREAM_TAIL)
        self.client.disconnect()
        self.wait()
        event_classes = [e.__class__ for e in handler.events_received]
        self.assertEqual(event_classes, [AuthenticatedEvent,
                    StreamConnectedEvent, AuthorizedEvent, DisconnectedEvent])
 
    def test_bind_resource(self):
        handler = EventRecorder()
        handlers = [ResourceBindingHandler(), handler]
        processor = StanzaProcessor()
        self.start_transport(handlers)
        self.stream = StreamBase(u"jabber:client", processor, handlers)
        processor.uplink = self.stream
        self.stream.receive(self.transport, self.addr[0])
        self.stream.set_peer_authenticated(JID("[email protected]"))
        processor.setup_stanza_handlers(handlers, "post-auth")
        self.client.write(C2S_CLIENT_STREAM_HEAD)
        features = self.wait(
                expect = re.compile(br".*<stream:features>"
                    br"(.*<bind.*urn:ietf:params:xml:ns:xmpp-bind.*)"
                                                    br"</stream:features>"))
        self.assertIsNotNone(features)
        self.client.write(BIND_PROVIDED_REQUEST)
        resource = self.wait(
                expect = re.compile(br".*<iq.*id=(?:\"42\"|'42').*>"
                            br"<bind.*<jid>[email protected]/(.*)</jid>.*</bind>"))
        self.assertEqual(resource, b"Provided")
        self.client.write(STREAM_TAIL)
        self.client.disconnect()
        self.wait()
        event_classes = [e.__class__ for e in handler.events_received]
        self.assertEqual(event_classes, [AuthenticatedEvent,
                    StreamConnectedEvent, AuthorizedEvent, DisconnectedEvent])
開發者ID:AdamPrzybyla,項目名稱:pyxmpp2,代碼行數:58,代碼來源:binding.py


注:本文中的pyxmpp2.streambase.StreamBase.set_peer_authenticated方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。