python: Fix exception handler compatibility.
authorRussell Bryant <russell@ovn.org>
Wed, 6 Jan 2016 18:48:16 +0000 (13:48 -0500)
committerRussell Bryant <russell@ovn.org>
Tue, 12 Jan 2016 16:47:33 +0000 (11:47 -0500)
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 <russell@ovn.org>
Acked-by: Ben Pfaff <blp@ovn.org>
Makefile.am
debian/ovs-monitor-ipsec
ofproto/ipfix-gen-entities
tests/test-json.py
tests/test-ovsdb.py
utilities/ovs-pcap.in
xenserver/usr_share_openvswitch_scripts_ovs-xapi-sync

index 2537532..615d456 100644 (file)
@@ -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
index e79c755..efab91b 100755 (executable)
@@ -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))
 
 
index 11d2aaf..54951b6 100755 (executable)
@@ -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)
 
index d9f0bfe..1356145 100644 (file)
@@ -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)
 
index e240208..5744fde 100644 (file)
@@ -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)
index 5253c31..ed35fc5 100755 (executable)
@@ -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)
 
index f6fbe85..bed8084 100755 (executable)
@@ -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