Skip to content

Commit

Permalink
Standardize on newer except syntax
Browse files Browse the repository at this point in the history
We currently have a mix of 'except X, y:' and 'except X as y:' syntax.
Standardize on the newer 'except as' form.

This patch was generated automatically using:

find * -type f -name 'glance-*' ! -name '*\.conf' ! -name '*\.ini' -o \
 -name '*\.py' | xargs 2to3 -f except | patch -p0

Addresses bug 1160331.

Change-Id: Ica8d1303973af64d0406457267ee75f608e869d0
  • Loading branch information
Stuart McLaren committed Mar 26, 2013
1 parent 46fcf87 commit 19b82a0
Show file tree
Hide file tree
Showing 36 changed files with 116 additions and 116 deletions.
4 changes: 2 additions & 2 deletions bin/glance-api
Expand Up @@ -59,7 +59,7 @@ if __name__ == '__main__':
server = wsgi.Server()
server.start(config.load_paste_app(), default_port=9292)
server.wait()
except exception.WorkerCreationFailure, e:
except exception.WorkerCreationFailure as e:
fail(2, e)
except RuntimeError, e:
except RuntimeError as e:
fail(1, e)
2 changes: 1 addition & 1 deletion bin/glance-cache-cleaner
Expand Up @@ -62,5 +62,5 @@ if __name__ == '__main__':

app = cleaner.Cleaner()
app.run()
except RuntimeError, e:
except RuntimeError as e:
sys.exit("ERROR: %s" % e)
4 changes: 2 additions & 2 deletions bin/glance-cache-manage
Expand Up @@ -64,7 +64,7 @@ def catch_error(action):
except exception.Forbidden:
print "Not authorized to make this request."
return FAILURE
except Exception, e:
except Exception as e:
options = args[0]
if options.debug:
raise
Expand Down Expand Up @@ -512,5 +512,5 @@ Commands:
if options.verbose:
print "Completed in %-0.4f sec." % (end_time - start_time)
sys.exit(result)
except (RuntimeError, NotImplementedError), e:
except (RuntimeError, NotImplementedError) as e:
print "ERROR: ", e
2 changes: 1 addition & 1 deletion bin/glance-cache-prefetcher
Expand Up @@ -57,5 +57,5 @@ if __name__ == '__main__':

app = prefetcher.Prefetcher()
app.run()
except RuntimeError, e:
except RuntimeError as e:
sys.exit("ERROR: %s" % e)
2 changes: 1 addition & 1 deletion bin/glance-cache-pruner
Expand Up @@ -54,5 +54,5 @@ if __name__ == '__main__':

app = pruner.Pruner()
app.run()
except RuntimeError, e:
except RuntimeError as e:
sys.exit("ERROR: %s" % e)
2 changes: 1 addition & 1 deletion bin/glance-control
Expand Up @@ -172,7 +172,7 @@ def do_start(verb, pid_file, server, args):
redirect_stdio(server, capture_output)
try:
os.execlp('%s' % server, *args)
except OSError, e:
except OSError as e:
msg = 'unable to launch %s. Got error: %s' % (server, e)
sys.exit(msg)
sys.exit(0)
Expand Down
4 changes: 2 additions & 2 deletions bin/glance-manage
Expand Up @@ -121,12 +121,12 @@ def main():
config.parse_args(default_config_files=default_cfg_files,
usage="%(prog)s [options] <cmd>")
log.setup('glance')
except RuntimeError, e:
except RuntimeError as e:
sys.exit("ERROR: %s" % e)

try:
CONF.command.func()
except exception.GlanceException, e:
except exception.GlanceException as e:
sys.exit("ERROR: %s" % e)


