Skip to content

Commit

Permalink
python: Fix exception handler compatibility.
Browse files Browse the repository at this point in the history
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 <[email protected]>
Acked-by: Ben Pfaff <[email protected]>
  • Loading branch information
russellb committed Jan 12, 2016
1 parent 66d61c9 commit f3068bf
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 20 deletions.
27 changes: 16 additions & 11 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -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 <name> from line <N> (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 <name> from line <N> (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
Expand Down
2 changes: 1 addition & 1 deletion debian/ovs-monitor-ipsec
Original file line number Diff line number Diff line change
Expand Up @@ -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))


Expand Down
2 changes: 1 addition & 1 deletion ofproto/ipfix-gen-entities
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion tests/test-json.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions tests/test-ovsdb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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")


Expand Down Expand Up @@ -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)

Expand Down Expand Up @@ -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)
4 changes: 2 additions & 2 deletions utilities/ovs-pcap.in
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 1 addition & 1 deletion xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit f3068bf

Please sign in to comment.