[libvirt-python 3/3] Update exception catching in generated code

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Use a syntax for exception handling that works in both Python 2 and
Python 3. The new syntax is 'except Exception as e:' but this does not
work in older Pythons so we use the most compatible way by just catching
the exception and getting the type and the exception value after the
fact.
---
 generator.py | 12 ++++++++----
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/generator.py b/generator.py
index 009d3e1..214abed 100755
--- a/generator.py
+++ b/generator.py
@@ -1822,10 +1822,12 @@ def qemuBuildWrappers(module):
 
     fd.write("try:\n")
     fd.write("    import libvirtmod_qemu\n")
-    fd.write("except ImportError, lib_e:\n")
+    fd.write("except ImportError:\n")
+    fd.write("    lib_e = sys.exc_info()[1]\n")
     fd.write("    try:\n")
     fd.write("        import cygvirtmod_qemu as libvirtmod_qemu\n")
-    fd.write("    except ImportError, cyg_e:\n")
+    fd.write("    except ImportError:\n")
+    fd.write("        cyg_e = sys.exc_info()[1]\n")
     fd.write("        if str(cyg_e).count(\"No module named\"):\n")
     fd.write("            raise lib_e\n\n")
 
@@ -1933,10 +1935,12 @@ def lxcBuildWrappers(module):
 
     fd.write("try:\n")
     fd.write("    import libvirtmod_lxc\n")
-    fd.write("except ImportError, lib_e:\n")
+    fd.write("except ImportError:\n")
+    fd.write("    lib_e = sys.exc_info()[1]\n")
     fd.write("    try:\n")
     fd.write("        import cygvirtmod_lxc as libvirtmod_lxc\n")
-    fd.write("    except ImportError, cyg_e:\n")
+    fd.write("    except ImportError:\n")
+    fd.write("        cyg_e = sys.exc_info()[1]\n")
     fd.write("        if str(cyg_e).count(\"No module named\"):\n")
     fd.write("            raise lib_e\n\n")
 
-- 
1.8.3.2

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list




[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]