Skip to contentSkip to conversation

Use Python 2.6 "except E as ..." syntax

PATCH Superseded Markus Armbruster 4 participants 15 messages Dec 17, 2015 – Dec 18, 2015

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

cover Use Python 2.6 "except E as ..." syntax

I can take this through my tree, but of course don't mind if a maintainer prefers to pick up "his" parts.

Markus Armbruster (4):
qapi: Use Python 2.6 "except E as ..." syntax scripts/qmp: Use Python 2.6 "except E as ..." syntax Revert "tracetool: use Python 2.4-compatible exception handling
syntax"
tests: Use Python 2.6 "except E as ..." syntax

 scripts/qapi.py              |  8 ++++----
 scripts/qmp/qemu-ga-client   |  2 +-
 scripts/qmp/qmp              |  4 ++--
 scripts/qmp/qmp-shell        |  2 +-
 scripts/qmp/qmp.py           |  4 ++--
 scripts/tracetool.py         |  4 ++--
 tests/image-fuzzer/runner.py | 12 ++++++------
 tests/qemu-iotests/qed.py    |  2 +-
 8 files changed, 19 insertions(+), 19 deletions(-)
Signature · 1 line
2.4.3
#1 lore raw

PATCH 1/4 qapi: Use Python 2.6 "except E as ..." syntax

PEP 8 calls for it, because it's forward compatibile with Python 3.

---
 scripts/qapi.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
scripts/qapi.py +4 -4
index 7c50cc4..ba7151b 100644
@@ -152,7 +152,7 @@ class QAPISchemaParser(object):
                     continue
                 try:
                     fobj = open(incl_abs_fname, 'r')
-                except IOError, e:
+                except IOError as e:
                     raise QAPIExprError(expr_info,
                                         '%s: %s' % (e.strerror, include))
                 exprs_include = QAPISchemaParser(fobj, previously_included,
@@ -1148,7 +1148,7 @@ class QAPISchema(object):
             self._predefining = False
             self._def_exprs()
             self.check()
-        except (QAPISchemaError, QAPIExprError), err:
+        except (QAPISchemaError, QAPIExprError) as err:
             print >>sys.stderr, err
             exit(1)
 
@@ -1639,7 +1639,7 @@ def parse_command_line(extra_options="", extra_long_options=[]):
                                        "chp:o:" + extra_options,
                                        ["source", "header", "prefix=",
                                         "output-dir="] + extra_long_options)
-    except getopt.GetoptError, err:
+    except getopt.GetoptError as err:
         print >>sys.stderr, "%s: %s" % (sys.argv[0], str(err))
         sys.exit(1)
 
@@ -1693,7 +1693,7 @@ def open_output(output_dir, do_c, do_h, prefix, c_file, h_file,
     if output_dir:
         try:
             os.makedirs(output_dir)
-        except os.error, e:
+        except os.error as e:
             if e.errno != errno.EEXIST:
                 raise
 
Signature · 1 line
2.4.3
Reviewed-by on v1 1/4
#2 lore raw

Re: [Qemu-devel] [PATCH 1/4] qapi: Use Python 2.6 "except E as ..." syntax

Quoted 1 line · Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

And possible as a cleanup only because we require 2.6 as a minimum since fec21036 (your subject line hints at it, even if not stating it outright).

Quoted 5 lines
---
 scripts/qapi.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#3 lore raw

Re: [Qemu-devel] [PATCH 1/4] qapi: Use Python 2.6 "except E as ..." syntax

Quoted 5 lines · Eric Blake
Quoted 1 line · Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

And possible as a cleanup only because we require 2.6 as a minimum since fec21036 (your subject line hints at it, even if not stating it outright).

What about:

Supported since Python 2.6, which we require (commit fec2103).

Quoted 7 lines
Quoted 5 lines
---
 scripts/qapi.py | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

Thanks!

#4 lore raw

Re: [Qemu-devel] [PATCH 1/4] qapi: Use Python 2.6 "except E as ..." syntax

Quoted 11 lines · Markus Armbruster
Quoted 5 lines · Eric Blake
Quoted 1 line · Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

And possible as a cleanup only because we require 2.6 as a minimum since fec21036 (your subject line hints at it, even if not stating it outright).

What about:

Supported since Python 2.6, which we require (commit fec2103).

Sounds good. Looks like you can pretty much copy/paste that into 1, 2, and 4.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#5 lore raw

Re: [Qemu-devel] [PATCH 1/4] qapi: Use Python 2.6 "except E as ..." syntax

In reply to Markus Armbruster
Quoted 1 line · Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

Typo nit: "compatible".

thanks
-- PMM

#6 lore raw

PATCH 2/4 scripts/qmp: Use Python 2.6 "except E as ..." syntax

In reply to Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

---
 scripts/qmp/qemu-ga-client | 2 +-
 scripts/qmp/qmp            | 4 ++--
 scripts/qmp/qmp-shell      | 2 +-
 scripts/qmp/qmp.py         | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)
