Improve Python 3.x compatibility

Some mechanical translation of the deprecated
except x,y construct. Should work with Python >= 2.6
just fine

Change-Id: I394f9956b9e3e3d9f5f1e9ad50c35b13200af2a1
This commit is contained in:
Dirk Mueller 2013-04-22 16:38:55 +02:00
parent 11c2c40d46
commit 45feb672af
9 changed files with 18 additions and 18 deletions

@ -348,14 +348,14 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
if self.cert_file:
try:
self.context.use_certificate_file(self.cert_file)
except Exception, e:
except Exception as e:
msg = 'Unable to load cert from "%s" %s' % (self.cert_file, e)
raise exc.SSLConfigurationError(msg)
if self.key_file is None:
# We support having key and cert in same file
try:
self.context.use_privatekey_file(self.cert_file)
except Exception, e:
except Exception as e:
msg = ('No key file specified and unable to load key '
'from "%s" %s' % (self.cert_file, e))
raise exc.SSLConfigurationError(msg)
@ -363,14 +363,14 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
if self.key_file:
try:
self.context.use_privatekey_file(self.key_file)
except Exception, e:
except Exception as e:
msg = 'Unable to load key from "%s" %s' % (self.key_file, e)
raise exc.SSLConfigurationError(msg)
if self.cacert:
try:
self.context.load_verify_locations(self.cacert)
except Exception, e:
except Exception as e:
msg = 'Unable to load CA from "%s"' % (self.cacert, e)
raise exc.SSLConfigurationError(msg)
else:

@ -470,6 +470,6 @@ def main():
except KeyboardInterrupt:
print >> sys.stderr, '... terminating glance client'
sys.exit(1)
except Exception, e:
except Exception as e:
print >> sys.stderr, e
sys.exit(1)

@ -207,7 +207,7 @@ class ImageManager(base.Manager):
obj_size = obj.tell()
obj.seek(0)
return obj_size
except IOError, e:
except IOError as e:
if e.errno == errno.ESPIPE:
# Illegal seek. This means the user is trying
# to pipe image data to the client, e.g.

@ -50,7 +50,7 @@ def get_image_filters_from_args(args):
"""Build a dictionary of query filters based on the supplied args."""
try:
fields = get_image_fields_from_args(args)
except RuntimeError, e:
except RuntimeError as e:
print e
return FAILURE
@ -108,7 +108,7 @@ def do_add(gc, args):
"""DEPRECATED! Use image-create instead."""
try:
fields = get_image_fields_from_args(args.fields)
except RuntimeError, e:
except RuntimeError as e:
print e
return FAILURE
@ -182,7 +182,7 @@ def do_update(gc, args):
"""DEPRECATED! Use image-update instead."""
try:
fields = get_image_fields_from_args(args.fields)
except RuntimeError, e:
except RuntimeError as e:
print e
return FAILURE
@ -333,7 +333,7 @@ def do_clear(gc, args):
image.delete()
if args.verbose:
print 'done'
except Exception, e:
except Exception as e:
print 'Failed to delete image %s' % image.id
print e
return FAILURE

@ -309,7 +309,7 @@ def do_image_delete(gc, args):
if args.verbose:
print '[Done]'
except exc.HTTPException, e:
except exc.HTTPException as e:
if args.verbose:
print '[Fail]'
print '%s: Unable to delete image %s' % (e, args_image)

@ -61,7 +61,7 @@ class TestClient(testtools.TestCase):
# rather than assertRaises() so that we can check the body of
# the exception.
self.fail('An exception should have bypassed this line.')
except exc.CommunicationError, comm_err:
except exc.CommunicationError as comm_err:
fail_msg = ("Exception message '%s' should contain '%s'" %
(comm_err.message, self.endpoint))
self.assertTrue(self.endpoint in comm_err.message, fail_msg)
@ -100,7 +100,7 @@ class TestClient(testtools.TestCase):
client.raw_request('GET', '/v1/images/detail?limit=20')
self.fail('An exception should have bypassed this line.')
except exc.CommunicationError, comm_err:
except exc.CommunicationError as comm_err:
fail_msg = ("Exception message '%s' should contain '%s'" %
(comm_err.message, endpoint))
self.assertTrue(endpoint in comm_err.message, fail_msg)

@ -27,7 +27,7 @@ class TestUtils(testtools.TestCase):
try:
data = ''.join([f for f in utils.integrity_iter('A', None)])
self.fail('integrity checked passed without checksum.')
except IOError, e:
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was 7fc56270e7a70fa81a5935b72eacbe29 expected None'
self.assertTrue(msg in str(e))
@ -36,7 +36,7 @@ class TestUtils(testtools.TestCase):
try:
data = ''.join([f for f in utils.integrity_iter('BB', 'wrong')])
self.fail('integrity checked passed with wrong checksum')
except IOError, e:
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
self.assertTrue('expected wrong' in str(e))

@ -333,7 +333,7 @@ class ImageManagerTest(testtools.TestCase):
try:
data = ''.join([b for b in data])
self.fail('data did not raise an error.')
except IOError, e:
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
self.assertTrue(msg in str(e))
@ -507,7 +507,7 @@ class ImageTest(testtools.TestCase):
try:
data = ''.join([b for b in image.data()])
self.fail('data did not raise an error.')
except IOError, e:
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
self.assertTrue(msg in str(e))

@ -289,7 +289,7 @@ class TestController(testtools.TestCase):
try:
body = ''.join([b for b in body])
self.fail('data did not raise an error.')
except IOError, e:
except IOError as e:
self.assertEqual(errno.EPIPE, e.errno)
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
self.assertTrue(msg in str(e))