[libvirt] [libvirt-python][PATCH] generator: fix build fail with old xml lib

Luyao Huang lhuang at redhat.com
Wed Sep 2 05:58:00 UTC 2015


if build libvirt-python with some old xml lib (python-pyxml),
build will fail and error like this:

      File "generator.py", line 139, in start
        if "string" in attrs:
      File "/usr/local/lib/python2.7/site-packages/_xmlplus/sax/xmlreader.py" \
        , line 316, in __getitem__
        return self._attrs[name]
    KeyError: 0

This is an old issue and have been mentioned in commit 3ae0a76d.
There is no __contains__ in class AttributesImpl, python will use
__getitem__ in this place, so we will get error.
Let's use 'YYY in XXX.keys()' to avoid this issue.

Signed-off-by: Luyao Huang <lhuang at redhat.com>
 generator.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/generator.py b/generator.py
index 2fc838c..d9ae17e 100755
--- a/generator.py
+++ b/generator.py
@@ -136,7 +136,7 @@ class docParser(xml.sax.handler.ContentHandler):
             elif attrs['file'] == "libvirt-qemu":
         elif tag == "macro":
-            if "string" in attrs:
+            if "string" in attrs.keys():
                 params.append((attrs['name'], attrs['string']))
     def end(self, tag):

More information about the libvir-list mailing list