scripts/qmp/qemu-ga-client +1 -1
index 9908f21..fd05605 100755
@@ -259,7 +259,7 @@ def main(address, cmd, args):
 
     try:
         client = QemuGuestAgentClient(address)
-    except QemuGuestAgent.error, e:
+    except QemuGuestAgent.error as e:
         import errno
 
         print(e)
scripts/qmp/qmp +2 -2
index 1db3c7f..514b539 100755
@@ -91,8 +91,8 @@ def main(args):
         try:
             os.environ['QMP_PATH'] = path
             os.execvp(fullcmd, [fullcmd] + args)
-        except OSError, (errno, msg):
-            if errno == 2:
+        except OSError as exc:
+            if exc.errno == 2:
                 print 'Command "%s" not found.' % (fullcmd)
                 return 1
             raise
scripts/qmp/qmp-shell +1 -1
index fa39bf0..7a402ed 100755
@@ -240,7 +240,7 @@ class QMPShell(qmp.QEMUMonitorProtocol):
     def _execute_cmd(self, cmdline):
         try:
             qmpcmd = self.__build_cmd(cmdline)
-        except Exception, e:
+        except Exception as e:
             print 'Error while parsing command line: %s' % e
             print 'command format: <command-name> ',
             print '[arg-name1=arg1] ... [arg-nameN=argN]'
scripts/qmp/qmp.py +2 -2
index 1d38e3e..779332f 100644
@@ -92,7 +92,7 @@ class QEMUMonitorProtocol:
         self.__sock.setblocking(0)
         try:
             self.__json_read()
-        except socket.error, err:
+        except socket.error as err:
             if err[0] == errno.EAGAIN:
                 # No data available
                 pass
