diff options
author | Justin Santa Barbara <justin@fathomdb.com> | 2011-02-23 12:36:09 -0800 |
---|---|---|
committer | Justin Santa Barbara <justin@fathomdb.com> | 2011-02-23 12:36:09 -0800 |
commit | b3b005f50de54b5ef6c62e387dcec5a123f93cf6 (patch) | |
tree | 70aa46c02622e40341cc7d6311b6a265bf65c263 /nova/utils.py | |
parent | 5283e1c131a21ea4963c702a7137536f7b894bb6 (diff) | |
download | nova-b3b005f50de54b5ef6c62e387dcec5a123f93cf6.tar.gz nova-b3b005f50de54b5ef6c62e387dcec5a123f93cf6.tar.xz nova-b3b005f50de54b5ef6c62e387dcec5a123f93cf6.zip |
Cope when we pass a non-list to xpath_select - wrap it in a list
Diffstat (limited to 'nova/utils.py')
-rw-r--r-- | nova/utils.py | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/nova/utils.py b/nova/utils.py index 2f926bd82..c2cbeb2a7 100644 --- a/nova/utils.py +++ b/nova/utils.py @@ -508,7 +508,8 @@ def minixpath_select(items, minixpath): item in items, looks up items[prop1][prop2][prop3]. Like XPath, if any of the intermediate results are lists it will treat each list item individually. A 'None' in items or any child expressions will be ignored, - this function will not throw because of None (anywhere) in items""" + this function will not throw because of None (anywhere) in items. The + returned list will contain no None values.""" if minixpath is None: raise exception.Error("Invalid mini_xpath") @@ -523,6 +524,10 @@ def minixpath_select(items, minixpath): if items is None: return results + if not isinstance(items, types.ListType): + # Wrap single objects in a list + items = [items] + for item in items: if item is None: continue @@ -532,6 +537,7 @@ def minixpath_select(items, minixpath): child = get_method(first_token) if child is None: continue + #print "%s => %s" % (first_token, child) if isinstance(child, types.ListType): # Flatten intermediate lists for x in child: |