diff options
| author | Devendra | 2014-04-23 21:35:06 +0530 | 
|---|---|---|
| committer | Devendra | 2014-04-23 21:35:06 +0530 | 
| commit | f7b89bfafae34fa22509c1d1c59d1284ec62c5df (patch) | |
| tree | 2eeaf63f906ade16c82c86844e8f76b191b9ad6c /common | |
| parent | 1d97c69f186719fe007a4fa0033d39d9a68a4e43 (diff) | |
| download | pubnub-python-f7b89bfafae34fa22509c1d1c59d1284ec62c5df.tar.bz2 | |
exception handling changes
Diffstat (limited to 'common')
| -rw-r--r-- | common/PubnubBase.py | 13 | ||||
| -rw-r--r-- | common/PubnubCore.py | 20 | ||||
| -rw-r--r-- | common/PubnubCoreAsync.py | 24 | 
3 files changed, 18 insertions, 39 deletions
| diff --git a/common/PubnubBase.py b/common/PubnubBase.py index 5863da9..9a20034 100644 --- a/common/PubnubBase.py +++ b/common/PubnubBase.py @@ -10,7 +10,7 @@ import sys  try:      from urllib.parse import quote -except: +except ImportError:      from urllib2 import quote  from base64 import urlsafe_b64encode @@ -221,7 +221,7 @@ class PubnubBase(object):          """ -        message = self.encrypt(args['message']) +        message = self.encrypt(message)          ## Send Message          return self._request({"urlcomponents": [ @@ -282,15 +282,6 @@ class PubnubBase(object):          print(here_now['uuids'])          """ -        channel = str(args['channel']) - -        callback = args['callback'] if 'callback' in args else None -        error = args['error'] if 'error' in args else None - -        ## Fail if bad input. -        if not channel: -            raise Exception('Missing Channel') -            return False          ## Get Presence Here Now          return self._request({"urlcomponents": [ 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): diff --git a/common/PubnubCoreAsync.py b/common/PubnubCoreAsync.py index de7627f..f8e9e68 100644 --- a/common/PubnubCoreAsync.py +++ b/common/PubnubCoreAsync.py @@ -248,21 +248,23 @@ class PubnubCoreAsync(PubnubBase):                  return              ## CONNECT TO PUBNUB SUBSCRIBE SERVERS -            try: -                self.SUB_RECEIVER = self._request({"urlcomponents": [ -                    'subscribe', -                    self.subscribe_key, -                    channel_list, -                    '0', -                    str(self.timetoken) -                ], "urlparams": {"uuid": self.uuid, "auth": self.auth_key}}, -                    sub_callback, -                    sub_callback, -                    single=True) +            #try: +            self.SUB_RECEIVER = self._request({"urlcomponents": [ +                'subscribe', +                self.subscribe_key, +                channel_list, +                '0', +                str(self.timetoken) +            ], "urlparams": {"uuid": self.uuid, "auth": self.auth_key}}, +                sub_callback, +                sub_callback, +                single=True) +            '''              except Exception as e:                  print(e)                  self.timeout(1, _connect)                  return +            '''          self._connect = _connect | 