Expand Down
2 changes: 1 addition & 1 deletion bin/glance-registry
Expand Up @@ -49,5 +49,5 @@ if __name__ == '__main__':
server = wsgi.Server()
server.start(config.load_paste_app(), default_port=9191)
server.wait()
except RuntimeError, e:
except RuntimeError as e:
sys.exit("ERROR: %s" % e)
2 changes: 1 addition & 1 deletion bin/glance-scrubber
Expand Up @@ -74,5 +74,5 @@ if __name__ == '__main__':
import eventlet
pool = eventlet.greenpool.GreenPool(1000)
scrubber = app.run(pool)
except RuntimeError, e:
except RuntimeError as e:
sys.exit("ERROR: %s" % e)
4 changes: 2 additions & 2 deletions glance/api/common.py
Expand Up @@ -37,7 +37,7 @@ def notify_image_sent_hook(env):
for chunk in image_iter:
yield chunk
bytes_written += len(chunk)
except Exception, err:
except Exception as err:
msg = _("An error occurred reading from backend storage "
"for image %(image_id)s: %(err)s") % locals()
LOG.error(msg)
Expand Down Expand Up @@ -72,7 +72,7 @@ def image_send_notification(bytes_written, expected_size, image_meta, request,

notify('image.send', payload)

except Exception, err:
except Exception as err:
msg = _("An error occurred during image.send"
" notification: %(err)s") % locals()
LOG.error(msg)
36 changes: 18 additions & 18 deletions glance/api/v1/images.py
Expand Up @@ -169,7 +169,7 @@ def index(self, req):
params = self._get_query_params(req)
try:
images = registry.get_images_list(req.context, **params)
except exception.Invalid, e:
except exception.Invalid as e:
raise HTTPBadRequest(explanation="%s" % e)

return dict(images=images)
Expand Down Expand Up @@ -209,7 +209,7 @@ def detail(self, req):
# information to the API end user...
for image in images:
del image['location']
except exception.Invalid, e:
except exception.Invalid as e:
raise HTTPBadRequest(explanation="%s" % e)
return dict(images=images)

Expand Down Expand Up @@ -297,7 +297,7 @@ def _external_source(image_meta, req):
def _get_from_store(context, where):
try:
image_data, image_size = get_from_backend(context, where)
except exception.NotFound, e:
except exception.NotFound as e:
raise HTTPNotFound(explanation="%s" % e)
image_size = int(image_size) if image_size else None
return image_data, image_size
Expand Down Expand Up @@ -374,7 +374,7 @@ def _reserve(self, req, image_meta):
raise HTTPConflict(explanation=msg,
request=req,
content_type="text/plain")
except exception.Invalid, e:
except exception.Invalid as e:
msg = (_("Failed to reserve image. Got error: %(e)s") % locals())
for line in msg.split('\n'):
LOG.debug(line)
Expand Down Expand Up @@ -476,53 +476,53 @@ def _kill_mismatched(image_meta, attr, actual):

return location

except exception.Duplicate, e:
except exception.Duplicate as e:
msg = _("Attempt to upload duplicate image: %s") % e
LOG.debug(msg)
self._safe_kill(req, image_id)
raise HTTPConflict(explanation=msg, request=req)

except exception.Forbidden, e:
except exception.Forbidden as e:
msg = _("Forbidden upload attempt: %s") % e
LOG.debug(msg)
self._safe_kill(req, image_id)
raise HTTPForbidden(explanation=msg,
request=req,
content_type="text/plain")

except exception.StorageFull, e:
except exception.StorageFull as e:
msg = _("Image storage media is full: %s") % e
LOG.error(msg)
self._safe_kill(req, image_id)
self.notifier.error('image.upload', msg)
raise HTTPRequestEntityTooLarge(explanation=msg, request=req,
content_type='text/plain')

except exception.StorageWriteDenied, e:
except exception.StorageWriteDenied as e:
msg = _("Insufficient permissions on image storage media: %s") % e
LOG.error(msg)
self._safe_kill(req, image_id)
self.notifier.error('image.upload', msg)
raise HTTPServiceUnavailable(explanation=msg, request=req,
content_type='text/plain')

except exception.ImageSizeLimitExceeded, e:
except exception.ImageSizeLimitExceeded as e:
msg = _("Denying attempt to upload image larger than %d bytes."
% CONF.image_size_cap)
LOG.info(msg)
self._safe_kill(req, image_id)
raise HTTPBadRequest(explanation=msg, request=req,
content_type='text/plain')

except HTTPError, e:
except HTTPError as e:
self._safe_kill(req, image_id)
#NOTE(bcwaldon): Ideally, we would just call 'raise' here,
# but something in the above function calls is affecting the
# exception context and we must explicitly re-raise the
# caught exception.
raise e

except Exception, e:
except Exception as e:
LOG.exception(_("Failed to upload image"))
self._safe_kill(req, image_id)
raise HTTPInternalServerError(request=req)
Expand All @@ -547,7 +547,7 @@ def _activate(self, req, image_id, location):
self.notifier.info("image.activate", redact_loc(image_meta_data))
self.notifier.info("image.update", redact_loc(image_meta_data))
return image_meta_data
except exception.Invalid, e:
except exception.Invalid as e:
msg = (_("Failed to activate image. Got error: %(e)s")
% locals())
LOG.debug(msg)
Expand Down Expand Up @@ -577,7 +577,7 @@ def _safe_kill(self, req, image_id):
"""
try:
self._kill(req, image_id)
except Exception, e:
except Exception as e:
LOG.error(_("Unable to kill image %(id)s: "
"%(exc)s") % ({'id': image_id,
'exc': repr(e)}))
Expand Down Expand Up @@ -775,21 +775,21 @@ def update(self, req, id, image_meta, image_data):
image_meta = self._handle_source(req, id, image_meta,
image_data)

except exception.Invalid, e:
except exception.Invalid as e:
msg = (_("Failed to update image metadata. Got error: %(e)s")
% locals())
LOG.debug(msg)
raise HTTPBadRequest(explanation=msg,
request=req,
content_type="text/plain")
except exception.NotFound, e:
except exception.NotFound as e:
msg = (_("Failed to find image to update: %(e)s") % locals())
for line in msg.split('\n'):
LOG.info(line)
raise HTTPNotFound(explanation=msg,
request=req,
content_type="text/plain")
except exception.Forbidden, e:
except exception.Forbidden as e:
msg = (_("Forbidden to update image: %(e)s") % locals())
for line in msg.split('\n'):
LOG.info(line)
Expand Down Expand Up @@ -859,14 +859,14 @@ def delete(self, req, id):
# See https://bugs.launchpad.net/glance/+bug/747799
if image['location']:
self._initiate_deletion(req, image['location'], id)
except exception.NotFound, e:
except exception.NotFound as e:
msg = (_("Failed to find image to delete: %(e)s") % locals())
for line in msg.split('\n'):
LOG.info(line)
raise HTTPNotFound(explanation=msg,
request=req,
content_type="text/plain")
except exception.Forbidden, e:
except exception.Forbidden as e:
msg = (_("Forbidden to delete image: %(e)s") % locals())
for line in msg.split('\n'):
LOG.info(line)
Expand Down
20 changes: 10 additions & 10 deletions glance/api/v1/members.py
Expand Up @@ -69,11 +69,11 @@ def delete(self, req, image_id, id):
try:
registry.delete_member(req.context, image_id, id)
self._update_store_acls(req, image_id)
except exception.NotFound, e:
except exception.NotFound as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
except exception.Forbidden, e:
except exception.Forbidden as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
Expand Down Expand Up @@ -107,15 +107,15 @@ def update(self, req, image_id, id, body=None):
try:
registry.add_member(req.context, image_id, id, can_share)
self._update_store_acls(req, image_id)
except exception.Invalid, e:
except exception.Invalid as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NotFound, e:
except exception.NotFound as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
except exception.Forbidden, e:
except exception.Forbidden as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
Expand All @@ -138,15 +138,15 @@ def update_all(self, req, image_id, body):
try:
registry.replace_members(req.context, image_id, body)
self._update_store_acls(req, image_id)
except exception.Invalid, e:
except exception.Invalid as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPBadRequest(explanation=msg)
except exception.NotFound, e:
except exception.NotFound as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
except exception.Forbidden, e:
except exception.Forbidden as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
Expand All @@ -168,11 +168,11 @@ def index_shared_images(self, req, id):
"""
try:
members = registry.get_member_images(req.context, id)
except exception.NotFound, e:
except exception.NotFound as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPNotFound(msg)
except exception.Forbidden, e:
except exception.Forbidden as e:
msg = "%s" % e
LOG.debug(msg)
raise webob.exc.HTTPForbidden(msg)
Expand Down
16 changes: 8 additions & 8 deletions glance/api/v2/image_data.py
Expand Up @@ -52,39 +52,39 @@ def upload(self, req, image_id, data, size):
image_repo.save(image)
image.set_data(data, size)
image_repo.save(image)
except ValueError, e:
except ValueError as e:
LOG.debug("Cannot save data for image %s: %s", image_id, e)
raise webob.exc.HTTPBadRequest(explanation=unicode(e))
except exception.Duplicate, e:
except exception.Duplicate as e:
msg = _("Unable to upload duplicate image data for image: %s")
LOG.debug(msg % image_id)
raise webob.exc.HTTPConflict(explanation=msg, request=req)

except exception.Forbidden, e:
except exception.Forbidden as e:
msg = _("Not allowed to upload image data for image %s")
LOG.debug(msg % image_id)
raise webob.exc.HTTPForbidden(explanation=msg, request=req)

except exception.NotFound, e:
except exception.NotFound as e:
raise webob.exc.HTTPNotFound(explanation=unicode(e))

except exception.StorageFull, e:
except exception.StorageFull as e:
msg = _("Image storage media is full: %s") % e
LOG.error(msg)
raise webob.exc.HTTPRequestEntityTooLarge(explanation=msg,
request=req)

except exception.StorageWriteDenied, e:
except exception.StorageWriteDenied as e:
msg = _("Insufficient permissions on image storage media: %s") % e
LOG.error(msg)
raise webob.exc.HTTPServiceUnavailable(explanation=msg,
request=req)

except webob.exc.HTTPError, e:
except webob.exc.HTTPError as e:
LOG.error(_("Failed to upload image data due to HTTP error"))
raise

except Exception, e:
except Exception as e:
LOG.exception(_("Failed to upload image data due to "
"internal error"))
raise
Expand Down
2 changes: 1 addition & 1 deletion glance/common/client.py
Expand Up @@ -518,7 +518,7 @@ def _retry(res):
raise exception.UnexpectedStatus(status=status_code,
body=res.read())

except (socket.error, IOError), e:
except (socket.error, IOError) as e:
raise exception.ClientConnectionError(e)

def _seekable(self, body):
Expand Down
2 changes: 1 addition & 1 deletion glance/common/config.py
Expand Up @@ -210,7 +210,7 @@ def load_paste_app(app_name=None):
CONF.log_opt_values(logger, logging.DEBUG)

return app
except (LookupError, ImportError), e:
except (LookupError, ImportError) as e:
msg = _("Unable to load %(app_name)s from "
"configuration file %(conf_file)s."
"\nGot: %(e)r") % locals()
Expand Down

0 comments on commit 19b82a0

Please sign in to comment.