From 150ae1566d813acbb773839e919db2c0f467931c Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 16 Apr 2014 00:00:40 +0530 Subject: adding code to support async and pam client capabilities with python v2 and v3 --- python-tornado/examples/publish-example.py | 35 +++++++++++++++++------------- 1 file changed, 20 insertions(+), 15 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py index b9eaa15..bb8b199 100644 --- a/python-tornado/examples/publish-example.py +++ b/python-tornado/examples/publish-example.py @@ -10,54 +10,59 @@ ## ----------------------------------- import sys -import tornado +from twisted.internet import reactor sys.path.append('../') -sys.path.append('../..') -sys.path.append('../../common') +sys.path.append('../../') from Pubnub import Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or 'demo' ##(Cipher key is Optional) +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ##(Cipher key is Optional) ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- -pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key,cipher_key=cipher_key, ssl_on=ssl_on ) -#pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) +pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on ) crazy = 'hello_world' +## ----------------------------------------------------------------------- +## Publish Example +## ----------------------------------------------------------------------- def publish_complete(info): print(info) +def publish_error(info): + print('ERROR : ' + str(info)) + ## Publish string pubnub.publish({ 'channel' : crazy, 'message' : 'Hello World!', - 'callback' : publish_complete + 'callback' : publish_complete, + 'error' : publish_error }) ## Publish list li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] + pubnub.publish({ 'channel' : crazy, 'message' : li, - 'callback' : publish_complete + 'callback' : publish_complete, + 'error' : publish_error }) def done_cb(info): publish_complete(info) - tornado.ioloop.IOLoop.instance().stop() -## Publish Dictionary Object pubnub.publish({ 'channel' : crazy, 'message' : { 'some_key' : 'some_val' }, - 'callback' : done_cb + 'callback' : done_cb, + 'error' : publish_error }) -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -tornado.ioloop.IOLoop.instance().start() + + +pubnub.start() -- cgit v1.2.3 From 09cd0c015ae276aa849297a6a976065b2b3f247b Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 23 Apr 2014 14:03:13 +0530 Subject: modifying code for pep 8 compliance --- python-tornado/examples/here-now-example.py | 22 +++++++------ python-tornado/examples/history-example.py | 26 ++++++++------- python-tornado/examples/publish-example.py | 48 ++++++++++++++++------------ python-tornado/examples/subscribe-example.py | 27 +++++++++------- python-tornado/examples/uuid-example.py | 5 ++- 5 files changed, 71 insertions(+), 57 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/here-now-example.py b/python-tornado/examples/here-now-example.py index 85e3432..e6e45a3 100644 --- a/python-tornado/examples/here-now-example.py +++ b/python-tornado/examples/here-now-example.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -15,28 +15,30 @@ sys.path.append('..') sys.path.append('../../common') from Pubnub import Pubnub -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- -pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on ) -crazy = 'hello_world' +pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) +crazy = 'hello_world' ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- + + def here_now_complete(messages): print(messages) pubnub.stop() -pubnub.here_now( { - 'channel' : crazy, - 'callback' : here_now_complete +pubnub.here_now({ + 'channel': crazy, + 'callback': here_now_complete }) ## ----------------------------------------------------------------------- diff --git a/python-tornado/examples/history-example.py b/python-tornado/examples/history-example.py index c1619f4..00bdaf3 100644 --- a/python-tornado/examples/history-example.py +++ b/python-tornado/examples/history-example.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -13,30 +13,32 @@ import sys import tornado from Pubnub import Pubnub -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- -pubnub = Pubnub( publish_key, subscribe_key, secret_key,cipher_key, ssl_on ) -crazy = 'hello_world' +pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) +crazy = 'hello_world' ## ----------------------------------------------------------------------- ## History Example ## ----------------------------------------------------------------------- + + def history_complete(messages): print(messages) tornado.ioloop.IOLoop.instance().stop() -pubnub.history( { - 'channel' : crazy, - 'limit' : 10, - 'callback' : history_complete -}) +pubnub.history({ + 'channel': crazy, + 'limit': 10, + 'callback': history_complete + }) ## ----------------------------------------------------------------------- ## IO Event Loop diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py index bb8b199..38d713c 100644 --- a/python-tornado/examples/publish-example.py +++ b/python-tornado/examples/publish-example.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -15,53 +15,59 @@ sys.path.append('../') sys.path.append('../../') from Pubnub import Pubnub -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ##(Cipher key is Optional) -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len( + sys.argv) > 4 and sys.argv[4] or '' # (Cipher key is Optional) +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- -pubnub = Pubnub( publish_key, subscribe_key, secret_key, cipher_key, ssl_on ) -crazy = 'hello_world' +pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) +crazy = 'hello_world' ## ----------------------------------------------------------------------- ## Publish Example ## ----------------------------------------------------------------------- + + def publish_complete(info): print(info) + def publish_error(info): - print('ERROR : ' + str(info)) + print('ERROR : ' + str(info)) ## Publish string pubnub.publish({ - 'channel' : crazy, - 'message' : 'Hello World!', - 'callback' : publish_complete, - 'error' : publish_error + 'channel': crazy, + 'message': 'Hello World!', + 'callback': publish_complete, + 'error': publish_error }) ## Publish list -li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] +li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', + 'Saturday'] pubnub.publish({ - 'channel' : crazy, - 'message' : li, - 'callback' : publish_complete, - 'error' : publish_error + 'channel': crazy, + 'message': li, + 'callback': publish_complete, + 'error': publish_error }) + def done_cb(info): publish_complete(info) pubnub.publish({ - 'channel' : crazy, - 'message' : { 'some_key' : 'some_val' }, - 'callback' : done_cb, - 'error' : publish_error + 'channel': crazy, + 'message': {'some_key': 'some_val'}, + 'callback': done_cb, + 'error': publish_error }) diff --git a/python-tornado/examples/subscribe-example.py b/python-tornado/examples/subscribe-example.py index dfe8010..34ee886 100644 --- a/python-tornado/examples/subscribe-example.py +++ b/python-tornado/examples/subscribe-example.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -15,29 +15,33 @@ sys.path.append('../') sys.path.append('../..') from Pubnub import Pubnub -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or 'demo' ##(Cipher key is Optional) -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len( + sys.argv) > 4 and sys.argv[4] or 'demo' # (Cipher key is Optional) +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- -pubnub = Pubnub( publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key,cipher_key=cipher_key, ssl_on=ssl_on ) +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, + secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) #pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) -crazy = 'hello_world' +crazy = 'hello_world' + def connect_cb(): print 'Connect' + def subscribe_result(response): print response pubnub.subscribe({ - 'channel' : crazy, - 'callback' : subscribe_result, - 'connect' : connect_cb + 'channel': crazy, + 'callback': subscribe_result, + 'connect': connect_cb }) ## ----------------------------------------------------------------------- ## Publish Example @@ -54,7 +58,8 @@ pubnub.publish({ }) ## Publish list -li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday'] +li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', + 'Saturday'] pubnub.publish({ 'channel' : crazy, 'message' : li, diff --git a/python-tornado/examples/uuid-example.py b/python-tornado/examples/uuid-example.py index f24671b..33e19f8 100644 --- a/python-tornado/examples/uuid-example.py +++ b/python-tornado/examples/uuid-example.py @@ -1,4 +1,4 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. +## www.pubnub.com - PubNub Real-time push service in the cloud. # coding=utf8 ## PubNub Real-time Push APIs and Notifications Framework @@ -17,7 +17,7 @@ from Pubnub import Pubnub ## ----------------------------------------------------------------------- ## Initiate Pubnub State ## ----------------------------------------------------------------------- -pubnub = Pubnub( "", "", "", False ) +pubnub = Pubnub("", "", "", False) ## ----------------------------------------------------------------------- ## UUID Example @@ -25,4 +25,3 @@ pubnub = Pubnub( "", "", "", False ) uuid = pubnub.uuid() print "UUID: " print uuid - -- cgit v1.2.3 From f7b89bfafae34fa22509c1d1c59d1284ec62c5df Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 23 Apr 2014 21:35:06 +0530 Subject: exception handling changes --- python-tornado/examples/here-now-example.py | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/here-now-example.py b/python-tornado/examples/here-now-example.py index e6e45a3..6e69d53 100644 --- a/python-tornado/examples/here-now-example.py +++ b/python-tornado/examples/here-now-example.py @@ -10,7 +10,6 @@ ## ----------------------------------- import sys -import tornado sys.path.append('..') sys.path.append('../../common') from Pubnub import Pubnub @@ -34,12 +33,11 @@ crazy = 'hello_world' def here_now_complete(messages): print(messages) + print(type(messages)) pubnub.stop() -pubnub.here_now({ - 'channel': crazy, - 'callback': here_now_complete -}) +pubnub.here_now( + channel=crazy, callback=here_now_complete, error=here_now_complete) ## ----------------------------------------------------------------------- ## IO Event Loop -- cgit v1.2.3 From 493e29a108255eb3ae3166dc920f40e2f4e5c4c4 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 00:16:57 +0530 Subject: adding single file for all platforms --- python-tornado/examples/here-now-example.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/here-now-example.py b/python-tornado/examples/here-now-example.py index 6e69d53..c701daf 100644 --- a/python-tornado/examples/here-now-example.py +++ b/python-tornado/examples/here-now-example.py @@ -10,9 +10,7 @@ ## ----------------------------------- import sys -sys.path.append('..') -sys.path.append('../../common') -from Pubnub import Pubnub +from Pubnub import PubnubTornado as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -- cgit v1.2.3 From 93379625e26c98a8cfab72c106ae40819843f956 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 00:35:10 +0530 Subject: remove relative imports --- python-tornado/examples/publish-example.py | 2 -- python-tornado/examples/subscribe-example.py | 2 -- python-tornado/examples/uuid-example.py | 1 - 3 files changed, 5 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py index 38d713c..b02c41f 100644 --- a/python-tornado/examples/publish-example.py +++ b/python-tornado/examples/publish-example.py @@ -11,8 +11,6 @@ import sys from twisted.internet import reactor -sys.path.append('../') -sys.path.append('../../') from Pubnub import Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' diff --git a/python-tornado/examples/subscribe-example.py b/python-tornado/examples/subscribe-example.py index 34ee886..0724fa9 100644 --- a/python-tornado/examples/subscribe-example.py +++ b/python-tornado/examples/subscribe-example.py @@ -11,8 +11,6 @@ import sys import tornado -sys.path.append('../') -sys.path.append('../..') from Pubnub import Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' diff --git a/python-tornado/examples/uuid-example.py b/python-tornado/examples/uuid-example.py index 33e19f8..a1cabf6 100644 --- a/python-tornado/examples/uuid-example.py +++ b/python-tornado/examples/uuid-example.py @@ -11,7 +11,6 @@ import sys import tornado -sys.path.append('../') from Pubnub import Pubnub ## ----------------------------------------------------------------------- -- cgit v1.2.3 From c98286f500b77dcf426367df0b688f536b77ea9b Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 01:33:45 +0530 Subject: fixing imports --- python-tornado/examples/history-example.py | 30 +++++++--------------------- python-tornado/examples/publish-example.py | 6 ++---- python-tornado/examples/subscribe-example.py | 2 +- python-tornado/examples/uuid-example.py | 2 +- 4 files changed, 11 insertions(+), 29 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/history-example.py b/python-tornado/examples/history-example.py index 00bdaf3..879568b 100644 --- a/python-tornado/examples/history-example.py +++ b/python-tornado/examples/history-example.py @@ -10,8 +10,7 @@ ## ----------------------------------- import sys -import tornado -from Pubnub import Pubnub +from Pubnub import PubnubTornado as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' @@ -19,28 +18,13 @@ secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## History Example -## ----------------------------------------------------------------------- - +channel = 'hello_world' def history_complete(messages): print(messages) - tornado.ioloop.IOLoop.instance().stop() - -pubnub.history({ - 'channel': crazy, - 'limit': 10, - 'callback': history_complete - }) - -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -tornado.ioloop.IOLoop.instance().start() + pubnub.stop() + +pubnub.history(channel=channel, count=10, callback=history_complete) + +pubnub.start() diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py index b02c41f..5da6485 100644 --- a/python-tornado/examples/publish-example.py +++ b/python-tornado/examples/publish-example.py @@ -10,14 +10,12 @@ ## ----------------------------------- import sys -from twisted.internet import reactor -from Pubnub import Pubnub +from Pubnub import PubnubTwisted as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len( - sys.argv) > 4 and sys.argv[4] or '' # (Cipher key is Optional) +cipher_key = len( sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- diff --git a/python-tornado/examples/subscribe-example.py b/python-tornado/examples/subscribe-example.py index 0724fa9..26be1fd 100644 --- a/python-tornado/examples/subscribe-example.py +++ b/python-tornado/examples/subscribe-example.py @@ -11,7 +11,7 @@ import sys import tornado -from Pubnub import Pubnub +from Pubnub import PubnubTwisted as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' diff --git a/python-tornado/examples/uuid-example.py b/python-tornado/examples/uuid-example.py index a1cabf6..e5521ab 100644 --- a/python-tornado/examples/uuid-example.py +++ b/python-tornado/examples/uuid-example.py @@ -11,7 +11,7 @@ import sys import tornado -from Pubnub import Pubnub +from Pubnub import PubnubTwisted as Pubnub ## ----------------------------------------------------------------------- ## Initiate Pubnub State -- cgit v1.2.3 From 98242257846e9276dd83adbea950f83e25a4f2b6 Mon Sep 17 00:00:00 2001 From: Devendra Date: Thu, 24 Apr 2014 02:07:56 +0530 Subject: pep8 compliance, removing redundant files --- python-tornado/examples/history-example.py | 1 + python-tornado/examples/publish-example.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/history-example.py b/python-tornado/examples/history-example.py index 879568b..3a5fd88 100644 --- a/python-tornado/examples/history-example.py +++ b/python-tornado/examples/history-example.py @@ -21,6 +21,7 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) channel = 'hello_world' + def history_complete(messages): print(messages) pubnub.stop() diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py index 5da6485..456dbf9 100644 --- a/python-tornado/examples/publish-example.py +++ b/python-tornado/examples/publish-example.py @@ -15,7 +15,7 @@ from Pubnub import PubnubTwisted as Pubnub publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len( sys.argv) > 4 and sys.argv[4] or '' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- -- cgit v1.2.3 From cf1021b3671fb7537ad7b3a4d577ef0fcace694a Mon Sep 17 00:00:00 2001 From: Devendra Date: Tue, 6 May 2014 16:43:09 +0530 Subject: modifying examples --- python-tornado/examples/here-now-example.py | 43 ---------------- python-tornado/examples/here-now.py | 33 ++++++++++++ python-tornado/examples/history-example.py | 31 ----------- python-tornado/examples/history.py | 32 ++++++++++++ python-tornado/examples/publish-example.py | 70 ------------------------- python-tornado/examples/publish.py | 33 ++++++++++++ python-tornado/examples/subscribe-example.py | 77 ---------------------------- python-tornado/examples/subscribe.py | 48 +++++++++++++++++ python-tornado/examples/uuid-example.py | 26 ---------- 9 files changed, 146 insertions(+), 247 deletions(-) delete mode 100644 python-tornado/examples/here-now-example.py create mode 100644 python-tornado/examples/here-now.py delete mode 100644 python-tornado/examples/history-example.py create mode 100644 python-tornado/examples/history.py delete mode 100644 python-tornado/examples/publish-example.py create mode 100644 python-tornado/examples/publish.py delete mode 100644 python-tornado/examples/subscribe-example.py create mode 100644 python-tornado/examples/subscribe.py delete mode 100644 python-tornado/examples/uuid-example.py (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/here-now-example.py b/python-tornado/examples/here-now-example.py deleted file mode 100644 index c701daf..0000000 --- a/python-tornado/examples/here-now-example.py +++ /dev/null @@ -1,43 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -from Pubnub import PubnubTornado as Pubnub - -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' -subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## History Example -## ----------------------------------------------------------------------- - - -def here_now_complete(messages): - print(messages) - print(type(messages)) - pubnub.stop() - -pubnub.here_now( - channel=crazy, callback=here_now_complete, error=here_now_complete) - -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -pubnub.start() diff --git a/python-tornado/examples/here-now.py b/python-tornado/examples/here-now.py new file mode 100644 index 0000000..5c195f1 --- /dev/null +++ b/python-tornado/examples/here-now.py @@ -0,0 +1,33 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubTornado as Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False + +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, + secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) +channel = 'hello_world' + + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.here_now(channel, callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/history-example.py b/python-tornado/examples/history-example.py deleted file mode 100644 index 3a5fd88..0000000 --- a/python-tornado/examples/history-example.py +++ /dev/null @@ -1,31 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.0 Real-time Push Cloud API -## ----------------------------------- - -import sys -from Pubnub import PubnubTornado as Pubnub - -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' -subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) -channel = 'hello_world' - - -def history_complete(messages): - print(messages) - pubnub.stop() - -pubnub.history(channel=channel, count=10, callback=history_complete) - -pubnub.start() diff --git a/python-tornado/examples/history.py b/python-tornado/examples/history.py new file mode 100644 index 0000000..da3d6a5 --- /dev/null +++ b/python-tornado/examples/history.py @@ -0,0 +1,32 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubTornado as Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False + +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, + secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) +channel = 'a' + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.history(channel, count=2 , callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/publish-example.py b/python-tornado/examples/publish-example.py deleted file mode 100644 index 456dbf9..0000000 --- a/python-tornado/examples/publish-example.py +++ /dev/null @@ -1,70 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -from Pubnub import PubnubTwisted as Pubnub - -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' -subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub(publish_key, subscribe_key, secret_key, cipher_key, ssl_on) -crazy = 'hello_world' - -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- - - -def publish_complete(info): - print(info) - - -def publish_error(info): - print('ERROR : ' + str(info)) - -## Publish string -pubnub.publish({ - 'channel': crazy, - 'message': 'Hello World!', - 'callback': publish_complete, - 'error': publish_error -}) - -## Publish list -li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', - 'Saturday'] - -pubnub.publish({ - 'channel': crazy, - 'message': li, - 'callback': publish_complete, - 'error': publish_error -}) - - -def done_cb(info): - publish_complete(info) - -pubnub.publish({ - 'channel': crazy, - 'message': {'some_key': 'some_val'}, - 'callback': done_cb, - 'error': publish_error -}) - - -pubnub.start() diff --git a/python-tornado/examples/publish.py b/python-tornado/examples/publish.py new file mode 100644 index 0000000..4e662fd --- /dev/null +++ b/python-tornado/examples/publish.py @@ -0,0 +1,33 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubTornado as Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False + +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, + secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) +channel = 'hello_world' +message = 'Hello World !!!' + +# Asynchronous usage + +def callback(message): + print(message) + +pubnub.publish(channel, message, callback=callback, error=callback) + +pubnub.start() diff --git a/python-tornado/examples/subscribe-example.py b/python-tornado/examples/subscribe-example.py deleted file mode 100644 index 26be1fd..0000000 --- a/python-tornado/examples/subscribe-example.py +++ /dev/null @@ -1,77 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -import tornado -from Pubnub import PubnubTwisted as Pubnub - -publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' -subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' -secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' -cipher_key = len( - sys.argv) > 4 and sys.argv[4] or 'demo' # (Cipher key is Optional) -ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, - secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -#pubnub = Pubnub( publish_key, subscribe_key, secret_key, ssl_on ) -crazy = 'hello_world' - - -def connect_cb(): - print 'Connect' - - -def subscribe_result(response): - print response - -pubnub.subscribe({ - 'channel': crazy, - 'callback': subscribe_result, - 'connect': connect_cb -}) -## ----------------------------------------------------------------------- -## Publish Example -## ----------------------------------------------------------------------- -''' -def publish_complete(info): - print(info) - -## Publish string -pubnub.publish({ - 'channel' : crazy, - 'message' : 'Hello World!', - 'callback' : publish_complete -}) - -## Publish list -li = ['Sunday', 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', - 'Saturday'] -pubnub.publish({ - 'channel' : crazy, - 'message' : li, - 'callback' : publish_complete -}) - -## Publish Dictionary Object -pubnub.publish({ - 'channel' : crazy, - 'message' : { 'some_key' : 'some_val' }, - 'callback' : publish_complete -}) -''' -## ----------------------------------------------------------------------- -## IO Event Loop -## ----------------------------------------------------------------------- -tornado.ioloop.IOLoop.instance().start() diff --git a/python-tornado/examples/subscribe.py b/python-tornado/examples/subscribe.py new file mode 100644 index 0000000..9288836 --- /dev/null +++ b/python-tornado/examples/subscribe.py @@ -0,0 +1,48 @@ +## www.pubnub.com - PubNub Real-time push service in the cloud. +# coding=utf8 + +## PubNub Real-time Push APIs and Notifications Framework +## Copyright (c) 2010 Stephen Blum +## http://www.pubnub.com/ + + +import sys +from Pubnub import PubnubTornado as Pubnub + +publish_key = len(sys.argv) > 1 and sys.argv[1] or 'demo' +subscribe_key = len(sys.argv) > 2 and sys.argv[2] or 'demo' +secret_key = len(sys.argv) > 3 and sys.argv[3] or 'demo' +cipher_key = len(sys.argv) > 4 and sys.argv[4] or '' +ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False + +## ----------------------------------------------------------------------- +## Initiate Pubnub State +## ----------------------------------------------------------------------- +pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, + secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) + +channel = 'a' + + + +# Asynchronous usage + +def callback(message, channel): + print(message) + +def error(message): + print("ERROR : " + str(message)) + +def connect(message): + print("CONNECTED") + +def reconnect(message): + print("RECONNECTED") + +def disconnect(message): + print("DISCONNECTED") + + +pubnub.subscribe(channel, callback=callback, error=callback, connect=connect, reconnect=reconnect, disconnect=disconnect) + +pubnub.start() diff --git a/python-tornado/examples/uuid-example.py b/python-tornado/examples/uuid-example.py deleted file mode 100644 index e5521ab..0000000 --- a/python-tornado/examples/uuid-example.py +++ /dev/null @@ -1,26 +0,0 @@ -## www.pubnub.com - PubNub Real-time push service in the cloud. -# coding=utf8 - -## PubNub Real-time Push APIs and Notifications Framework -## Copyright (c) 2010 Stephen Blum -## http://www.pubnub.com/ - -## ----------------------------------- -## PubNub 3.1 Real-time Push Cloud API -## ----------------------------------- - -import sys -import tornado -from Pubnub import PubnubTwisted as Pubnub - -## ----------------------------------------------------------------------- -## Initiate Pubnub State -## ----------------------------------------------------------------------- -pubnub = Pubnub("", "", "", False) - -## ----------------------------------------------------------------------- -## UUID Example -## ----------------------------------------------------------------------- -uuid = pubnub.uuid() -print "UUID: " -print uuid -- cgit v1.2.3 From 1b49e712e12ba833f460324b95969b162d464edf Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 7 May 2014 12:13:17 +0530 Subject: console changes and pep8 compliance --- python-tornado/examples/history.py | 5 +++-- python-tornado/examples/publish.py | 5 +++-- python-tornado/examples/subscribe.py | 11 +++++++---- 3 files changed, 13 insertions(+), 8 deletions(-) (limited to 'python-tornado/examples') diff --git a/python-tornado/examples/history.py b/python-tornado/examples/history.py index da3d6a5..daf1c6e 100644 --- a/python-tornado/examples/history.py +++ b/python-tornado/examples/history.py @@ -20,13 +20,14 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -channel = 'a' +channel = 'a' # Asynchronous usage + def callback(message): print(message) -pubnub.history(channel, count=2 , callback=callback, error=callback) +pubnub.history(channel, count=2, callback=callback, error=callback) pubnub.start() diff --git a/python-tornado/examples/publish.py b/python-tornado/examples/publish.py index 4e662fd..04e88fd 100644 --- a/python-tornado/examples/publish.py +++ b/python-tornado/examples/publish.py @@ -20,11 +20,12 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False ## ----------------------------------------------------------------------- pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -channel = 'hello_world' -message = 'Hello World !!!' +channel = 'hello_world' +message = 'Hello World !!!' # Asynchronous usage + def callback(message): print(message) diff --git a/python-tornado/examples/subscribe.py b/python-tornado/examples/subscribe.py index 9288836..72f0fc1 100644 --- a/python-tornado/examples/subscribe.py +++ b/python-tornado/examples/subscribe.py @@ -21,28 +21,31 @@ ssl_on = len(sys.argv) > 5 and bool(sys.argv[5]) or False pubnub = Pubnub(publish_key=publish_key, subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, ssl_on=ssl_on) -channel = 'a' - +channel = 'a' # Asynchronous usage - def callback(message, channel): print(message) + def error(message): print("ERROR : " + str(message)) + def connect(message): print("CONNECTED") + def reconnect(message): print("RECONNECTED") + def disconnect(message): print("DISCONNECTED") -pubnub.subscribe(channel, callback=callback, error=callback, connect=connect, reconnect=reconnect, disconnect=disconnect) +pubnub.subscribe(channel, callback=callback, error=callback, + connect=connect, reconnect=reconnect, disconnect=disconnect) pubnub.start() -- cgit v1.2.3