def _packDict(val, codec): # Pack dictionary whose keys are strings (e.g. 'foo'), Keywords (e.g. k.name) or AETypes (e.g. AEType('pnam'). record = AECreateList('', True) if val.has_key(_classKeyword) or val.has_key(_classType): # if hash contains a 'class' property containing a class name, coerce the AEDesc to that class newval = val.copy() if newval.has_key(_classKeyword): value = newval.pop(_classKeyword) else: value = newval.pop(_classType) if isinstance(value, Keyword): # get the corresponding AEType (assuming there is one) value = codec.typebyname.get(value.name, value) if isinstance(value, aem.AEType): # coerce the record to the desired type record = record.AECoerceDesc(value.code) val = newval usrf = None for key, value in val.items(): if isinstance(key, Keyword): try: keyCode = codec.typebyname[key.AS_name].code except KeyError: raise KeyError, "Unknown Keyword: k.%s" % key.AS_name record.AEPutParamDesc(keyCode, codec.pack(value)) elif isinstance(key, aem.AETypeBase): # AEType/AEProp (AEType is normally used in practice) record.AEPutParamDesc(key.code, codec.pack(value)) else: # user-defined key (normally a string) if not usrf: usrf = AECreateList('', False) usrf.AEPutDesc(0, codec.pack(key)) usrf.AEPutDesc(0, codec.pack(value)) if usrf: record.AEPutParamDesc('usrf', usrf) return record
def _packDict(val, codecs): record = AECreateList('', True) usrf = None for key, value in val.items(): if isinstance(key, (AEType, AEProp)): if key.code == 'pcls': # AS packs records that contain a 'class' property by coercing the packed record to that type at the end try: record = record.AECoerceDesc(value.code) except: record.AEPutParamDesc(key.code, codecs.pack(value)) else: record.AEPutParamDesc(key.code, codecs.pack(value)) else: if not usrf: usrf = AECreateList('', False) usrf.AEPutDesc(0, codecs.pack(key)) usrf.AEPutDesc(0, codecs.pack(value)) if usrf: record.AEPutParamDesc('usrf', usrf) return record
def _packDict(val, codecs): record = AECreateList('', True) usrf = None for key, value in val.items(): if isinstance(key, (AEType, AEProp)): record.AEPutParamDesc(key.code, codecs.pack(value)) else: if not usrf: usrf = AECreateList('', False) usrf.AEPutDesc(0, codecs.pack(key)) usrf.AEPutDesc(0, codecs.pack(value)) if usrf: record.AEPutParamDesc('usrf', usrf) return record
def _packDict(val, codec): # Pack dictionary whose keys are strings (e.g. 'foo'), Keywords (e.g. k.name) or AETypes (e.g. AEType('pnam'). record = AECreateList('', True) usrf = None for key, value in val.items(): if isinstance(key, Keyword): try: keyCode = codec.typebyname[key.AS_name].code except KeyError: raise KeyError, "Unknown Keyword: k.%s" % key.AS_name record.AEPutParamDesc(keyCode, codec.pack(value)) elif isinstance( key, aem.AETypeBase ): # AEType/AEProp (AEType is normally used in practice) record.AEPutParamDesc(key.code, codec.pack(value)) else: # user-defined key (normally a string) if not usrf: usrf = AECreateList('', False) usrf.AEPutDesc(0, codec.pack(key)) usrf.AEPutDesc(0, codec.pack(value)) if usrf: record.AEPutParamDesc('usrf', usrf) return record
def _packList(val, codecs): lst = AECreateList('', False) for item in val: lst.AEPutDesc(0, codecs.pack(item)) return lst