本文整理汇总了Python中pubnub.pubnub_tornado.PubNubTornado.start方法的典型用法代码示例。如果您正苦于以下问题:Python PubNubTornado.start方法的具体用法?Python PubNubTornado.start怎么用?Python PubNubTornado.start使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pubnub.pubnub_tornado.PubNubTornado
的用法示例。
在下文中一共展示了PubNubTornado.start方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: TestPubNubAsyncPublish
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import start [as 别名]
class TestPubNubAsyncPublish(AsyncTestCase):
def setUp(self):
AsyncTestCase.setUp(self)
self.env = None
def callback(self, tornado_res):
self.env = tornado_res.result()
self.pubnub.stop()
self.stop()
def assert_success(self, pub):
pub.future().add_done_callback(self.callback)
self.pubnub.start()
self.wait()
assert isinstance(self.env, TornadoEnvelope)
assert isinstance(self.env.result, PNPublishResult)
assert isinstance(self.env.status, PNStatus)
assert self.env.result.timetoken > 0
assert len(self.env.status.original_response) > 0
@tornado.testing.gen_test
def assert_success_yield(self, pub):
envelope = yield pub.future()
assert isinstance(envelope, TornadoEnvelope)
assert isinstance(envelope.result, PNPublishResult)
assert isinstance(envelope.status, PNStatus)
assert envelope.result.timetoken > 0
assert len(envelope.status.original_response) > 0
def assert_success_publish_get(self, msg):
self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg))
def assert_success_publish_post(self, msg):
self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg).use_post(True))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg).use_post(True))
def assert_success_publish_get_encrypted(self, msg):
self.pubnub = PubNubTornado(pnconf_enc, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg))
def assert_success_publish_post_encrypted(self, msg):
self.pubnub = PubNubTornado(pnconf_enc, custom_ioloop=self.io_loop)
self.assert_success(self.pubnub.publish().channel(ch).message(msg).use_post(True))
self.assert_success_yield(self.pubnub.publish().channel(ch).message(msg).use_post(True))
def assert_client_side_error(self, pub, expected_err_msg):
try:
yield pub.future()
self.pubnub.start()
self.wait()
except PubNubException as e:
assert expected_err_msg in str(e)
self.pubnub.stop()
self.stop()
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/mixed_via_get.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
def test_publish_mixed_via_get(self):
self.assert_success_publish_get("hi")
self.assert_success_publish_get(5)
self.assert_success_publish_get(True)
self.assert_success_publish_get(["hi", "hi2", "hi3"])
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/object_via_get.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['method', 'scheme', 'host', 'port', 'object_in_path', 'query'])
def test_publish_object_via_get(self):
self.assert_success_publish_get({"name": "Alex", "online": True})
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/mixed_via_post.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['method', 'scheme', 'host', 'port', 'path', 'query'])
def test_publish_mixed_via_post(self):
self.assert_success_publish_post("hi")
self.assert_success_publish_post(5)
self.assert_success_publish_post(True)
self.assert_success_publish_post(["hi", "hi2", "hi3"])
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/object_via_post.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'],
match_on=['host', 'method', 'path', 'query', 'object_in_body'])
def test_publish_object_via_post(self):
self.assert_success_publish_post({"name": "Alex", "online": True})
@pn_vcr.use_cassette(
'tests/integrational/fixtures/tornado/publish/mixed_via_get_encrypted.yaml',
filter_query_parameters=['uuid', 'seqn', 'pnsdk', 'l_pub'])
#.........这里部分代码省略.........
示例2: main
# 需要导入模块: from pubnub.pubnub_tornado import PubNubTornado [as 别名]
# 或者: from pubnub.pubnub_tornado.PubNubTornado import start [as 别名]
# pubnub receive
@gen.coroutine
def main(channels):
class BitflyerSubscriberCallback(SubscribeCallback):
def presence(self, pubnub, presence):
pass
def status(self, pubnub, status):
if status.category == PNStatusCategory.PNUnexpectedDisconnectCategory:
pass
elif status.category == PNStatusCategory.PNConnectedCategory:
pass
elif status.category == PNStatusCategory.PNReconnectedCategory:
pass
elif status.category == PNStatusCategory.PNDecryptionErrorCategory:
pass
def message(self, pubnub, message):
try:
received_message_task(message.channel, message.message)
except:
print('Could not do received_message_task.')
listener = BitflyerSubscriberCallback()
pubnub.add_listener(listener)
pubnub.subscribe().channels(channels).execute()
if __name__ == '__main__':
main(['lightning_executions_FX_BTC_JPY'])
pubnub.start()