HACKING compliance: consistent use of 'except'
Change-Id: I8301043965e08ffdec63441e612628d9a60876b7
This commit is contained in:
parent
a6ef09d943
commit
5761a2c55d
@ -119,9 +119,9 @@ class MySQLPingListener(object):
|
||||
def checkout(self, dbapi_con, con_record, con_proxy):
|
||||
try:
|
||||
dbapi_con.cursor().execute('select 1')
|
||||
except dbapi_con.OperationalError, ex:
|
||||
if ex.args[0] in (2006, 2013, 2014, 2045, 2055):
|
||||
logging.warn('Got mysql server has gone away: %s', ex)
|
||||
except dbapi_con.OperationalError as e:
|
||||
if e.args[0] in (2006, 2013, 2014, 2045, 2055):
|
||||
logging.warn('Got mysql server has gone away: %s', e)
|
||||
raise DisconnectionError("Database server went away")
|
||||
else:
|
||||
raise
|
||||
|
@ -286,7 +286,7 @@ class AuthProtocol(object):
|
||||
LOG.info('Invalid user token - rejecting request')
|
||||
return self._reject_request(env, start_response)
|
||||
|
||||
except ServiceError, e:
|
||||
except ServiceError as e:
|
||||
LOG.critical('Unable to obtain admin token: %s' % e)
|
||||
resp = webob.exc.HTTPServiceUnavailable()
|
||||
return resp(env, start_response)
|
||||
@ -378,7 +378,7 @@ class AuthProtocol(object):
|
||||
conn.request(method, path)
|
||||
response = conn.getresponse()
|
||||
body = response.read()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.error('HTTP connection exception: %s' % e)
|
||||
raise ServiceError('Unable to communicate with keystone')
|
||||
finally:
|
||||
@ -418,7 +418,7 @@ class AuthProtocol(object):
|
||||
conn.request(method, full_path, **kwargs)
|
||||
response = conn.getresponse()
|
||||
body = response.read()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
LOG.error('HTTP connection exception: %s' % e)
|
||||
raise ServiceError('Unable to communicate with keystone')
|
||||
finally:
|
||||
|
@ -147,7 +147,7 @@ class XmlBodyMiddleware(wsgi.Middleware):
|
||||
try:
|
||||
body_obj = jsonutils.loads(response.body)
|
||||
response.body = serializer.to_xml(body_obj)
|
||||
except:
|
||||
except Exception:
|
||||
raise exception.Error(message=response.body)
|
||||
return response
|
||||
|
||||
|
@ -99,7 +99,7 @@ class S3Token(object):
|
||||
headers=headers)
|
||||
response = conn.getresponse()
|
||||
output = response.read()
|
||||
except Exception, e:
|
||||
except Exception as e:
|
||||
self.logger.info('HTTP connection exception: %s' % e)
|
||||
resp = self.deny_request('InvalidURI')
|
||||
raise ServiceError(resp)
|
||||
@ -143,7 +143,7 @@ class S3Token(object):
|
||||
auth_header = req.headers['Authorization']
|
||||
try:
|
||||
access, signature = auth_header.split(' ')[-1].rsplit(':', 1)
|
||||
except(ValueError):
|
||||
except ValueError:
|
||||
msg = 'You have an invalid Authorization header: %s'
|
||||
self.logger.debug(msg % (auth_header))
|
||||
return self.deny_request('InvalidURI')(environ, start_response)
|
||||
|
@ -258,10 +258,6 @@ class RestfulTestCase(test.TestCase):
|
||||
class CoreApiTests(object):
|
||||
def assertValidError(self, error):
|
||||
"""Applicable to XML and JSON."""
|
||||
try:
|
||||
print error.attrib
|
||||
except:
|
||||
pass
|
||||
self.assertIsNotNone(error.get('code'))
|
||||
self.assertIsNotNone(error.get('title'))
|
||||
self.assertIsNotNone(error.get('message'))
|
||||
|
@ -29,7 +29,7 @@ class XmlSerializerTestCase(test.TestCase):
|
||||
"""
|
||||
try:
|
||||
self.assertEqual(a, b)
|
||||
except:
|
||||
except AssertionError:
|
||||
a = re.sub('[ \n]+', ' ', a).strip().split()
|
||||
b = re.sub('[ \n]+', ' ', b).strip().split()
|
||||
self.assertEqual(a, b)
|
||||
|
Loading…
Reference in New Issue
Block a user