From 1eb0a92e804609f65afbecf6b47166853f950bbf Mon Sep 17 00:00:00 2001 From: Scott Baker Date: Tue, 13 Jan 2009 22:52:17 +0000 Subject: [PATCH] added save_to_string, load_from_string --- util/record.py | 41 +++++++++++++++++++++++++++++++++-------- 1 file changed, 33 insertions(+), 8 deletions(-) diff --git a/util/record.py b/util/record.py index 2d6d7acf..50e3e678 100644 --- a/util/record.py +++ b/util/record.py @@ -52,14 +52,7 @@ class GeniRecord(): if pointer: self.set_pointer(pointer) if dict: - self.set_name(dict['name']) - self.set_gid(dict['gid']) - self.set_type(dict['type']) - self.set_pointer(dict['pointer']) - if "pl_info" in dict: - self.set_pl_info(dict["pl_info"]) - if "geni_info" in dict: - self.set_geni_info(dict["geni_info"]) + self.load_from_dict(dict) ## # Set the name of the record @@ -223,6 +216,38 @@ class GeniRecord(): return dict + ## + # Load the record from a dictionary + # + # @param dict dictionary to load record fields from + + def load_from_dict(self, dict): + self.set_name(dict['name']) + self.set_gid(dict['gid']) + self.set_type(dict['type']) + self.set_pointer(dict['pointer']) + if "pl_info" in dict: + self.set_pl_info(dict["pl_info"]) + if "geni_info" in dict: + self.set_geni_info(dict["geni_info"]) + + ## + # Save the record to a string. The string contains an XML representation of + # the record. + + def save_to_string(self): + dict = self.as_dict() + str = xmlrpclib.dumps((dict,), allow_none=True) + return str + + ## + # Load the record from a string. The string is assumed to contain an XML + # representation of the record. + + def load_from_string(self, str): + dict = xmlrpclib.loads(str)[0][0] + self.load_from_dict(dict) + ## # Dump the record to stdout # -- 2.43.0