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


Python PubNubTornado.start方法代碼示例

本文整理匯總了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'])
#.........這裏部分代碼省略.........
開發者ID:pubnub,項目名稱:python,代碼行數:103,代碼來源:test_publish.py

示例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()
開發者ID:hiromitsu-a,項目名稱:bitFlyerScalpingBot,代碼行數:31,代碼來源:bitFlyerScalpingBot.py


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