+ assert self.type in BUILTIN_TYPES
+
+ # in addition we provide convenience for converting to and from xml records
+ # for this purpose only, we need the subclasses to define 'fields' as either
+ # a list or a dictionary
+ def xml_fields (self):
+ fields=self.fields
+ if isinstance(fields,dict): fields=fields.keys()
+ return fields
+ def load_from_xml (self, xml):
+ xml_record = XML(xml)
+ xml_dict = xml_record.todict()
+ for k in self.xml_fields():
+ if k in xml_dict:
+ setattr(self,k,xml_dict[k])
+
+ def save_as_xml (self):
+ # xxx unset fields don't get exposed, is that right ?
+ input_dict = dict( [ (key, getattr(self.key), ) for key in self.xml_fields() if getattr(self,key,None) ] )
+ xml_record=XML("<record />")
+ xml_record.parse_dict (input_dict)
+ return xml_record.toxml()