Python 3 no longer accepts 'except Exception, e:' as valid while Python
2.4 does not accept the new syntax 'except Exception as e:' so this uses
a fall back method that is compatible with both.
---
libvirt-override-virStream.py | 3 ++-
libvirt-override.py | 8 ++++++--
2 files changed, 8 insertions(+), 3 deletions(-)
diff --git a/libvirt-override-virStream.py b/libvirt-override-virStream.py
index 53000da..189d062 100644
--- a/libvirt-override-virStream.py
+++ b/libvirt-override-virStream.py
@@ -50,7 +50,8 @@
ret = handler(self, got, opaque)
if type(ret) is int and ret < 0:
raise RuntimeError("recvAll handler returned %d" % ret)
- except Exception, e:
+ except Exception:
+ e = sys.exc_info()[1]
try:
self.abort()
except:
diff --git a/libvirt-override.py b/libvirt-override.py
index 87996f8..63f8ecb 100644
--- a/libvirt-override.py
+++ b/libvirt-override.py
@@ -3,12 +3,16 @@
#
# On cygwin, the DLL is called cygvirtmod.dll
+import sys
+
try:
import libvirtmod
-except ImportError, lib_e:
+except ImportError:
+ lib_e = sys.exc_info()[1]
try:
import cygvirtmod as libvirtmod
- except ImportError, cyg_e:
+ except ImportError:
+ cyg_e = sys.exc_info()[1]
if str(cyg_e).count("No module named"):
raise lib_e
--
1.8.3.2
Show replies by date
The 'print' statement no longer exists in Python 3 and now must be
called as a function. This is compatible down to Python 2.4 as we are
not using any special syntax of the function.
---
sanitytest.py | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)
diff --git a/sanitytest.py b/sanitytest.py
index 7346d7b..bd93fe6 100644
--- a/sanitytest.py
+++ b/sanitytest.py
@@ -232,9 +232,9 @@ for name in sorted(finalklassmap):
if func in gotfunctions[klass]:
usedfunctions["%s.%s" % (klass, func)] = 1
if verbose:
- print "PASS %s -> %s.%s" % (name, klass, func)
+ print("PASS %s -> %s.%s" % (name, klass, func))
else:
- print "FAIL %s -> %s.%s (C API not mapped to python)" % (name,
klass, func)
+ print("FAIL %s -> %s.%s (C API not mapped to python)" % (name,
klass, func))
fail = True
@@ -249,11 +249,11 @@ for klass in gotfunctions:
key = "%s.%s" % (klass, func)
if not key in usedfunctions:
- print "FAIL %s.%s (Python API not mapped to C)" % (klass,
func)
+ print("FAIL %s.%s (Python API not mapped to C)" % (klass,
func))
fail = True
else:
if verbose:
- print "PASS %s.%s" % (klass, func)
+ print("PASS %s.%s" % (klass, func))
# Phase 7: Validate that all the low level C APIs have binding
for name in sorted(finalklassmap):
@@ -273,7 +273,7 @@ for name in sorted(finalklassmap):
try:
thing = getattr(libvirt.libvirtmod, pyname)
except AttributeError:
- print "FAIL libvirt.libvirtmod.%s (C binding does not exist)" %
pyname
+ print("FAIL libvirt.libvirtmod.%s (C binding does not exist)" %
pyname)
fail = True
if fail:
--
1.8.3.2