There is a lib code, trying to parse an Element Tree object. If exception happens, it either returns an empty dict of dict or a partially constructed object of such type. In this case, caller needs to parse the results to see if parsing is correctly handled or not. Or in other words, the returned dict is not deterministic. How to solve this issue? Or if this is an issue?
def parse_ET(self, ETObj):
if ETObj == None: return None
dict_of_dict = collections.defaultdict(dict)
try:
for doc in ETObj.iter("result"):
id = doc.attrib.get("id")
for elem in doc.iter("attrib"):
dict_of_dict[id].setdefault(elem.attrib.get("name"), elem.text)
except Exception, ex:
logging.exception("%s:%s" % (self.__class__, str(ex)))
finally:
return dict_of_docs