From 765ee5db6fc39d77e55dcf4fe97fb96da2f46d30 Mon Sep 17 00:00:00 2001 From: Devendra Date: Wed, 2 Apr 2014 02:44:29 +0530 Subject: multiplexing support --- common/PubnubCore.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'common/PubnubCore.py') diff --git a/common/PubnubCore.py b/common/PubnubCore.py index dcfd319..3ed3a68 100644 --- a/common/PubnubCore.py +++ b/common/PubnubCore.py @@ -1,4 +1,4 @@ -class PubnubCore(PubnubBase): +class PubnubCore(PubnubCoreAsync): def __init__( self, publish_key, @@ -44,7 +44,7 @@ class PubnubCore(PubnubBase): - def subscribe( self, args ) : + def subscribe_sync( self, args ) : """ #** #* Subscribe -- cgit v1.2.3 From 99096b8c11b9a541f6350639e8735495cf90091c Mon Sep 17 00:00:00 2001 From: Devendra Date: Fri, 11 Apr 2014 14:49:43 +0530 Subject: v1 MX and async code for python, twisted, tornado --- common/PubnubCore.py | 2 ++ 1 file changed, 2 insertions(+) (limited to 'common/PubnubCore.py') diff --git a/common/PubnubCore.py b/common/PubnubCore.py index 3ed3a68..7fb67d6 100644 --- a/common/PubnubCore.py +++ b/common/PubnubCore.py @@ -5,6 +5,7 @@ class PubnubCore(PubnubCoreAsync): subscribe_key, secret_key = False, cipher_key = False, + auth_key = None, ssl_on = False, origin = 'pubsub.pubnub.com', uuid = None @@ -32,6 +33,7 @@ class PubnubCore(PubnubCoreAsync): subscribe_key=subscribe_key, secret_key=secret_key, cipher_key=cipher_key, + auth_key=auth_key, ssl_on=ssl_on, origin=origin, UUID=uuid -- 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 --- common/PubnubCore.py | 53 ++++++++++++++++++++++++++-------------------------- 1 file changed, 26 insertions(+), 27 deletions(-) (limited to 'common/PubnubCore.py') diff --git a/common/PubnubCore.py b/common/PubnubCore.py index 7fb67d6..1c00215 100644 --- a/common/PubnubCore.py +++ b/common/PubnubCore.py @@ -3,13 +3,13 @@ class PubnubCore(PubnubCoreAsync): self, publish_key, subscribe_key, - secret_key = False, - cipher_key = False, - auth_key = None, - ssl_on = False, - origin = 'pubsub.pubnub.com', - uuid = None - ) : + secret_key=False, + cipher_key=False, + auth_key=None, + ssl_on=False, + origin='pubsub.pubnub.com', + uuid=None + ): """ #** #* Pubnub @@ -21,7 +21,8 @@ class PubnubCore(PubnubCoreAsync): #* @param string secret_key optional key to sign messages. #* @param boolean ssl required for 2048 bit encrypted messages. #* @param string origin PUBNUB Server Origin. - #* @param string pres_uuid optional identifier for presence (auto-generated if not supplied) + #* @param string pres_uuid optional + #* identifier for presence (auto-generated if not supplied) #** ## Initiat Class @@ -37,16 +38,14 @@ class PubnubCore(PubnubCoreAsync): ssl_on=ssl_on, origin=origin, UUID=uuid - ) + ) self.subscriptions = {} - self.timetoken = 0 - self.version = '3.4' + self.timetoken = 0 + self.version = '3.4' self.accept_encoding = 'gzip' - - - def subscribe_sync( self, args ) : + def subscribe_sync(self, args): """ #** #* Subscribe @@ -65,50 +64,50 @@ class PubnubCore(PubnubCoreAsync): pubnub.subscribe({ 'channel' : 'hello_world', - 'callback' : receive + 'callback' : receive }) """ ## Fail if missing channel - if not 'channel' in args : + if not 'channel' in args: raise Exception('Missing Channel.') return False ## Fail if missing callback - if not 'callback' in args : + if not 'callback' in args: raise Exception('Missing Callback.') return False ## Capture User Input - channel = str(args['channel']) - callback = args['callback'] + channel = str(args['channel']) + callback = args['callback'] subscribe_key = args.get('subscribe_key') or self.subscribe_key ## Begin Subscribe - while True : + while True: timetoken = 'timetoken' in args and args['timetoken'] or 0 - try : + try: ## Wait for Message - response = self._request({"urlcomponents" : [ + response = self._request({"urlcomponents": [ 'subscribe', subscribe_key, channel, '0', str(timetoken) - ],"urlparams" : {"uuid" : self.uuid }}) + ], "urlparams": {"uuid": self.uuid}}) - messages = response[0] + messages = response[0] args['timetoken'] = response[1] ## If it was a timeout - if not len(messages) : + if not len(messages): continue ## Run user Callback and Reconnect if user permits. - for message in messages : - if not callback(self.decrypt(message)) : + for message in messages: + if not callback(self.decrypt(message)): return except Exception: -- 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 --- common/PubnubCore.py | 20 +++----------------- 1 file changed, 3 insertions(+), 17 deletions(-) (limited to 'common/PubnubCore.py') diff --git a/common/PubnubCore.py b/common/PubnubCore.py index 1c00215..8454797 100644 --- a/common/PubnubCore.py +++ b/common/PubnubCore.py @@ -45,7 +45,7 @@ class PubnubCore(PubnubCoreAsync): self.version = '3.4' self.accept_encoding = 'gzip' - def subscribe_sync(self, args): + def subscribe_sync(self, channel, callback, timetoken=0): """ #** #* Subscribe @@ -69,25 +69,11 @@ class PubnubCore(PubnubCoreAsync): """ - ## Fail if missing channel - if not 'channel' in args: - raise Exception('Missing Channel.') - return False - - ## Fail if missing callback - if not 'callback' in args: - raise Exception('Missing Callback.') - return False - - ## Capture User Input - channel = str(args['channel']) - callback = args['callback'] - subscribe_key = args.get('subscribe_key') or self.subscribe_key + subscribe_key = self.subscribe_key ## Begin Subscribe while True: - timetoken = 'timetoken' in args and args['timetoken'] or 0 try: ## Wait for Message response = self._request({"urlcomponents": [ @@ -99,7 +85,7 @@ class PubnubCore(PubnubCoreAsync): ], "urlparams": {"uuid": self.uuid}}) messages = response[0] - args['timetoken'] = response[1] + timetoken = response[1] ## If it was a timeout if not len(messages): -- 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 --- common/PubnubCore.py | 102 --------------------------------------------------- 1 file changed, 102 deletions(-) delete mode 100644 common/PubnubCore.py (limited to 'common/PubnubCore.py') diff --git a/common/PubnubCore.py b/common/PubnubCore.py deleted file mode 100644 index 8454797..0000000 --- a/common/PubnubCore.py +++ /dev/null @@ -1,102 +0,0 @@ -class PubnubCore(PubnubCoreAsync): - def __init__( - self, - publish_key, - subscribe_key, - secret_key=False, - cipher_key=False, - auth_key=None, - ssl_on=False, - origin='pubsub.pubnub.com', - uuid=None - ): - """ - #** - #* Pubnub - #* - #* Init the Pubnub Client API - #* - #* @param string publish_key required key to send messages. - #* @param string subscribe_key required key to receive messages. - #* @param string secret_key optional key to sign messages. - #* @param boolean ssl required for 2048 bit encrypted messages. - #* @param string origin PUBNUB Server Origin. - #* @param string pres_uuid optional - #* identifier for presence (auto-generated if not supplied) - #** - - ## Initiat Class - pubnub = Pubnub( 'PUBLISH-KEY', 'SUBSCRIBE-KEY', 'SECRET-KEY', False ) - - """ - super(PubnubCore, self).__init__( - publish_key=publish_key, - subscribe_key=subscribe_key, - secret_key=secret_key, - cipher_key=cipher_key, - auth_key=auth_key, - ssl_on=ssl_on, - origin=origin, - UUID=uuid - ) - - self.subscriptions = {} - self.timetoken = 0 - self.version = '3.4' - self.accept_encoding = 'gzip' - - def subscribe_sync(self, channel, callback, timetoken=0): - """ - #** - #* Subscribe - #* - #* This is BLOCKING. - #* Listen for a message on a channel. - #* - #* @param array args with channel and callback. - #* @return false on fail, array on success. - #** - - ## Subscribe Example - def receive(message) : - print(message) - return True - - pubnub.subscribe({ - 'channel' : 'hello_world', - 'callback' : receive - }) - - """ - - subscribe_key = self.subscribe_key - - ## Begin Subscribe - while True: - - try: - ## Wait for Message - response = self._request({"urlcomponents": [ - 'subscribe', - subscribe_key, - channel, - '0', - str(timetoken) - ], "urlparams": {"uuid": self.uuid}}) - - messages = response[0] - timetoken = response[1] - - ## If it was a timeout - if not len(messages): - continue - - ## Run user Callback and Reconnect if user permits. - for message in messages: - if not callback(self.decrypt(message)): - return - - except Exception: - time.sleep(1) - - return True -- cgit v1.2.3