本文整理匯總了Python中pyxmpp2.streambase.StreamBase.is_connected方法的典型用法代碼示例。如果您正苦於以下問題:Python StreamBase.is_connected方法的具體用法?Python StreamBase.is_connected怎麽用?Python StreamBase.is_connected使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類pyxmpp2.streambase.StreamBase
的用法示例。
在下文中一共展示了StreamBase.is_connected方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: TestReceiverSelect
# 需要導入模塊: from pyxmpp2.streambase import StreamBase [as 別名]
# 或者: from pyxmpp2.streambase.StreamBase import is_connected [as 別名]
class TestReceiverSelect(ReceiverSelectTestCase):
def test_stream_connect_disconnect(self):
handler = JustStreamConnectEventHandler()
self.start_transport([handler])
self.stream = StreamBase("jabber:client", None, [])
self.stream.receive(self.transport, self.addr[0])
self.client.write(C2S_CLIENT_STREAM_HEAD)
self.wait_short(0.25)
self.wait_short(0.25)
self.client.write(STREAM_TAIL)
self.wait()
self.assertFalse(self.stream.is_connected())
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [StreamConnectedEvent,
DisconnectedEvent])
def test_parse_error(self):
handler = IgnoreEventHandler()
self.start_transport([handler])
self.stream = StreamBase("jabber:client", None, [])
self.stream.receive(self.transport, self.addr[0])
self.client.write(C2S_CLIENT_STREAM_HEAD)
self.wait_short(0.25)
self.wait_short(0.25)
self.client.write(b"</stream:test>")
logger.debug("waiting for exception...")
with self.assertRaises(StreamParseError):
self.wait()
logger.debug(" got it!")
self.assertFalse(self.stream.is_connected())
self.wait_short(0.1)
logger.debug("waiting for connection close...")
self.client.wait(1)
logger.debug(" done")
self.assertTrue(self.client.eof)
self.assertTrue(self.client.rdata.endswith(PARSE_ERROR_RESPONSE))
self.client.disconnect()
logger.debug("final wait...")
self.wait()
logger.debug(" done")
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [StreamConnectedEvent,
DisconnectedEvent])
示例2: TestBindingInitiator
# 需要導入模塊: from pyxmpp2.streambase import StreamBase [as 別名]
# 或者: from pyxmpp2.streambase.StreamBase import is_connected [as 別名]
class TestBindingInitiator(InitiatorSelectTestCase):
def test_bind_no_resource(self):
handler = AuthorizedEventHandler()
handlers = [ResourceBindingHandler(), handler]
processor = StanzaProcessor()
processor.setup_stanza_handlers(handlers, "post-auth")
self.stream = StreamBase(u"jabber:client", processor, handlers)
processor.uplink = self.stream
self.stream.me = JID("[email protected]")
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
self.server.write(C2S_SERVER_STREAM_HEAD)
self.wait_short(1)
self.server.write(BIND_FEATURES)
req_id = self.wait(1,
expect = re.compile(br".*<iq[^>]*id=[\"']([^\"']*)[\"']"))
self.assertIsNotNone(req_id)
req_id = req_id.decode("utf-8")
self.server.write(BIND_GENERATED_RESPONSE.format(req_id)
.encode("utf-8"))
self.wait()
self.assertFalse(self.stream.is_connected())
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [ConnectingEvent,
ConnectedEvent, StreamConnectedEvent, GotFeaturesEvent,
BindingResourceEvent, AuthorizedEvent, DisconnectedEvent])
def test_bind(self):
handler = AuthorizedEventHandler()
handlers = [ResourceBindingHandler(), handler]
processor = StanzaProcessor()
processor.setup_stanza_handlers(handlers, "post-auth")
self.stream = StreamBase(u"jabber:client", processor, handlers,
XMPPSettings({"resource": "Provided"}))
processor.uplink = self.stream
self.stream.me = JID("[email protected]")
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
self.server.write(C2S_SERVER_STREAM_HEAD)
self.wait_short(1)
self.server.write(BIND_FEATURES)
req_id = self.wait(1,
expect = re.compile(br".*<iq[^>]*id=[\"']([^\"']*)[\"'].*"
br"<resource>Provided</resource>"))
self.assertIsNotNone(req_id)
req_id = req_id.decode("utf-8")
self.server.write(BIND_PROVIDED_RESPONSE.format(req_id).encode("utf-8"))
self.wait()
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [ConnectingEvent,
ConnectedEvent, StreamConnectedEvent, GotFeaturesEvent,
BindingResourceEvent, AuthorizedEvent, DisconnectedEvent])
示例3: TestInitiatorSelect
# 需要導入模塊: from pyxmpp2.streambase import StreamBase [as 別名]
# 或者: from pyxmpp2.streambase.StreamBase import is_connected [as 別名]
class TestInitiatorSelect(InitiatorSelectTestCase):
def test_connect_close(self):
handler = JustConnectEventHandler()
self.stream = StreamBase("jabber:client", None, [])
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
self.wait()
self.assertFalse(self.stream.is_connected())
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [ConnectingEvent,
ConnectedEvent, DisconnectedEvent])
def test_stream_connect_disconnect(self):
handler = JustStreamConnectEventHandler()
self.stream = StreamBase("jabber:client", None, [])
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
self.wait_short(0.25)
self.wait_short(0.25)
self.assertTrue(self.stream.is_connected())
self.server.write(C2S_SERVER_STREAM_HEAD)
self.wait(expect = re.compile(b".*(</stream:stream>)"))
self.server.write(STREAM_TAIL)
self.server.disconnect()
self.wait()
self.assertFalse(self.stream.is_connected())
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [ConnectingEvent, ConnectedEvent,
StreamConnectedEvent, DisconnectedEvent])
def test_parse_error(self):
handler = IgnoreEventHandler()
self.stream = StreamBase("jabber:client", None, [])
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
self.server.write(C2S_SERVER_STREAM_HEAD)
self.wait_short()
self.server.write(b"</stream:test>")
with self.assertRaises(StreamParseError):
logger.debug("-- WAIT start")
self.wait()
logger.debug("-- WAIT end")
self.assertFalse(self.stream.is_connected())
self.wait_short()
self.server.wait(1)
self.assertTrue(self.server.eof)
self.assertTrue(self.server.rdata.endswith(PARSE_ERROR_RESPONSE))
self.server.disconnect()
self.wait()
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [ConnectingEvent, ConnectedEvent,
StreamConnectedEvent, DisconnectedEvent])
def test_stanza_send(self):
handler = IgnoreEventHandler()
route = RecordingRoute()
self.stream = StreamBase("jabber:client", route, [])
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
self.server.write(C2S_SERVER_STREAM_HEAD)
self.wait_short(0.25)
self.wait_short(0.25)
self.assertTrue(self.stream.is_connected())
self.stream.send(Message(to_jid = JID("[email protected]"),
body = "Test"))
xml = self.wait(expect = re.compile(b".*(<message.*</message>)"))
self.assertIsNotNone(xml)
if b"xmlns" not in xml:
xml = xml.replace(b"<message", b"<message xmlns='jabber:client'")
element = XML(xml)
stanza = Message(element)
self.assertEqual(stanza.body, "Test")
self.stream.disconnect()
self.server.write(STREAM_TAIL)
self.server.disconnect()
self.wait()
self.assertEqual(route.sent, [])
self.assertEqual(route.received, [])
event_classes = [e.__class__ for e in handler.events_received]
self.assertEqual(event_classes, [ConnectingEvent, ConnectedEvent,
StreamConnectedEvent, DisconnectedEvent])
def test_stanza_receive(self):
handler = IgnoreEventHandler()
route = RecordingRoute()
self.stream = StreamBase("jabber:client", route, [])
self.start_transport([handler])
self.stream.initiate(self.transport)
self.connect_transport()
logger.debug("-- waiting for connect")
self.wait_short(0.25)
self.wait_short(0.25)
logger.debug("-- checking connected")
self.assertTrue(self.stream.is_connected())
self.server.write(C2S_SERVER_STREAM_HEAD)
self.server.write(b"<message><body>Test</body></message>")
#.........這裏部分代碼省略.........