From: Aaron Hill Date: Fri, 21 Feb 2014 00:46:41 +0000 (-0500) Subject: Use new exception-related syntax for Python 3 compatibility X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=5bb8c4c63d99fba6715704e507894d07478ee7de;p=tweepy.git Use new exception-related syntax for Python 3 compatibility --- diff --git a/tweepy/api.py b/tweepy/api.py index 51a4bb6..d142285 100644 --- a/tweepy/api.py +++ b/tweepy/api.py @@ -329,7 +329,7 @@ class API(object): require_auth = True, allowed_param = ['include_entities', 'skip_status'], )(self, **kargs) - except TweepError, e: + except TweepError as e: if e.response and e.response.status == 401: return False raise diff --git a/tweepy/auth.py b/tweepy/auth.py index 29df5b2..86c4430 100644 --- a/tweepy/auth.py +++ b/tweepy/auth.py @@ -67,7 +67,7 @@ class OAuthHandler(AuthHandler): request.sign_request(self._sigmethod, self._consumer, None) resp = urlopen(Request(url, headers=request.to_header())) return oauth.OAuthToken.from_string(resp.read()) - except Exception, e: + except Exception as e: raise TweepError(e) def set_request_token(self, key, secret): @@ -92,7 +92,7 @@ class OAuthHandler(AuthHandler): ) return request.to_url() - except Exception, e: + except Exception as e: raise TweepError(e) def get_access_token(self, verifier=None): @@ -115,7 +115,7 @@ class OAuthHandler(AuthHandler): resp = urlopen(Request(url, headers=request.to_header())) self.access_token = oauth.OAuthToken.from_string(resp.read()) return self.access_token - except Exception, e: + except Exception as e: raise TweepError(e) def get_xauth_access_token(self, username, password): @@ -141,7 +141,7 @@ class OAuthHandler(AuthHandler): resp = urlopen(Request(url, data=request.to_postdata())) self.access_token = oauth.OAuthToken.from_string(resp.read()) return self.access_token - except Exception, e: + except Exception as e: raise TweepError(e) def get_username(self): diff --git a/tweepy/binder.py b/tweepy/binder.py index 29eacae..1f8c619 100644 --- a/tweepy/binder.py +++ b/tweepy/binder.py @@ -153,7 +153,7 @@ def bind_api(**config): try: conn.request(self.method, url, headers=self.headers, body=self.post_data) resp = conn.getresponse() - except Exception, e: + except Exception as e: raise TweepError('Failed to send request: %s' % e) # Exit request loop if non-retry error code @@ -181,7 +181,7 @@ def bind_api(**config): try: zipper = gzip.GzipFile(fileobj=StringIO(body)) body = zipper.read() - except Exception, e: + except Exception as e: raise TweepError('Failed to decompress data: %s' % e) result = self.api.parser.parse(self, body) diff --git a/tweepy/parsers.py b/tweepy/parsers.py index 55a5ba8..31e0022 100644 --- a/tweepy/parsers.py +++ b/tweepy/parsers.py @@ -48,7 +48,7 @@ class JSONParser(Parser): def parse(self, method, payload): try: json = self.json_lib.loads(payload) - except Exception, e: + except Exception as e: raise TweepError('Failed to parse JSON payload: %s' % e) needsCursors = method.parameters.has_key('cursor') diff --git a/tweepy/streaming.py b/tweepy/streaming.py index 533f1b3..be233ff 100644 --- a/tweepy/streaming.py +++ b/tweepy/streaming.py @@ -171,7 +171,7 @@ class Stream(object): self.snooze_time = self.snooze_time_step self.listener.on_connect() self._read_loop(resp) - except (timeout, ssl.SSLError), exc: + except (timeout, ssl.SSLError) as exc: # If it's not time out treat it like any other exception if isinstance(exc, ssl.SSLError) and not (exc.args and 'timed out' in str(exc.args[0])): exception = exc @@ -185,7 +185,7 @@ class Stream(object): sleep(self.snooze_time) self.snooze_time = min(self.snooze_time + self.snooze_time_step, self.snooze_time_cap) - except Exception, exception: + except Exception as exception: # any other exception is fatal, so kill loop break diff --git a/tweepy/utils.py b/tweepy/utils.py index 7c2d498..3085ba1 100644 --- a/tweepy/utils.py +++ b/tweepy/utils.py @@ -47,7 +47,7 @@ def import_simplejson(): try: from django.utils import simplejson as json # Google App Engine except ImportError: - raise ImportError, "Can't load a json library" + raise ImportError("Can't load a json library") return json