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


Python pubnub_tornado.PubNubTornado類代碼示例

本文整理匯總了Python中pubnub.pubnub_tornado.PubNubTornado的典型用法代碼示例。如果您正苦於以下問題:Python PubNubTornado類的具體用法?Python PubNubTornado怎麽用?Python PubNubTornado使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


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

示例1: test_publish_futurex

    def test_publish_futurex(self):
        pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
        envelope = yield pubnub.publish().message('hey').channel('blah').future()
        assert isinstance(envelope, TornadoEnvelope)
        assert not envelope.is_error()

        pubnub.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:7,代碼來源:test_invocations.py

示例2: test_super_call

    def test_super_call(self):
        ch1 = "state-tornado-ch1"
        ch2 = "state-tornado-ch2"
        pnconf = pnconf_pam_copy()
        pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
        pubnub.config.uuid = 'test-state-tornado-uuid-|.*$'
        state = {"name": "Alex", "count": 5}

        env = yield pubnub.set_state() \
            .channels([ch1, ch2]) \
            .state(state) \
            .future()

        assert env.result.state['name'] == "Alex"
        assert env.result.state['count'] == 5

        env = yield pubnub.get_state() \
            .channels([ch1, ch2]) \
            .future()

        assert env.result.channels[ch1]['name'] == "Alex"
        assert env.result.channels[ch2]['name'] == "Alex"
        assert env.result.channels[ch1]['count'] == 5
        assert env.result.channels[ch2]['count'] == 5

        pubnub.stop()
        self.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:27,代碼來源:test_state.py

示例3: test_publish_future_raises

    def test_publish_future_raises(self):
        pubnub = PubNubTornado(corrupted_keys, custom_ioloop=self.io_loop)
        e = yield pubnub.publish().message('hey').channel('blah').future()
        assert isinstance(e, PubNubTornadoException)
        assert e.is_error()
        assert 400 == e.value()._status_code

        pubnub.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:8,代碼來源:test_invocations.py

示例4: test_publish_result_raises_pubnub_error

    def test_publish_result_raises_pubnub_error(self):
        pubnub = PubNubTornado(corrupted_keys, custom_ioloop=self.io_loop)
        with pytest.raises(PubNubException) as exinfo:
            yield pubnub.publish().message('hey').channel('blah').result()

        assert 'Invalid Subscribe Key' in str(exinfo.value)
        assert 400 == exinfo.value._status_code

        pubnub.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:9,代碼來源:test_invocations.py

示例5: xtest_publish_future_raises_lower_level_error

    def xtest_publish_future_raises_lower_level_error(self):
        pubnub = PubNubTornado(corrupted_keys, custom_ioloop=self.io_loop)

        pubnub.http.close()

        e = yield pubnub.publish().message('hey').channel('blah').future()
        assert isinstance(e, PubNubTornadoException)
        assert str(e) == "fetch() called on closed AsyncHTTPClient"

        pubnub.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:10,代碼來源:test_invocations.py

示例6: setUp

    def setUp(self):
        super(TestChannelSubscription, self).setUp()

        messenger_config = pnconf_sub_copy()
        messenger_config.set_presence_timeout(8)
        messenger_config.uuid = "heartbeat-tornado-messenger"

        listener_config = pnconf_sub_copy()
        listener_config.uuid = "heartbeat-tornado-listener"

        self.pubnub = PubNubTornado(messenger_config, custom_ioloop=self.io_loop)
        self.pubnub_listener = PubNubTornado(listener_config, custom_ioloop=self.io_loop)
開發者ID:pubnub,項目名稱:python,代碼行數:12,代碼來源:test_heartbeat.py

示例7: xtest_publish_result_raises_lower_level_error

    def xtest_publish_result_raises_lower_level_error(self):
        pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)

        # TODO: find a better way ot emulate broken connection
        pubnub.http.close()

        with self.assertRaises(Exception) as context:
            yield pubnub.publish().message('hey').channel('blah').result()

        assert 'fetch() called on closed AsyncHTTPClient' in str(context.exception.message)

        pubnub.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:12,代碼來源:test_invocations.py

示例8: test_publish_ssl

    def test_publish_ssl(self):
        print(sys.version_info)
        pubnub = PubNubTornado(pnconf_ssl_copy(), custom_ioloop=self.io_loop)
        msg = "hey"
        pub = pubnub.publish().channel(ch).message(msg)

        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

        pubnub.stop()
開發者ID:pubnub,項目名稱:python,代碼行數:15,代碼來源:test_ssl.py

示例9: test_publish_do_not_store

    def test_publish_do_not_store(self):
        self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)

        self.assert_success(
            self.pubnub.publish().channel(ch).message("hey").should_store(False))
        self.assert_success_yield(
            self.pubnub.publish().channel(ch).message("hey").should_store(False))
