diff options
| author | Devendra | 2014-04-23 12:54:16 +0530 |
|---|---|---|
| committer | Devendra | 2014-04-23 12:54:16 +0530 |
| commit | fdb46e56fa6794940f9fbe51a2863d58e927e655 (patch) | |
| tree | 99d71159c47858aaa17b31b77d4e5a153c2153cf /python/Pubnub.py | |
| parent | 69240816755406b26b364f37ca521fdb269581d1 (diff) | |
| download | pubnub-python-fdb46e56fa6794940f9fbe51a2863d58e927e655.tar.bz2 | |
switching to positional arguments
Diffstat (limited to 'python/Pubnub.py')
| -rw-r--r-- | python/Pubnub.py | 108 |
1 files changed, 17 insertions, 91 deletions
diff --git a/python/Pubnub.py b/python/Pubnub.py index d41f626..230915c 100644 --- a/python/Pubnub.py +++ b/python/Pubnub.py @@ -247,7 +247,9 @@ class PubnubBase(object): if not isinstance(self.uuid, str): raise AttributeError("pres_uuid must be a string") - def sign(self, channel, message): + ''' + + def _sign(self, channel, message): ## Sign Message if self.secret_key: signature = hashlib.md5('/'.join([ @@ -260,6 +262,7 @@ class PubnubBase(object): else: signature = '0' return signature + ''' def _pam_sign( self, msg ): """Calculate a signature by secret key and message.""" @@ -367,7 +370,7 @@ class PubnubBase(object): return None - def publish( self, args ) : + def publish(channel, message, callback=None, error=None): """ #** #* Publish @@ -388,28 +391,9 @@ class PubnubBase(object): print(info) """ - ## Fail if bad input. - if not (args['channel'] and args['message']) : - return [ 0, 'Missing Channel or Message' ] - - ## Capture User Input - channel = str(args['channel']) - - ## Capture Callback - if 'callback' in args : - callback = args['callback'] - else : - callback = None - - if 'error' in args : - error = args['error'] - else : - error = None message = self.encrypt(args['message']) - #signature = self.sign(channel, message) - ## Send Message return self._request({"urlcomponents": [ 'publish', @@ -422,7 +406,7 @@ class PubnubBase(object): ], 'urlparams' : {'auth' : self.auth_key}}, callback=self._return_wrapped_callback(callback), error=self._return_wrapped_callback(error)) - def presence( self, args ) : + def presence( self, channel, callback, error=None) : """ #** #* presence @@ -444,26 +428,10 @@ class PubnubBase(object): 'callback' : receive }) """ - - ## 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 - - return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':subscribe_key, 'callback': self._return_wrapped_callback(callback)}) + return self.subscribe({'channel': channel+'-pnpres', 'subscribe_key':self.subscribe_key, 'callback': self._return_wrapped_callback(callback)}) - def here_now( self, args ) : + def here_now( self, channel, callback, error=None) : """ #** #* Here Now @@ -501,7 +469,7 @@ class PubnubBase(object): ], 'urlparams' : {'auth' : self.auth_key}}, callback=self._return_wrapped_callback(callback), error=self._return_wrapped_callback(error)) - def history(self, args) : + def history(self, channel, count=100, reverse=False, start=None, end=None, callback=None, error=None) : """ #** #* History @@ -520,23 +488,13 @@ class PubnubBase(object): print(history) """ - ## Capture User Input - channel = str(args['channel']) - - callback = args['callback'] if 'callback' in args else None - error = args['error'] if 'error' in args else None params = dict() - params['count'] = str(args['count']) if 'count' in args else 100 - params['reverse'] = str(args['reverse']).lower() if 'reverse' in args else 'false' - params['start'] = str(args['start']) if 'start' in args else None - params['end'] = str(args['end']) if 'end' in args else None - - ## Fail if bad input. - if not channel : - raise Exception('Missing Channel') - return False + params['count'] = count + params['reverse'] = reverse + params['start'] = start + params['end'] = end ## Get History return self._request({ 'urlcomponents' : [ @@ -549,7 +507,7 @@ class PubnubBase(object): ], 'urlparams' : {'auth' : self.auth_key}}, callback=self._return_wrapped_callback(callback), error=self._return_wrapped_callback(error)) - def time(self, args = None) : + def time(self,callback=None) : """ #** #* Time @@ -564,9 +522,6 @@ class PubnubBase(object): print(timestamp) """ - ## Capture Callback - - callback = callback if args and 'callback' in args else None time = self._request({'urlcomponents' : [ 'time', @@ -698,7 +653,7 @@ class PubnubCoreAsync(PubnubBase): for i in l: func(i) - def subscribe( self, args=None, sync=False ) : + def subscribe( self, channel, callback, error=None, connect=None, disconnect=None, reconnect=None, sync=False ) : """ #** #* Subscribe @@ -730,27 +685,11 @@ class PubnubCoreAsync(PubnubBase): }) """ - if args is None: - _invoke(error, "Arguments Missing") - return - channel = args['channel'] if 'channel' in args else None - callback = args['callback'] if 'callback' in args else None - connect = args['connect'] if 'connect' in args else None - disconnect = args['disconnect'] if 'disconnect' in args else None - reconnect = args['reconnect'] if 'reconnect' in args else None - error = args['error'] if 'error' in args else None with self._tt_lock: self.last_timetoken = self.timetoken if self.timetoken != 0 else self.last_timetoken self.timetoken = 0 - if channel is None: - _invoke(error, "Channel Missing") - return - if callback is None: - _invoke(error, "Callback Missing") - return - if sync is True and self.susbcribe_sync is not None: self.susbcribe_sync(args) return @@ -781,16 +720,6 @@ class PubnubCoreAsync(PubnubBase): chobj = self.subscriptions[ch] _invoke(chobj['error'],err) - ''' - if callback is None: - _invoke(error, "Callback Missing") - return - - if channel is None: - _invoke(error, "Channel Missing") - return - ''' - def _get_channel(): for ch in self.subscriptions: chobj = self.subscriptions[ch] @@ -887,14 +816,11 @@ class PubnubCoreAsync(PubnubBase): self._connect() - def unsubscribe( self, args ): + def unsubscribe( self, channel ): - if 'channel' in self.subscriptions is False: + if channel in self.subscriptions is False: return False - channel = str(args['channel']) - - ## DISCONNECT with self._channel_list_lock: if channel in self.subscriptions: |
