updated Xml.todict()
[sfa.git] / sfa / util / record.py
index f9eaa09..7ebf379 100644 (file)
@@ -4,18 +4,14 @@
 # TODO: Use existing PLC database methods? or keep this separate?
 ##
 
-### $Id$
-### $URL$
-
 from types import StringTypes
 
-from sfa.trust.gid import *
+from sfa.trust.gid import GID
 
-import sfa.util.report
-from sfa.util.rspec import *
-from sfa.util.parameter import *
-from sfa.util.namespace import *
+from sfa.util.parameter import Parameter
+from sfa.util.xrn import get_authority
 from sfa.util.row import Row
+from sfa.util.xml import XML 
 
 class SfaRecord(Row):
     """ 
@@ -208,6 +204,22 @@ class SfaRecord(Row):
         """
         return GID(string=self.gid)
 
+    ##
+    # Returns the value of a field
+
+    def get_field(self, fieldname, default=None):
+        # sometimes records act like classes, and sometimes they act like dicts
+        try:
+            return getattr(self, fieldname)
+        except AttributeError:
+            try:
+                 return self[fieldname]
+            except KeyError:
+                 if default != None:
+                     return default
+                 else:
+                     raise
+
     ##
     # Returns a list of field names in this record. 
 
@@ -267,6 +279,7 @@ class SfaRecord(Row):
         """
         Load the record from a dictionary 
         """
+
         self.set_name(dict['hrn'])
         gidstr = dict.get("gid", None)
         if gidstr:
@@ -289,10 +302,9 @@ class SfaRecord(Row):
         """
         recorddict = self.as_dict()
         filteredDict = dict([(key, val) for (key, val) in recorddict.iteritems() if key in self.fields.keys()])
-        record = RecordSpec()
-        record.parseDict(filteredDict)
+        record = XML('<record/>')
+        record.parse_dict(filteredDict)
         str = record.toxml()
-        #str = xmlrpclib.dumps((dict,), allow_none=True)
         return str
 
     ##
@@ -305,12 +317,9 @@ class SfaRecord(Row):
         representation of the record.
         """
         #dict = xmlrpclib.loads(str)[0][0]
-        
-        record = RecordSpec()
-        record.parseString(str)
-        record_dict = record.toDict()
-        sfa_dict = record_dict['record']
-        self.load_from_dict(sfa_dict)
+
+        record = XML(str)
+        self.load_from_dict(record.todict())
 
     ##
     # Dump the record to stdout
@@ -355,7 +364,7 @@ class UserRecord(SfaRecord):
         'first_name': Parameter(str, 'First name'),
         'last_name': Parameter(str, 'Last name'),
         'phone': Parameter(str, 'Phone Number'),
-        'key': Parameter(str, 'Public key'),
+        'keys': Parameter(str, 'Public key'),
         'slices': Parameter([str], 'List of slices this user belongs to'),
         }
     fields.update(SfaRecord.fields)