開發者ID:pubnub,項目名稱:python,代碼行數:7,代碼來源:test_publish.py

示例10: test_error_non_serializable

    def test_error_non_serializable(self):
        self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)

        def method():
            pass

        self.assert_client_side_error(self.pubnub.publish().channel(ch).message(method), "not JSON serializable")
開發者ID:pubnub,項目名稱:python,代碼行數:7,代碼來源:test_publish.py

示例11: test_publish_with_meta

    def test_publish_with_meta(self):
        self.pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)

        self.assert_success(
            self.pubnub.publish().channel(ch).message("hey").meta({'a': 2, 'b': 'qwer'}))
        self.assert_success_yield(
            self.pubnub.publish().channel(ch).message("hey").meta({'a': 2, 'b': 'qwer'}))
開發者ID:pubnub,項目名稱:python,代碼行數:7,代碼來源:test_publish.py

示例12: TestChannelSubscription

class TestChannelSubscription(AsyncTestCase, SubscriptionTest):
    def setUp(self):
        super(TestChannelSubscription, self).setUp()
        self.pubnub = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)
        self.pubnub_listener = PubNubTornado(pnconf_sub_copy(), custom_ioloop=self.io_loop)

    @tornado.testing.gen_test
    async def test_subscribe_publish_unsubscribe(self):
        ch = helper.gen_channel("subscribe-test")
        message = "hey"

        callback_messages = SubscribeListener()
        self.pubnub.add_listener(callback_messages)
        self.pubnub.subscribe().channels(ch).execute()
        await callback_messages.wait_for_connect()

        sub_env, pub_env = await tornado.gen.multi([
            callback_messages.wait_for_message_on(ch),
            self.pubnub.publish().channel(ch).message(message).future()])

        assert pub_env.status.original_response[0] == 1
        assert pub_env.status.original_response[1] == 'Sent'

        assert sub_env.channel == ch
        assert sub_env.subscription is None
        assert sub_env.message == message

        self.pubnub.unsubscribe().channels(ch).execute()
        await callback_messages.wait_for_disconnect()
開發者ID:pubnub,項目名稱:python,代碼行數:29,代碼來源:test_tornado_async_await_syntax.py

示例13: test_error_not_permitted_403

    def test_error_not_permitted_403(self):
        my_pnconf = pnconf_pam_copy()
        my_pnconf.secret_key = None
        self.pubnub = PubNubTornado(my_pnconf, custom_ioloop=self.io_loop)

        self.assert_server_side_error(
            self.pubnub.publish().channel("not_permitted_channel").message("hey"), "HTTP Client Error (403)")
        self.assert_server_side_error_yield(
            self.pubnub.publish().channel("not_permitted_channel").message("hey"), "HTTP Client Error (403)")
開發者ID:pubnub,項目名稱:python,代碼行數:9,代碼來源:test_publish.py

示例14: test_error_invalid_key

    def test_error_invalid_key(self):
        conf = PNConfiguration()
        conf.publish_key = "fake"
        conf.subscribe_key = "demo"

        self.pubnub = PubNubTornado(conf, custom_ioloop=self.io_loop)

        self.assert_server_side_error(self.pubnub.publish().channel(ch).message("hey"), "Invalid Key")
        self.assert_server_side_error_yield(self.pubnub.publish().channel(ch).message("hey"), "Invalid Key")
開發者ID:pubnub,項目名稱:python,代碼行數:9,代碼來源:test_publish.py

示例15: test_reconnection

    def test_reconnection(self):
        pnconf = PNConfiguration()
        pnconf.publish_key = "demo"
        pnconf.subscribe_key = "demo"
        pnconf.origin = "localhost:8089"
        pnconf.subscribe_request_timeout = 10
        pnconf.reconnect_policy = PNReconnectionPolicy.LINEAR
        pubnub = PubNubTornado(pnconf, custom_ioloop=self.io_loop)
        time_until_open_again = 10

        @gen.coroutine
        def close_soon():
            yield gen.sleep(3)
            pubnub.http.close()
            pubnub.http = None
            print(">>> connection is broken")

        @gen.coroutine
        def open_again():
            yield gen.sleep(time_until_open_again)
            pubnub.http = tornado.httpclient.AsyncHTTPClient(max_clients=PubNubTornado.MAX_CLIENTS)
            print(">>> connection is open again")

        @gen.coroutine
        def countdown():
            yield gen.sleep(2)
            opened = False
            count = time_until_open_again

            while not opened:
                print(">>> %ds to open again" % count)
                count -= 1
                if count <= 0:
                    break
                yield gen.sleep(1)

        my_listener = MySubscribeCallback()
        pubnub.add_listener(my_listener)
        pubnub.subscribe().channels('my_channel').execute()

        yield gen.sleep(1000)
開發者ID:pubnub,項目名稱:python,代碼行數:41,代碼來源:test_reconnections.py


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