From 0399a77a6a39c696841b1f16d85122d1a8c46552 Mon Sep 17 00:00:00 2001 From: Craig Citro Date: Sun, 17 Aug 2014 10:17:17 -0700 Subject: [PATCH] Update except statements to use `as` everywhere. --- oauth2client/appengine.py | 2 +- oauth2client/gce.py | 2 +- oauth2client/locked_file.py | 14 +++++++------- oauth2client/old_run.py | 4 ++-- oauth2client/tools.py | 4 ++-- tests/test_clientsecrets.py | 6 +++--- tests/test_oauth2client.py | 12 ++++++------ 7 files changed, 22 insertions(+), 22 deletions(-) diff --git a/oauth2client/appengine.py b/oauth2client/appengine.py index a08427d..0aaa877 100644 --- a/oauth2client/appengine.py +++ b/oauth2client/appengine.py @@ -193,7 +193,7 @@ class AppAssertionCredentials(AssertionCredentials): scopes = self.scope.split() (token, _) = app_identity.get_access_token( scopes, service_account_id=self.service_account_id) - except app_identity.Error, e: + except app_identity.Error as e: raise AccessTokenRefreshError(str(e)) self.access_token = token diff --git a/oauth2client/gce.py b/oauth2client/gce.py index 41cf89f..be8c528 100644 --- a/oauth2client/gce.py +++ b/oauth2client/gce.py @@ -84,7 +84,7 @@ class AppAssertionCredentials(AssertionCredentials): if response.status == 200: try: d = simplejson.loads(content) - except StandardError, e: + except StandardError as e: raise AccessTokenRefreshError(str(e)) self.access_token = d['accessToken'] else: diff --git a/oauth2client/locked_file.py b/oauth2client/locked_file.py index 88c2e8b..5087886 100644 --- a/oauth2client/locked_file.py +++ b/oauth2client/locked_file.py @@ -122,7 +122,7 @@ class _PosixOpener(_Opener): validate_file(self._filename) try: self._fh = open(self._filename, self._mode) - except IOError, e: + except IOError as e: # If we can't access with _mode, try _fallback_mode and don't lock. if e.errno == errno.EACCES: self._fh = open(self._filename, self._fallback_mode) @@ -137,7 +137,7 @@ class _PosixOpener(_Opener): self._locked = True break - except OSError, e: + except OSError as e: if e.errno != errno.EEXIST: raise if (time.time() - start_time) >= timeout: @@ -192,7 +192,7 @@ try: validate_file(self._filename) try: self._fh = open(self._filename, self._mode) - except IOError, e: + except IOError as e: # If we can't access with _mode, try _fallback_mode and don't lock. if e.errno in ( errno.EPERM, errno.EACCES ): self._fh = open(self._filename, self._fallback_mode) @@ -204,7 +204,7 @@ try: fcntl.lockf(self._fh.fileno(), fcntl.LOCK_EX) self._locked = True return - except IOError, e: + except IOError as e: # If not retrying, then just pass on the error. if timeout == 0: raise e @@ -267,7 +267,7 @@ try: validate_file(self._filename) try: self._fh = open(self._filename, self._mode) - except IOError, e: + except IOError as e: # If we can't access with _mode, try _fallback_mode and don't lock. if e.errno == errno.EACCES: self._fh = open(self._filename, self._fallback_mode) @@ -284,7 +284,7 @@ try: pywintypes.OVERLAPPED()) self._locked = True return - except pywintypes.error, e: + except pywintypes.error as e: if timeout == 0: raise e @@ -308,7 +308,7 @@ try: try: hfile = win32file._get_osfhandle(self._fh.fileno()) win32file.UnlockFileEx(hfile, 0, -0x10000, pywintypes.OVERLAPPED()) - except pywintypes.error, e: + except pywintypes.error as e: if e[0] != _Win32Opener.FILE_ALREADY_UNLOCKED_ERROR: raise self._locked = False diff --git a/oauth2client/old_run.py b/oauth2client/old_run.py index da23358..3a7fe96 100644 --- a/oauth2client/old_run.py +++ b/oauth2client/old_run.py @@ -96,7 +96,7 @@ def run(flow, storage, http=None): try: httpd = ClientRedirectServer((FLAGS.auth_host_name, port), ClientRedirectHandler) - except socket.error, e: + except socket.error as e: pass else: success = True @@ -150,7 +150,7 @@ def run(flow, storage, http=None): try: credential = flow.step2_exchange(code, http=http) - except client.FlowExchangeError, e: + except client.FlowExchangeError as e: sys.exit('Authentication has failed: %s' % e) storage.put(credential) diff --git a/oauth2client/tools.py b/oauth2client/tools.py index 8b3cd12..5d75e6f 100644 --- a/oauth2client/tools.py +++ b/oauth2client/tools.py @@ -163,7 +163,7 @@ def run_flow(flow, storage, flags, http=None): try: httpd = ClientRedirectServer((flags.auth_host_name, port), ClientRedirectHandler) - except socket.error, e: + except socket.error as e: pass else: success = True @@ -217,7 +217,7 @@ def run_flow(flow, storage, flags, http=None): try: credential = flow.step2_exchange(code, http=http) - except client.FlowExchangeError, e: + except client.FlowExchangeError as e: sys.exit('Authentication has failed: %s' % e) storage.put(credential) diff --git a/tests/test_clientsecrets.py b/tests/test_clientsecrets.py index f69fb36..ae6ecf1 100644 --- a/tests/test_clientsecrets.py +++ b/tests/test_clientsecrets.py @@ -61,7 +61,7 @@ class OAuth2CredentialsTests(unittest.TestCase): try: clientsecrets.loads(src) self.fail(src + ' should not be a valid client_secrets file.') - except clientsecrets.InvalidClientSecretsError, e: + except clientsecrets.InvalidClientSecretsError as e: self.assertTrue(str(e).startswith(match)) # Test loads(fp) @@ -69,14 +69,14 @@ class OAuth2CredentialsTests(unittest.TestCase): fp = StringIO.StringIO(src) clientsecrets.load(fp) self.fail(src + ' should not be a valid client_secrets file.') - except clientsecrets.InvalidClientSecretsError, e: + except clientsecrets.InvalidClientSecretsError as e: self.assertTrue(str(e).startswith(match)) def test_load_by_filename(self): try: clientsecrets._loadfile(NONEXISTENT_FILE) self.fail('should fail to load a missing client_secrets file.') - except clientsecrets.InvalidClientSecretsError, e: + except clientsecrets.InvalidClientSecretsError as e: self.assertTrue(str(e).startswith('File')) diff --git a/tests/test_oauth2client.py b/tests/test_oauth2client.py index a633fba..a4b56fd 100644 --- a/tests/test_oauth2client.py +++ b/tests/test_oauth2client.py @@ -125,7 +125,7 @@ class CredentialsTests(unittest.TestCase): class MockResponse(object): """Mock the response of urllib2.urlopen() call.""" - + def __init__(self, headers): self._headers = headers @@ -187,7 +187,7 @@ class GoogleCredentialsTests(unittest.TestCase): self.get_a_google_credentials_object().create_scoped_required()) def test_create_scoped(self): - credentials = self.get_a_google_credentials_object() + credentials = self.get_a_google_credentials_object() self.assertEqual(credentials, credentials.create_scoped(None)) self.assertEqual(credentials, credentials.create_scoped(['dummy_scope'])) @@ -380,7 +380,7 @@ class GoogleCredentialsTests(unittest.TestCase): from oauth2client import client self.assertEqual(None, getattr(client, '_env_name')) self.test_get_application_default_from_environment_variable_service_account() - self.assertEqual('UNKNOWN', getattr(client, '_env_name')) + self.assertEqual('UNKNOWN', getattr(client, '_env_name')) def test_get_application_default_from_environment_variable_authorized_user( self): @@ -840,7 +840,7 @@ class OAuth2WebServerFlowTest(unittest.TestCase): try: credentials = self.flow.step2_exchange('some random code', http=http) self.fail('should raise exception if exchange doesn\'t get 200') - except FlowExchangeError, e: + except FlowExchangeError as e: self.assertEquals('invalid_request', str(e)) def test_exchange_failure_with_json_error(self): @@ -858,7 +858,7 @@ class OAuth2WebServerFlowTest(unittest.TestCase): try: credentials = self.flow.step2_exchange('some random code', http=http) self.fail('should raise exception if exchange doesn\'t get 200') - except FlowExchangeError, e: + except FlowExchangeError as e: pass def test_exchange_success(self): @@ -923,7 +923,7 @@ class OAuth2WebServerFlowTest(unittest.TestCase): try: credentials = self.flow.step2_exchange(code, http=http) self.fail('should raise exception if no code in dictionary.') - except FlowExchangeError, e: + except FlowExchangeError as e: self.assertTrue('shall not pass' in str(e)) def test_exchange_id_token_fail(self):