def packdict(self, val): # Pack dictionary whose keys are strings (e.g. 'foo'), Keywords (e.g. k.name) or AETypes (e.g. AEType('pnam'). record = newrecord() if self.kClassKeyword in val or self.kClassType in val: # if hash contains a 'class' property containing a class name, coerce the AEDesc to that class newval = val.copy() if self.kClassKeyword in newval: value = newval.pop(self.kClassKeyword) else: value = newval.pop(self.kClassType) if isinstance(value, Keyword): # get the corresponding AEType (assuming there is one) value = self.typebyname().get(value.name, value) if isinstance(value, aem.AEType): # coerce the record to the desired type record = record.coerce(value.code) val = newval usrf = None for key, value in val.items(): if isinstance(key, Keyword): try: keyCode = self.typebyname()[key.AS_name].code except KeyError as err: raise ValueError("Unknown Keyword: k.{}".format(key.AS_name)) from err record.setparam(keyCode, self.pack(value)) elif isinstance(key, aem.AETypeBase): # AEType/AEProp (AEType is normally used in practice) record.setparam(key.code, self.pack(value)) else: # user-defined key (normally a string) if not usrf: usrf = newlist() usrf.setitem(0, self.pack(key)) usrf.setitem(0, self.pack(value)) if usrf: record.setparam(b'usrf', usrf) return record
def packdict(self, val): # Pack dictionary whose keys are strings (e.g. 'foo'), Keywords (e.g. k.name) or AETypes (e.g. AEType('pnam'). record = newrecord() if self.kClassKeyword in val or self.kClassType in val: # if hash contains a 'class' property containing a class name, coerce the AEDesc to that class newval = val.copy() if self.kClassKeyword in newval: value = newval.pop(self.kClassKeyword) else: value = newval.pop(self.kClassType) if isinstance(value, Keyword): # get the corresponding AEType (assuming there is one) value = self.typebyname().get(value.name, value) if isinstance(value, aem.AEType): # coerce the record to the desired type record = record.coerce(value.code) val = newval usrf = None for key, value in val.items(): if isinstance(key, Keyword): try: keyCode = self.typebyname()[key.AS_name].code except KeyError: raise ValueError("Unknown Keyword: k.%s" % key.AS_name) record.setparam(keyCode, self.pack(value)) elif isinstance(key, aem.AETypeBase): # AEType/AEProp (AEType is normally used in practice) record.setparam(key.code, self.pack(value)) else: # user-defined key (normally a string) if not usrf: usrf = newlist() usrf.setitem(0, self.pack(key)) usrf.setitem(0, self.pack(value)) if usrf: record.setparam('usrf', usrf) return record