From f83b7eaf0940791002b8834890d7d903ec11a77d Mon Sep 17 00:00:00 2001 From: Dirk Mueller Date: Tue, 23 Apr 2013 00:12:22 +0200 Subject: [PATCH] Improve Python 3.x compatibility Mechanical translation of the deprecated except x,y: construct. the except x as y: construct works with all python 2.6+ versions Change-Id: Iad349b8079a01bbd66a22800ae2fcdfcde03b377 --- heat/cfn_client/utils.py | 4 ++-- heat/common/auth_token.py | 4 ++-- heat/common/client.py | 2 +- heat/common/config.py | 2 +- heat/common/exception.py | 2 +- heat/common/wsgi.py | 6 +++--- heat/db/sqlalchemy/models.py | 2 +- heat/db/sqlalchemy/session.py | 2 +- heat/tests/functional/util.py | 2 +- tools/hacking.py | 2 +- 10 files changed, 14 insertions(+), 14 deletions(-) diff --git a/heat/cfn_client/utils.py b/heat/cfn_client/utils.py index 85e02224..58fb7257 100644 --- a/heat/cfn_client/utils.py +++ b/heat/cfn_client/utils.py @@ -38,11 +38,11 @@ def catch_error(action): return FAILURE except exception.ClientConfigurationError: raise - except exception.KeystoneError, e: + except exception.KeystoneError as e: LOG.error("Keystone did not finish the authentication and " "returned the following message:\n\n%s" % e.message) return FAILURE - except Exception, e: + except Exception as e: options = arguments[0] if options.debug: raise diff --git a/heat/common/auth_token.py b/heat/common/auth_token.py index bf558b31..10c48bc2 100644 --- a/heat/common/auth_token.py +++ b/heat/common/auth_token.py @@ -184,7 +184,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) @@ -285,7 +285,7 @@ class AuthProtocol(object): conn.request(method, 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: diff --git a/heat/common/client.py b/heat/common/client.py index fd99ad5f..5c772f1c 100644 --- a/heat/common/client.py +++ b/heat/common/client.py @@ -501,7 +501,7 @@ class BaseClient(object): else: raise Exception("Unknown error occurred! %s" % res.read()) - except (socket.error, IOError), e: + except (socket.error, IOError) as e: raise exception.ClientConnectionError(e) def _iterable(self, body): diff --git a/heat/common/config.py b/heat/common/config.py index cd23d8db..9d631d9b 100644 --- a/heat/common/config.py +++ b/heat/common/config.py @@ -202,7 +202,7 @@ def load_paste_app(app_name=None): sys_logging.DEBUG) return app - except (LookupError, ImportError), e: + except (LookupError, ImportError) as e: raise RuntimeError("Unable to load %(app_name)s from " "configuration file %(conf_file)s." "\nGot: %(e)r" % locals()) diff --git a/heat/common/exception.py b/heat/common/exception.py index 00383559..875b4287 100644 --- a/heat/common/exception.py +++ b/heat/common/exception.py @@ -54,7 +54,7 @@ def wrap_exception(notifier=None, publisher_id=None, event_type=None, def wrapped(*args, **kw): try: return f(*args, **kw) - except Exception, e: + except Exception as e: # Save exception since it can be clobbered during processing # below before we can re-raise exc_info = sys.exc_info() diff --git a/heat/common/wsgi.py b/heat/common/wsgi.py index 7ce8d7a8..75c79039 100644 --- a/heat/common/wsgi.py +++ b/heat/common/wsgi.py @@ -124,7 +124,7 @@ def get_socket(conf, default_port): if use_ssl: sock = ssl.wrap_socket(sock, certfile=cert_file, keyfile=key_file) - except socket.error, err: + except socket.error as err: if err.args[0] != errno.EADDRINUSE: raise eventlet.sleep(0.1) @@ -199,7 +199,7 @@ class Server(object): self.logger.error(_('Removing dead child %s') % pid) self.children.remove(pid) self.run_child() - except OSError, err: + except OSError as err: if err.errno not in (errno.EINTR, errno.ECHILD): raise except KeyboardInterrupt: @@ -244,7 +244,7 @@ class Server(object): custom_pool=self.pool, url_length_limit=URL_LENGTH_LIMIT, log=WritableLogger(self.logger)) - except socket.error, err: + except socket.error as err: if err[0] != errno.EINVAL: raise self.pool.waitall() diff --git a/heat/db/sqlalchemy/models.py b/heat/db/sqlalchemy/models.py index 3392d3c1..a929604a 100644 --- a/heat/db/sqlalchemy/models.py +++ b/heat/db/sqlalchemy/models.py @@ -55,7 +55,7 @@ class HeatBase(object): session.add(self) try: session.flush() - except IntegrityError, e: + except IntegrityError as e: if str(e).endswith('is not unique'): raise exception.Duplicate(str(e)) else: diff --git a/heat/db/sqlalchemy/session.py b/heat/db/sqlalchemy/session.py index 7764c0f8..be1677bd 100644 --- a/heat/db/sqlalchemy/session.py +++ b/heat/db/sqlalchemy/session.py @@ -58,7 +58,7 @@ class MySQLPingListener(object): def checkout(self, dbapi_con, con_record, con_proxy): try: dbapi_con.cursor().execute('select 1') - except dbapi_con.OperationalError, ex: + except dbapi_con.OperationalError as ex: if ex.args[0] in (2006, 2013, 2014, 2045, 2055): logger.warn('Got mysql server has gone away: %s', ex) raise DisconnectionError("Database server went away") diff --git a/heat/tests/functional/util.py b/heat/tests/functional/util.py index 73dc024c..48a3da9a 100644 --- a/heat/tests/functional/util.py +++ b/heat/tests/functional/util.py @@ -141,7 +141,7 @@ class Instance(object): while True: try: self.sftp.stat('/var/lib/heat-cfntools/boot-finished') - except IOError, e: + except IOError as e: tries += 1 if e.errno == errno.ENOENT: self.testcase.assertTrue(tries < 50, 'Timed out') diff --git a/tools/hacking.py b/tools/hacking.py index 8b7d919a..c6c4afc4 100755 --- a/tools/hacking.py +++ b/tools/hacking.py @@ -201,7 +201,7 @@ def nova_import_rules(logical_line): try: # NOTE(vish): handle namespace modules module = __import__(mod) - except ImportError, exc: + except ImportError as exc: # NOTE(vish): the import error might be due # to a missing dependency missing = str(exc).split()[-1] -- 2.45.2