diff options
author | David Sommerseth <davids@redhat.com> | 2009-06-15 11:11:55 +0200 |
---|---|---|
committer | David Sommerseth <davids@redhat.com> | 2009-06-15 11:11:55 +0200 |
commit | e9a6b7f9ec31c1227be982fb8f2bb0ee8bf97710 (patch) | |
tree | 9f0a44c510c52908ba1a6fad3bec5b17a88b2cb3 /src/xmlpythonizer.c | |
parent | 20030e42b4d3f7283f6143641cb009a8dbf1da24 (diff) | |
download | python-dmidecode-e9a6b7f9ec31c1227be982fb8f2bb0ee8bf97710.tar.gz python-dmidecode-e9a6b7f9ec31c1227be982fb8f2bb0ee8bf97710.tar.xz python-dmidecode-e9a6b7f9ec31c1227be982fb8f2bb0ee8bf97710.zip |
Fixed wrong behavivour in pythonizeXMLnode() when no key value is found
If the XPath expression for the key value points on a non-existing XML
node, it would earlier abort pythonizing the XML data. Even though this
could look like the correct behaviour, it will not work out well in
reality.
For sections like 'bios', it might be that the DMI/SMBIOS data do not
describe or provide the BIOSLanguage section (type id 0x0D). Which
means calling dmidecode.bios() would fail completely instead of
reporting what it could find.
This patch fixes this issue and it will normally ignore not found key
values and just continue pythonizing the XML data and return what it
managed to translate into a Python dictionary.
If DEBUG is defined when compiling python-dmidecode, a warning message
will be printed directly to stderr when a key value is not found.
A warning is printed if dmidecode is compiled with DEBUG defined.
Diffstat (limited to 'src/xmlpythonizer.c')
-rw-r--r-- | src/xmlpythonizer.c | 45 |
1 files changed, 22 insertions, 23 deletions
diff --git a/src/xmlpythonizer.c b/src/xmlpythonizer.c index bf3d323..a9282e2 100644 --- a/src/xmlpythonizer.c +++ b/src/xmlpythonizer.c @@ -1040,33 +1040,32 @@ PyObject *pythonizeXMLnode(ptzMAP *in_map, xmlNode *data_n) { xpctx->node = data_n; xpo = _get_xpath_values(xpctx, map_p->rootpath); - if( (xpo == NULL) || (xpo->nodesetval == NULL) || (xpo->nodesetval->nodeNr == 0) ) { - if( xpo != NULL ) { - xmlXPathFreeObject(xpo); + if( (xpo != NULL) && (xpo->nodesetval != NULL) && (xpo->nodesetval->nodeNr > 0) ) { + for( i = 0; i < xpo->nodesetval->nodeNr; i++ ) { + xpctx->node = xpo->nodesetval->nodeTab[i]; + + if( _get_key_value(key, 256, map_p, xpctx, 0) != NULL ) { + PyObject *res = _deep_pythonize(retdata, map_p, + xpo->nodesetval->nodeTab[i], i); + if( res == NULL ) { + // Exit if we get NULL - something is wrong + //and exception is set + return NULL; + } + } } - xmlFreeDoc(xpdoc); xmlXPathFreeContext(xpctx); - PyReturnError(PyExc_LookupError, - "Could not locate XML path node (e2): %s " - "(Defining key: %s)", map_p->rootpath, map_p->key); + xmlFreeDoc(xpdoc); } - - for( i = 0; i < xpo->nodesetval->nodeNr; i++ ) { - xpctx->node = xpo->nodesetval->nodeTab[i]; - - if( _get_key_value(key, 256, map_p, xpctx, 0) != NULL ) { - PyObject *res = _deep_pythonize(retdata, map_p, - xpo->nodesetval->nodeTab[i], i); - if( res == NULL ) { - // Exit if we get NULL - something is wrong - //and exception is set - return NULL; - } - } +#ifdef DEBUG + else { + fprintf(stderr, "** pythonizeXMLnode :: Could not locate node for key value: " + "root path '%s', key '%s'\n", map_p->rootpath, map_p->key); + } +#endif + if( xpo != NULL ) { + xmlXPathFreeObject(xpo); xpo = NULL; } - xmlXPathFreeObject(xpo); - xmlXPathFreeContext(xpctx); - xmlFreeDoc(xpdoc); } else { PyObject *res = _deep_pythonize(retdata, map_p, data_n, 0); if( res == NULL ) { |