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:
@@ -348,14 +348,14 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
|
|||||||
if self.cert_file:
|
if self.cert_file:
|
||||||
try:
|
try:
|
||||||
self.context.use_certificate_file(self.cert_file)
|
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)
|
msg = 'Unable to load cert from "%s" %s' % (self.cert_file, e)
|
||||||
raise exc.SSLConfigurationError(msg)
|
raise exc.SSLConfigurationError(msg)
|
||||||
if self.key_file is None:
|
if self.key_file is None:
|
||||||
# We support having key and cert in same file
|
# We support having key and cert in same file
|
||||||
try:
|
try:
|
||||||
self.context.use_privatekey_file(self.cert_file)
|
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 '
|
msg = ('No key file specified and unable to load key '
|
||||||
'from "%s" %s' % (self.cert_file, e))
|
'from "%s" %s' % (self.cert_file, e))
|
||||||
raise exc.SSLConfigurationError(msg)
|
raise exc.SSLConfigurationError(msg)
|
||||||
@@ -363,14 +363,14 @@ class VerifiedHTTPSConnection(httplib.HTTPSConnection):
|
|||||||
if self.key_file:
|
if self.key_file:
|
||||||
try:
|
try:
|
||||||
self.context.use_privatekey_file(self.key_file)
|
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)
|
msg = 'Unable to load key from "%s" %s' % (self.key_file, e)
|
||||||
raise exc.SSLConfigurationError(msg)
|
raise exc.SSLConfigurationError(msg)
|
||||||
|
|
||||||
if self.cacert:
|
if self.cacert:
|
||||||
try:
|
try:
|
||||||
self.context.load_verify_locations(self.cacert)
|
self.context.load_verify_locations(self.cacert)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
msg = 'Unable to load CA from "%s"' % (self.cacert, e)
|
msg = 'Unable to load CA from "%s"' % (self.cacert, e)
|
||||||
raise exc.SSLConfigurationError(msg)
|
raise exc.SSLConfigurationError(msg)
|
||||||
else:
|
else:
|
||||||
|
@@ -470,6 +470,6 @@ def main():
|
|||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print >> sys.stderr, '... terminating glance client'
|
print >> sys.stderr, '... terminating glance client'
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print >> sys.stderr, e
|
print >> sys.stderr, e
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
@@ -207,7 +207,7 @@ class ImageManager(base.Manager):
|
|||||||
obj_size = obj.tell()
|
obj_size = obj.tell()
|
||||||
obj.seek(0)
|
obj.seek(0)
|
||||||
return obj_size
|
return obj_size
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
if e.errno == errno.ESPIPE:
|
if e.errno == errno.ESPIPE:
|
||||||
# Illegal seek. This means the user is trying
|
# Illegal seek. This means the user is trying
|
||||||
# to pipe image data to the client, e.g.
|
# 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."""
|
"""Build a dictionary of query filters based on the supplied args."""
|
||||||
try:
|
try:
|
||||||
fields = get_image_fields_from_args(args)
|
fields = get_image_fields_from_args(args)
|
||||||
except RuntimeError, e:
|
except RuntimeError as e:
|
||||||
print e
|
print e
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ def do_add(gc, args):
|
|||||||
"""DEPRECATED! Use image-create instead."""
|
"""DEPRECATED! Use image-create instead."""
|
||||||
try:
|
try:
|
||||||
fields = get_image_fields_from_args(args.fields)
|
fields = get_image_fields_from_args(args.fields)
|
||||||
except RuntimeError, e:
|
except RuntimeError as e:
|
||||||
print e
|
print e
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
|
||||||
@@ -182,7 +182,7 @@ def do_update(gc, args):
|
|||||||
"""DEPRECATED! Use image-update instead."""
|
"""DEPRECATED! Use image-update instead."""
|
||||||
try:
|
try:
|
||||||
fields = get_image_fields_from_args(args.fields)
|
fields = get_image_fields_from_args(args.fields)
|
||||||
except RuntimeError, e:
|
except RuntimeError as e:
|
||||||
print e
|
print e
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
|
||||||
@@ -333,7 +333,7 @@ def do_clear(gc, args):
|
|||||||
image.delete()
|
image.delete()
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print 'done'
|
print 'done'
|
||||||
except Exception, e:
|
except Exception as e:
|
||||||
print 'Failed to delete image %s' % image.id
|
print 'Failed to delete image %s' % image.id
|
||||||
print e
|
print e
|
||||||
return FAILURE
|
return FAILURE
|
||||||
|
@@ -309,7 +309,7 @@ def do_image_delete(gc, args):
|
|||||||
if args.verbose:
|
if args.verbose:
|
||||||
print '[Done]'
|
print '[Done]'
|
||||||
|
|
||||||
except exc.HTTPException, e:
|
except exc.HTTPException as e:
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print '[Fail]'
|
print '[Fail]'
|
||||||
print '%s: Unable to delete image %s' % (e, args_image)
|
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
|
# rather than assertRaises() so that we can check the body of
|
||||||
# the exception.
|
# the exception.
|
||||||
self.fail('An exception should have bypassed this line.')
|
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'" %
|
fail_msg = ("Exception message '%s' should contain '%s'" %
|
||||||
(comm_err.message, self.endpoint))
|
(comm_err.message, self.endpoint))
|
||||||
self.assertTrue(self.endpoint in comm_err.message, fail_msg)
|
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')
|
client.raw_request('GET', '/v1/images/detail?limit=20')
|
||||||
|
|
||||||
self.fail('An exception should have bypassed this line.')
|
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'" %
|
fail_msg = ("Exception message '%s' should contain '%s'" %
|
||||||
(comm_err.message, endpoint))
|
(comm_err.message, endpoint))
|
||||||
self.assertTrue(endpoint in comm_err.message, fail_msg)
|
self.assertTrue(endpoint in comm_err.message, fail_msg)
|
||||||
|
@@ -27,7 +27,7 @@ class TestUtils(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
data = ''.join([f for f in utils.integrity_iter('A', None)])
|
data = ''.join([f for f in utils.integrity_iter('A', None)])
|
||||||
self.fail('integrity checked passed without checksum.')
|
self.fail('integrity checked passed without checksum.')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.assertEqual(errno.EPIPE, e.errno)
|
self.assertEqual(errno.EPIPE, e.errno)
|
||||||
msg = 'was 7fc56270e7a70fa81a5935b72eacbe29 expected None'
|
msg = 'was 7fc56270e7a70fa81a5935b72eacbe29 expected None'
|
||||||
self.assertTrue(msg in str(e))
|
self.assertTrue(msg in str(e))
|
||||||
@@ -36,7 +36,7 @@ class TestUtils(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
data = ''.join([f for f in utils.integrity_iter('BB', 'wrong')])
|
data = ''.join([f for f in utils.integrity_iter('BB', 'wrong')])
|
||||||
self.fail('integrity checked passed with wrong checksum')
|
self.fail('integrity checked passed with wrong checksum')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.assertEqual(errno.EPIPE, e.errno)
|
self.assertEqual(errno.EPIPE, e.errno)
|
||||||
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
|
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
|
||||||
self.assertTrue('expected wrong' in str(e))
|
self.assertTrue('expected wrong' in str(e))
|
||||||
|
@@ -333,7 +333,7 @@ class ImageManagerTest(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
data = ''.join([b for b in data])
|
data = ''.join([b for b in data])
|
||||||
self.fail('data did not raise an error.')
|
self.fail('data did not raise an error.')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.assertEqual(errno.EPIPE, e.errno)
|
self.assertEqual(errno.EPIPE, e.errno)
|
||||||
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
|
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
|
||||||
self.assertTrue(msg in str(e))
|
self.assertTrue(msg in str(e))
|
||||||
@@ -507,7 +507,7 @@ class ImageTest(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
data = ''.join([b for b in image.data()])
|
data = ''.join([b for b in image.data()])
|
||||||
self.fail('data did not raise an error.')
|
self.fail('data did not raise an error.')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.assertEqual(errno.EPIPE, e.errno)
|
self.assertEqual(errno.EPIPE, e.errno)
|
||||||
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
|
msg = 'was fd7c5c4fdaa97163ee4ba8842baa537a expected wrong'
|
||||||
self.assertTrue(msg in str(e))
|
self.assertTrue(msg in str(e))
|
||||||
|
@@ -289,7 +289,7 @@ class TestController(testtools.TestCase):
|
|||||||
try:
|
try:
|
||||||
body = ''.join([b for b in body])
|
body = ''.join([b for b in body])
|
||||||
self.fail('data did not raise an error.')
|
self.fail('data did not raise an error.')
|
||||||
except IOError, e:
|
except IOError as e:
|
||||||
self.assertEqual(errno.EPIPE, e.errno)
|
self.assertEqual(errno.EPIPE, e.errno)
|
||||||
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
|
msg = 'was 9d3d9048db16a7eee539e93e3618cbe7 expected wrong'
|
||||||
self.assertTrue(msg in str(e))
|
self.assertTrue(msg in str(e))
|
||||||
|
Reference in New Issue
Block a user