From: smbaker Date: Mon, 31 Oct 2011 02:43:20 +0000 (-0700) Subject: fix for {"text":} dictionaries in record fields X-Git-Tag: sfa-1.1-3~95 X-Git-Url: http://git.onelab.eu/?p=sfa.git;a=commitdiff_plain;h=0d99aeaefbb5c67e963659f1c21e755cb5bc8c43 fix for {"text":} dictionaries in record fields --- diff --git a/sfa/util/record.py b/sfa/util/record.py index 54c3f9f7..424f4195 100644 --- a/sfa/util/record.py +++ b/sfa/util/record.py @@ -279,6 +279,7 @@ class SfaRecord(Row): """ Load the record from a dictionary """ + self.set_name(dict['hrn']) gidstr = dict.get("gid", None) if gidstr: @@ -316,9 +317,9 @@ class SfaRecord(Row): representation of the record. """ #dict = xmlrpclib.loads(str)[0][0] - + record = XML(str) - self.load_from_dict(record.todict()) + self.load_from_dict(record.todict2()) ## # Dump the record to stdout diff --git a/sfa/util/xml.py b/sfa/util/xml.py index 89eef9e0..d880ed3c 100755 --- a/sfa/util/xml.py +++ b/sfa/util/xml.py @@ -226,7 +226,24 @@ class XML: if child.tag not in d: d[child.tag] = [] d[child.tag].append(self.todict(child)) - return d + return d + + # XXX smbaker, for record.load_from_string + def todict2(self, elem=None): + if elem is None: + elem = self.root + d = {} + d.update(elem.attrib) + d['text'] = elem.text + for child in elem.iterchildren(): + if child.tag not in d: + d[child.tag] = [] + d[child.tag].append(self.todict2(child)) + + if len(d)==1 and ("text" in d): + d = d["text"] + + return d def save(self, filename): f = open(filename, 'w')