HACKING compliance: consistent use of 'except'

Change-Id: I8301043965e08ffdec63441e612628d9a60876b7
This commit is contained in:
Dolph Mathews 2012-11-05 10:52:57 -06:00
parent a6ef09d943
commit 5761a2c55d
6 changed files with 10 additions and 14 deletions

View File

@ -119,9 +119,9 @@ class MySQLPingListener(object):
def checkout(self, dbapi_con, con_record, con_proxy): def checkout(self, dbapi_con, con_record, con_proxy):
try: try:
dbapi_con.cursor().execute('select 1') dbapi_con.cursor().execute('select 1')
except dbapi_con.OperationalError, ex: except dbapi_con.OperationalError as e:
if ex.args[0] in (2006, 2013, 2014, 2045, 2055): if e.args[0] in (2006, 2013, 2014, 2045, 2055):
logging.warn('Got mysql server has gone away: %s', ex) logging.warn('Got mysql server has gone away: %s', e)
raise DisconnectionError("Database server went away") raise DisconnectionError("Database server went away")
else: else:
raise raise

View File

@ -286,7 +286,7 @@ class AuthProtocol(object):
LOG.info('Invalid user token - rejecting request') LOG.info('Invalid user token - rejecting request')
return self._reject_request(env, start_response) return self._reject_request(env, start_response)
except ServiceError, e: except ServiceError as e:
LOG.critical('Unable to obtain admin token: %s' % e) LOG.critical('Unable to obtain admin token: %s' % e)
resp = webob.exc.HTTPServiceUnavailable() resp = webob.exc.HTTPServiceUnavailable()
return resp(env, start_response) return resp(env, start_response)
@ -378,7 +378,7 @@ class AuthProtocol(object):
conn.request(method, path) conn.request(method, path)
response = conn.getresponse() response = conn.getresponse()
body = response.read() body = response.read()
except Exception, e: except Exception as e:
LOG.error('HTTP connection exception: %s' % e) LOG.error('HTTP connection exception: %s' % e)
raise ServiceError('Unable to communicate with keystone') raise ServiceError('Unable to communicate with keystone')
finally: finally:
@ -418,7 +418,7 @@ class AuthProtocol(object):
conn.request(method, full_path, **kwargs) conn.request(method, full_path, **kwargs)
response = conn.getresponse() response = conn.getresponse()
body = response.read() body = response.read()
except Exception, e: except Exception as e:
LOG.error('HTTP connection exception: %s' % e) LOG.error('HTTP connection exception: %s' % e)
raise ServiceError('Unable to communicate with keystone') raise ServiceError('Unable to communicate with keystone')
finally: finally:

View File

@ -147,7 +147,7 @@ class XmlBodyMiddleware(wsgi.Middleware):
try: try:
body_obj = jsonutils.loads(response.body) body_obj = jsonutils.loads(response.body)
response.body = serializer.to_xml(body_obj) response.body = serializer.to_xml(body_obj)
except: except Exception:
raise exception.Error(message=response.body) raise exception.Error(message=response.body)
return response return response

View File

@ -99,7 +99,7 @@ class S3Token(object):
headers=headers) headers=headers)
response = conn.getresponse() response = conn.getresponse()
output = response.read() output = response.read()
except Exception, e: except Exception as e:
self.logger.info('HTTP connection exception: %s' % e) self.logger.info('HTTP connection exception: %s' % e)
resp = self.deny_request('InvalidURI') resp = self.deny_request('InvalidURI')
raise ServiceError(resp) raise ServiceError(resp)
@ -143,7 +143,7 @@ class S3Token(object):
auth_header = req.headers['Authorization'] auth_header = req.headers['Authorization']
try: try:
access, signature = auth_header.split(' ')[-1].rsplit(':', 1) access, signature = auth_header.split(' ')[-1].rsplit(':', 1)
except(ValueError): except ValueError:
msg = 'You have an invalid Authorization header: %s' msg = 'You have an invalid Authorization header: %s'
self.logger.debug(msg % (auth_header)) self.logger.debug(msg % (auth_header))
return self.deny_request('InvalidURI')(environ, start_response) return self.deny_request('InvalidURI')(environ, start_response)

View File

@ -258,10 +258,6 @@ class RestfulTestCase(test.TestCase):
class CoreApiTests(object): class CoreApiTests(object):
def assertValidError(self, error): def assertValidError(self, error):
"""Applicable to XML and JSON.""" """Applicable to XML and JSON."""
try:
print error.attrib
except:
pass
self.assertIsNotNone(error.get('code')) self.assertIsNotNone(error.get('code'))
self.assertIsNotNone(error.get('title')) self.assertIsNotNone(error.get('title'))
self.assertIsNotNone(error.get('message')) self.assertIsNotNone(error.get('message'))

View File

@ -29,7 +29,7 @@ class XmlSerializerTestCase(test.TestCase):
""" """
try: try:
self.assertEqual(a, b) self.assertEqual(a, b)
except: except AssertionError:
a = re.sub('[ \n]+', ' ', a).strip().split() a = re.sub('[ \n]+', ' ', a).strip().split()
b = re.sub('[ \n]+', ' ', b).strip().split() b = re.sub('[ \n]+', ' ', b).strip().split()
self.assertEqual(a, b) self.assertEqual(a, b)