diff options
| author | Devendra | 2014-05-02 20:19:57 +0530 | 
|---|---|---|
| committer | Devendra | 2014-05-02 20:19:57 +0530 | 
| commit | ca29b41c781c3a9861141811b208432fbda8aa0a (patch) | |
| tree | d16eb6dad2bedc25c438f20ba8528ebbc0864e02 /Pubnub.py | |
| parent | 8a642ab92c537c84960ef3943b34aac95bc39121 (diff) | |
| download | pubnub-python-ca29b41c781c3a9861141811b208432fbda8aa0a.tar.bz2 | |
enahancements to dev console
Diffstat (limited to 'Pubnub.py')
| -rw-r--r-- | Pubnub.py | 52 | 
1 files changed, 27 insertions, 25 deletions
| @@ -713,7 +713,7 @@ class PubnubCoreAsync(PubnubBase):          for i in l:              func(i) -    def subscribe(self, channel, callback, error=None, +    def subscribe(self, channels, callback, error=None,                    connect=None, disconnect=None, reconnect=None, sync=False):          """          #** @@ -756,11 +756,13 @@ class PubnubCoreAsync(PubnubBase):              self.susbcribe_sync(args)              return -        def _invoke(func, msg=None): +        def _invoke(func, msg=None, channel=None):              if func is not None: -                if msg is not None: +                if msg is not None and channel is not None: +                    func(msg,channel) +                elif msg is not None:                      func(msg) -                else: +                else :                      func()          def _invoke_connect(): @@ -802,31 +804,32 @@ class PubnubCoreAsync(PubnubBase):                  chobj = self.subscriptions[ch]                  if chobj['subscribed'] is True:                      return chobj - -        ## New Channel? -        if not channel in self.subscriptions or \ -                self.subscriptions[channel]['subscribed'] is False: -                with self._channel_list_lock: -                    self.subscriptions[channel] = { -                        'name': channel, -                        'first': False, -                        'connected': False, -                        'disconnected': True, -                        'subscribed': True, -                        'callback': callback, -                        'connect': connect, -                        'disconnect': disconnect, -                        'reconnect': reconnect, -                        'error': error -                    } - +        channels = channels if isinstance(channels,list) else channels.split(",") +        for channel in channels: +            ## New Channel? +            if not channel in self.subscriptions or \ +                    self.subscriptions[channel]['subscribed'] is False: +                    with self._channel_list_lock: +                        self.subscriptions[channel] = { +                            'name': channel, +                            'first': False, +                            'connected': False, +                            'disconnected': True, +                            'subscribed': True, +                            'callback': callback, +                            'connect': connect, +                            'disconnect': disconnect, +                            'reconnect': reconnect, +                            'error': error +                        } +        '''          ## return if already connected to channel          if channel in self.subscriptions and \              'connected' in self.subscriptions[channel] and \                  self.subscriptions[channel]['connected'] is True:                      _invoke(error, "Already Connected")                      return - +        '''          ## SUBSCRIPTION RECURSION          def _connect(): @@ -845,6 +848,7 @@ class PubnubCoreAsync(PubnubBase):                      _invoke_error(err=response['message'])                  else:                      _invoke_disconnect() +                    self.timetoken = 0                      self.timeout(1, _connect)              def sub_callback(response): @@ -1129,8 +1133,6 @@ def _requests_request(url, timeout=320):          msg = str(error)          return (json.dumps(msg), 0)      except requests.exceptions.Timeout as error: -        #print(error); -        #print('timeout');          msg = str(error)          return (json.dumps(msg), 0) | 
