Update except statements to use as everywhere.
This commit is contained in:
@@ -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
|
||||
|
||||
|
||||
@@ -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:
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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'))
|
||||
|
||||
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user