From f3068bff92dc4fb76ee4aab149990f2492bcbc24 Mon Sep 17 00:00:00 2001 From: Russell Bryant Date: Wed, 6 Jan 2016 13:48:16 -0500 Subject: [PATCH] python: Fix exception handler compatibility. Python 3 dropped exception handlers of the deprecated form: except Exception, e: You must use the newer syntax of: except Exception as e: This patch also enables a flake8 warning for this. H231 Python 3.x incompatible 'except x,y:' construct Signed-off-by: Russell Bryant Acked-by: Ben Pfaff --- Makefile.am | 27 +++++++++++-------- debian/ovs-monitor-ipsec | 2 +- ofproto/ipfix-gen-entities | 2 +- tests/test-json.py | 2 +- tests/test-ovsdb.py | 6 ++--- utilities/ovs-pcap.in | 4 +-- ...sr_share_openvswitch_scripts_ovs-xapi-sync | 2 +- 7 files changed, 25 insertions(+), 20 deletions(-) diff --git a/Makefile.am b/Makefile.am index 253753250..615d45694 100644 --- a/Makefile.am +++ b/Makefile.am @@ -343,20 +343,25 @@ endif if HAVE_FLAKE8 ALL_LOCAL += flake8-check # http://flake8.readthedocs.org/en/latest/warnings.html -# E121 continuation line under-indented for hanging indent (only from flake8 v2.0) -# E123 closing bracket does not match indentation of opening bracket's line -# E125 continuation line with same indent as next logical line (only from flake8 v2.0) -# E126 continuation line over-indented for hanging indent -# E127 continuation line over-indented for visual indent -# E128 continuation line under-indented for visual indent -# E129 visually indented line with same indent as next logical line -# E131 continuation line unaligned for hanging indent -# F811 redefinition of unused from line (only from flake8 v2.0) -# W503 line break before binary operator +# All warnings explicitly selected or ignored should be listed below. +# +# E***, W*** -- warnings from pep8 +# E121 continuation line under-indented for hanging indent (only from flake8 v2.0) +# E123 closing bracket does not match indentation of opening bracket's line +# E125 continuation line with same indent as next logical line (only from flake8 v2.0) +# E126 continuation line over-indented for hanging indent +# E127 continuation line over-indented for visual indent +# E128 continuation line under-indented for visual indent +# E129 visually indented line with same indent as next logical line +# E131 continuation line unaligned for hanging indent +# W503 line break before binary operator +# F*** -- warnings native to flake8 +# F811 redefinition of unused from line (only from flake8 v2.0) # D*** -- warnings from flake8-docstrings plugin # H*** -- warnings from flake8 hacking plugin (custom style checks beyond PEP8) +# H231 Python 3.x incompatible 'except x,y:' construct flake8-check: $(FLAKE8_PYFILES) - $(AM_V_GEN) if flake8 $^ --ignore=E121,E123,E125,E126,E127,E128,E129,E131,F811,W503,D,H ${FLAKE8_FLAGS}; then touch $@; else exit 1; fi + $(AM_V_GEN) if flake8 $^ --select=H231 --ignore=E121,E123,E125,E126,E127,E128,E129,E131,W503,F811,D,H ${FLAKE8_FLAGS}; then touch $@; else exit 1; fi endif include $(srcdir)/manpages.mk diff --git a/debian/ovs-monitor-ipsec b/debian/ovs-monitor-ipsec index e79c7554d..efab91bdd 100755 --- a/debian/ovs-monitor-ipsec +++ b/debian/ovs-monitor-ipsec @@ -371,7 +371,7 @@ def update_ipsec(ipsec, interfaces, new_interfaces): try: ipsec.add_entry(vals["local_ip"], vals["remote_ip"], vals) - except error.Error, msg: + except error.Error as msg: vlog.warn("skipping ipsec config for %s: %s" % (name, msg)) diff --git a/ofproto/ipfix-gen-entities b/ofproto/ipfix-gen-entities index 11d2aaf9a..54951b63d 100755 --- a/ofproto/ipfix-gen-entities +++ b/ofproto/ipfix-gen-entities @@ -114,7 +114,7 @@ if __name__ == '__main__': try: options, args = getopt.gnu_getopt(sys.argv[1:], 'hV', ['help', 'version']) - except getopt.GetoptError, geo: + except getopt.GetoptError as geo: sys.stderr.write('%s: %s\n' % (sys.argv[0], geo.msg)) sys.exit(1) diff --git a/tests/test-json.py b/tests/test-json.py index d9f0bfe6d..13561458e 100644 --- a/tests/test-json.py +++ b/tests/test-json.py @@ -61,7 +61,7 @@ def main(argv): try: options, args = getopt.gnu_getopt(argv[1:], '', ['multiple']) - except getopt.GetoptError, geo: + except getopt.GetoptError as geo: sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) sys.exit(1) diff --git a/tests/test-ovsdb.py b/tests/test-ovsdb.py index e240208d4..5744fde00 100644 --- a/tests/test-ovsdb.py +++ b/tests/test-ovsdb.py @@ -105,7 +105,7 @@ def do_parse_atoms(type_string, *atom_strings): try: atom = data.Atom.from_json(base, atom_json) print ovs.json.to_string(atom.to_json()) - except error.Error, e: + except error.Error as e: print e.args[0].encode("utf8") @@ -548,7 +548,7 @@ def main(argv): options, args = getopt.gnu_getopt(argv[1:], 't:h', ['timeout', 'help']) - except getopt.GetoptError, geo: + except getopt.GetoptError as geo: sys.stderr.write("%s: %s\n" % (ovs.util.PROGRAM_NAME, geo.msg)) sys.exit(1) @@ -617,6 +617,6 @@ def main(argv): if __name__ == '__main__': try: main(sys.argv) - except error.Error, e: + except error.Error as e: sys.stderr.write("%s\n" % e) sys.exit(1) diff --git a/utilities/ovs-pcap.in b/utilities/ovs-pcap.in index 5253c3157..ed35fc5de 100755 --- a/utilities/ovs-pcap.in +++ b/utilities/ovs-pcap.in @@ -73,7 +73,7 @@ if __name__ == "__main__": try: options, args = getopt.gnu_getopt(sys.argv[1:], 'hV', ['help', 'version']) - except getopt.GetoptException, geo: + except getopt.GetoptException as geo: sys.stderr.write("%s: %s\n" % (argv0, geo.msg)) sys.exit(1) @@ -98,7 +98,7 @@ if __name__ == "__main__": print binascii.hexlify(packet) - except PcapException, e: + except PcapException as e: sys.stderr.write("%s: %s\n" % (argv0, e)) sys.exit(1) diff --git a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync index f6fbe851b..bed80843c 100755 --- a/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync +++ b/xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync @@ -67,7 +67,7 @@ def init_session(): try: session = XenAPI.xapi_local() session.xenapi.login_with_password("", "") - except XenAPI.Failure, e: + except XenAPI.Failure as e: session = None vlog.warn("Couldn't login to XAPI (%s)" % e) return False -- 2.20.1