From 4fe73f515d51a68bc4d46b145713aa6661c30de4 Mon Sep 17 00:00:00 2001 From: Sun Austin Date: Mon, 15 Oct 2018 14:41:06 +0800 Subject: [PATCH] Fix: "except" issues for Python 2/3 compatible code. change "except ValueError, e:" to "except ValueError as e:" and remove tox H231 from ignore for pep8 check Story:2003430 Task: 26522 Change-Id: I06c7646c375ada7f8f06f870a7bdb0d7fc282e5a Signed-off-by: Sun Austin --- service-mgmt-api/sm-api/sm_api/api/controllers/v1/smc_api.py | 2 +- service-mgmt-api/sm-api/sm_api/common/utils.py | 2 +- .../sm-api/sm_api/openstack/common/processutils.py | 2 +- service-mgmt-tools/sm-tools/sm_tools/sm_api_msg_utils.py | 2 +- tox.ini | 3 +-- 5 files changed, 5 insertions(+), 6 deletions(-) diff --git a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/smc_api.py b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/smc_api.py index d406bf8d..b9bdaa8d 100755 --- a/service-mgmt-api/sm-api/sm_api/api/controllers/v1/smc_api.py +++ b/service-mgmt-api/sm-api/sm_api/api/controllers/v1/smc_api.py @@ -94,7 +94,7 @@ def sm_api_notify(sm_dict): except: LOG.exception(_("sm-api bad rx message: %s" % sm_ack)) - except socket.error, e: + except socket.error as e: LOG.exception(_("sm-api socket error: %s on %s") % (e, sm_buf)) sm_ack_dict = { 'SM_API_MSG_TYPE': "unknown_set_node", diff --git a/service-mgmt-api/sm-api/sm_api/common/utils.py b/service-mgmt-api/sm-api/sm_api/common/utils.py index f9adccdb..e31c97ba 100644 --- a/service-mgmt-api/sm-api/sm_api/common/utils.py +++ b/service-mgmt-api/sm-api/sm_api/common/utils.py @@ -663,7 +663,7 @@ def notify_mtc_and_recv(mtc_address, mtc_port, idict): LOG.exception("Mtc Response Error: %s" % mtc_response) pass - except socket.error, e: + except socket.error as e: LOG.exception(_("Socket Error: %s on %s:%s for %s") % (e, mtc_address, mtc_port, serialized_idict)) # if e not in [errno.EWOULDBLOCK, errno.EINTR]: diff --git a/service-mgmt-api/sm-api/sm_api/openstack/common/processutils.py b/service-mgmt-api/sm-api/sm_api/openstack/common/processutils.py index 86a29d03..ef4a0cd1 100644 --- a/service-mgmt-api/sm-api/sm_api/openstack/common/processutils.py +++ b/service-mgmt-api/sm-api/sm_api/openstack/common/processutils.py @@ -207,7 +207,7 @@ def trycmd(*args, **kwargs): try: out, err = execute(*args, **kwargs) failed = False - except ProcessExecutionError, exn: + except ProcessExecutionError as exn: out, err = '', str(exn) failed = True diff --git a/service-mgmt-tools/sm-tools/sm_tools/sm_api_msg_utils.py b/service-mgmt-tools/sm-tools/sm_tools/sm_api_msg_utils.py index 031718e3..84d1dd0b 100644 --- a/service-mgmt-tools/sm-tools/sm_tools/sm_api_msg_utils.py +++ b/service-mgmt-tools/sm-tools/sm_tools/sm_api_msg_utils.py @@ -39,7 +39,7 @@ def _send_msg_to_sm(sm_api_msg): s.sendto(sm_api_msg, SM_API_SERVER_ADDR) time.sleep(1) - except socket.error, e: + except socket.error as e: print("sm-api socket error: %s on %s" % (e, sm_api_msg)) diff --git a/tox.ini b/tox.ini index 77a29d1f..e0ac16f6 100644 --- a/tox.ini +++ b/tox.ini @@ -84,7 +84,6 @@ commands = # H104: File contains nothing but comments # H105: Don't use author tags # H201: no 'except:' -# H231: Python 3.x incompatible 'except x,y:' construct # H233: Python 3.x incompatible use of print operator # H236: Python 3.x incompatible __metaclass__, use six.add_metaclass() # H306: imports not in alphabetical order @@ -109,7 +108,7 @@ commands = # B306 `BaseException.message` has been deprecated as of Python 2.6 and is removed in Python 3. ignore= E114,E116,E121,E122,E123,E124,E125,E126,E127,E128,E129,E131,E201,E228,E231,E241,E251,E265,E271, E302,E303,E305,E402,E713,E714,E722,E731,E999, - H102,H104,H105,H106,H201,H231,H233,H236,H306,H401,H403,H404,H405,H501, + H102,H104,H105,H106,H201,H233,H236,H306,H401,H403,H404,H405,H501, F401,F811,F821,F841, B001,B004,B006,B007,B008,B303,B305,B306 # Enable checks which are off by default