fix for {"text":} dictionaries in record fields
authorsmbaker <smbaker@fc8clean.lan>
Mon, 31 Oct 2011 02:43:20 +0000 (19:43 -0700)
committersmbaker <smbaker@fc8clean.lan>
Mon, 31 Oct 2011 02:43:20 +0000 (19:43 -0700)
sfa/util/record.py
sfa/util/xml.py

index 54c3f9f..424f419 100644 (file)
@@ -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
index 89eef9e..d880ed3 100755 (executable)
@@ -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')