@@ -150,7 +150,7 @@ class QEMUMonitorProtocol:
         """
         try:
             self.__sock.sendall(json.dumps(qmp_cmd))
-        except socket.error, err:
+        except socket.error as err:
             if err[0] == errno.EPIPE:
                 return
             raise socket.error(err)
Signature · 1 line
2.4.3
Reviewed-by on v1 2/4
#7 lore raw

Re: [Qemu-devel] [PATCH 2/4] scripts/qmp: Use Python 2.6 "except E as ..." syntax

Quoted 1 line · Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

Here, and also in 1/4,

s/compatibile/compatible/

Quoted 8 lines
---
 scripts/qmp/qemu-ga-client | 2 +-
 scripts/qmp/qmp            | 4 ++--
 scripts/qmp/qmp-shell      | 2 +-
 scripts/qmp/qmp.py         | 4 ++--
 4 files changed, 6 insertions(+), 6 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#8 lore raw

PATCH 3/4 Revert "tracetool: use Python 2.4-compatible exception handling syntax"

In reply to Markus Armbruster

This reverts commit 662da3854e3f490223373b40afdcfcc339d14aa5.

---
 scripts/tracetool.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
scripts/tracetool.py +2 -2
index 83bde7b..7b82959 100755
@@ -71,7 +71,7 @@ def main(args):
 
     try:
         opts, args = getopt.getopt(args[1:], "", long_opts)
-    except getopt.GetoptError, err:
+    except getopt.GetoptError as err:
         error_opt(str(err))
 
     check_backends = False
@@ -132,7 +132,7 @@ def main(args):
     try:
         tracetool.generate(sys.stdin, arg_format, arg_backends,
                            binary=binary, probe_prefix=probe_prefix)
-    except tracetool.TracetoolError, e:
+    except tracetool.TracetoolError as e:
         error_opt(str(e))
 
 if __name__ == "__main__":
Signature · 1 line
2.4.3
Reviewed-by on v1 3/4
#9 lore raw

Re: [Qemu-devel] [PATCH 3/4] Revert "tracetool: use Python 2.4-compatible exception handling syntax"

Quoted 6 lines · Markus Armbruster

This reverts commit 662da3854e3f490223373b40afdcfcc339d14aa5.

---
 scripts/tracetool.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Might be nice to mention fec21036 as the reason why we can revert.

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#10 lore raw

Re: [Qemu-devel] [PATCH 3/4] Revert "tracetool: use Python 2.4-compatible exception handling syntax"

Quoted 9 lines · Eric Blake
Quoted 6 lines · Markus Armbruster

This reverts commit 662da3854e3f490223373b40afdcfcc339d14aa5.

---
 scripts/tracetool.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

Might be nice to mention fec21036 as the reason why we can revert.

What about:

We require Python 2.6 now (commit fec2103).

Quoted 1 line

Thanks!

#11 lore raw

Re: [Qemu-devel] [PATCH 3/4] Revert "tracetool: use Python 2.4-compatible exception handling syntax"

Quoted 10 lines · Markus Armbruster
Quoted 8 lines · Eric Blake
Quoted 6 lines · Markus Armbruster

This reverts commit 662da3854e3f490223373b40afdcfcc339d14aa5.

---
 scripts/tracetool.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
Quoted 5 lines
Quoted 1 line

Might be nice to mention fec21036 as the reason why we can revert.

What about:

We require Python 2.6 now (commit fec2103).

Yes, that makes this commit a lot more meaningful.

Quoted 5 lines
Quoted 2 lines

Thanks!

Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
#12 lore raw

PATCH 4/4 tests: Use Python 2.6 "except E as ..." syntax

In reply to Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

---
 tests/image-fuzzer/runner.py | 12 ++++++------
 tests/qemu-iotests/qed.py    |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
tests/image-fuzzer/runner.py +6 -6
index be7e283..96a1c11 100755
@@ -157,7 +157,7 @@ class TestEnv(object):
 
         try:
             os.makedirs(self.current_dir)
-        except OSError, e:
+        except OSError as e:
             print >>sys.stderr, \
                 "Error: The working directory '%s' cannot be used. Reason: %s"\
                 % (self.work_dir, e[1])
@@ -244,7 +244,7 @@ class TestEnv(object):
             temp_log = StringIO.StringIO()
             try:
                 retcode = run_app(temp_log, current_cmd)
-            except OSError, e:
+            except OSError as e:
                 multilog("%sError: Start of '%s' failed. Reason: %s\n\n"
                          % (test_summary, os.path.basename(current_cmd[0]),
                             e[1]),
@@ -356,7 +356,7 @@ if __name__ == '__main__':
         opts, args = getopt.gnu_getopt(sys.argv[1:], 'c:hs:kvd:',
                                        ['command=', 'help', 'seed=', 'config=',
                                         'keep_passed', 'verbose', 'duration='])
-    except getopt.error, e:
+    except getopt.error as e:
         print >>sys.stderr, \
             "Error: %s\n\nTry 'runner.py --help' for more information" % e
         sys.exit(1)
@@ -374,7 +374,7 @@ if __name__ == '__main__':
         elif opt in ('-c', '--command'):
             try:
                 command = json.loads(arg)
-            except (TypeError, ValueError, NameError), e:
+            except (TypeError, ValueError, NameError) as e:
                 print >>sys.stderr, \
                     "Error: JSON array of test commands cannot be loaded.\n" \
                     "Reason: %s" % e
@@ -390,7 +390,7 @@ if __name__ == '__main__':
         elif opt == '--config':
             try:
                 config = json.loads(arg)
-            except (TypeError, ValueError, NameError), e:
+            except (TypeError, ValueError, NameError) as e:
                 print >>sys.stderr, \
                     "Error: JSON array with the fuzzer configuration cannot" \
                     " be loaded\nReason: %s" % e
@@ -414,7 +414,7 @@ if __name__ == '__main__':
 
     try:
         image_generator = __import__(generator_name)
-    except ImportError, e:
+    except ImportError as e:
         print >>sys.stderr, \
             "Error: The image generator '%s' cannot be imported.\n" \
             "Reason: %s" % (generator_name, e)
tests/qemu-iotests/qed.py +1 -1
index 52ff845..748068d 100755
@@ -227,7 +227,7 @@ def main():
     qed = QED(open(filename, 'r+b'))
     try:
         globals()[cmd](qed, *sys.argv[3:])
-    except TypeError, e:
+    except TypeError as e:
         sys.stderr.write(globals()[cmd].__doc__ + '\n')
         sys.exit(1)
 
Signature · 1 line
2.4.3
Reviewed-by on v1 4/4
#13 lore raw

Re: [Qemu-devel] [PATCH 4/4] tests: Use Python 2.6 "except E as ..." syntax

Quoted 1 line · Markus Armbruster

PEP 8 calls for it, because it's forward compatibile with Python 3.

Another s/compatibile/compatible/

Quoted 6 lines
---
 tests/image-fuzzer/runner.py | 12 ++++++------
 tests/qemu-iotests/qed.py    |  2 +-
 2 files changed, 7 insertions(+), 7 deletions(-)
Signature · 2 lines
Eric Blake   eblake redhat com    +1-919-301-3266
Libvirt virtualization library http://libvirt.org
Acked-by on the v1 series
#14 lore raw
In reply to Markus Armbruster
Quoted 10 lines · Markus Armbruster

I can take this through my tree, but of course don't mind if a maintainer prefers to pick up "his" parts.

Markus Armbruster (4):
qapi: Use Python 2.6 "except E as ..." syntax scripts/qmp: Use Python 2.6 "except E as ..." syntax Revert "tracetool: use Python 2.4-compatible exception handling
syntax"
tests: Use Python 2.6 "except E as ..." syntax

Quoted 13 lines
 scripts/qapi.py              |  8 ++++----
 scripts/qmp/qemu-ga-client   |  2 +-
 scripts/qmp/qmp              |  4 ++--
 scripts/qmp/qmp-shell        |  2 +-
 scripts/qmp/qmp.py           |  4 ++--
 scripts/tracetool.py         |  4 ++--
 tests/image-fuzzer/runner.py | 12 ++++++------
 tests/qemu-iotests/qed.py    |  2 +-
 8 files changed, 19 insertions(+), 19 deletions(-)
Signature · 1 line
2.4.3