Record.todict behaves suspisciously
authorThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 5 Jun 2015 10:06:23 +0000 (12:06 +0200)
committerThierry Parmentelat <thierry.parmentelat@inria.fr>
Fri, 5 Jun 2015 10:06:23 +0000 (12:06 +0200)
no change for now, but we disambiguate between XML.todict() and Record.todict()
so we can more easily spot which is which

clientbin/getNodes.py
sfa/client/sfi.py
sfa/managers/registry_manager.py
sfa/storage/model.py
sfa/storage/record.py

index 71d17f0..d77bbbc 100644 (file)
@@ -51,13 +51,18 @@ def print_dict(rdict, options, counter=1):
         if keys: print tab * (counter) + "(children: %s)" % (",".join(keys))    
         
 
+#
+# this code probably is obsolete
+# RSpec is not imported, it does not have a toDict() method anyway
+# plus, getNodes.py is not exposed in packaging
+# 
 def main():
     parser = create_parser(); 
     (options, args) = parser.parse_args()
     if not options.infile:
         print "RSpec file not specified"
         return 
-        
+
     rspec = RSpec()
     try:
         rspec.parseFile(options.infile)
index dce1ac2..dbf14a9 100644 (file)
@@ -1054,12 +1054,12 @@ use this if you mean an authority instead""")
             try:
                 record_filepath = args[0]
                 rec_file = self.get_record_file(record_filepath)
-                record_dict.update(load_record_from_file(rec_file).todict())
+                record_dict.update(load_record_from_file(rec_file).record_to_dict())
             except:
                 print "Cannot load record file {}".format(record_filepath)
                 sys.exit(1)
         if options:
-            record_dict.update(load_record_from_opts(options).todict())
+            record_dict.update(load_record_from_opts(options).record_to_dict())
         # we should have a type by now
         if 'type' not in record_dict :
             self.print_help()
@@ -1086,9 +1086,9 @@ use this if you mean an authority instead""")
         if len(args) > 0:
             record_filepath = args[0]
             rec_file = self.get_record_file(record_filepath)
-            record_dict.update(load_record_from_file(rec_file).todict())
+            record_dict.update(load_record_from_file(rec_file).record_to_dict())
         if options:
-            record_dict.update(load_record_from_opts(options).todict())
+            record_dict.update(load_record_from_opts(options).record_to_dict())
         # at the very least we need 'type' here
         if 'type' not in record_dict or record_dict['type'] is None:
             self.print_help()
index 6049ebb..8e8eb78 100644 (file)
@@ -235,7 +235,7 @@ class RegistryManager:
         # xxx somehow here calling dict(record) issues a weird error
         # however record.todict() seems to work fine
         # records.extend( [ dict(record) for record in local_records ] )
-        records.extend( [ record.todict(exclude_types=(InstrumentedList,)) for record in local_records ] )
+        records.extend( [ record.record_to_dict(exclude_types=(InstrumentedList,)) for record in local_records ] )
 
         if not records:
             raise RecordNotFound(str(hrns))
@@ -296,7 +296,7 @@ class RegistryManager:
                 # record.todict() is the place where __dict__ is used
                 print "DO NOT REMOVE ME before augment_with_sfa_builtins, record=%s"%record
                 augment_with_sfa_builtins(record)
-            record_dicts = [ record.todict(exclude_types=(InstrumentedList,)) for record in records ]
+            record_dicts = [ record.record_to_dict(exclude_types=(InstrumentedList,)) for record in records ]
     
         return record_dicts
     
index 347012d..7ce8345 100644 (file)
@@ -469,9 +469,9 @@ def make_record_dict (record_dict):
     # register non-db attributes in an extensions field
     return result
         
-def make_record_xml (xml):
-    xml_record = XML(xml)
-    xml_dict = xml_record.todict()
+def make_record_xml (xml_str):
+    xml = XML(xml_str)
+    xml_dict = xml.todict()
     logger.info("load from xml, keys=%s"%xml_dict.keys())
     return make_record_dict (xml_dict)
 
index a4a87b4..5931765 100644 (file)
@@ -8,12 +8,12 @@ from sfa.util.sfalogging import logger
 
 class Record:
 
-    def __init__(self, dict=None, xml=None):
+    def __init__(self, dict=None, xml_str=None):
         if dict:
             self.load_from_dict(dict)
-        elif xml:
-            xml_record = XML(xml)
-            xml_dict = xml_record.todict()
+        elif xml_str:
+            xml = XML(xml_str)
+            xml_dict = xml.todict()
             self.load_from_dict(xml_dict)  
 
 
@@ -39,7 +39,7 @@ class Record:
     # need to filter out results, esp. wrt relationships
     # exclude_types must be a tuple so we can use isinstance
     # 
-    def todict (self, exclude_types=None):
+    def record_to_dict (self, exclude_types=None):
         if exclude_types is None:
             exclude_types = ()
         d = self.__dict__