Index: Lib/plat-mac/aepack.py =================================================================== --- Lib/plat-mac/aepack.py (revision 56563) +++ Lib/plat-mac/aepack.py (working copy) @@ -35,26 +35,20 @@ #typeAEText = b'tTXT' #typeEnumeration = b'enum' -def b2i(byte_string): - result = 0 - for byte in byte_string: - result <<= 8 - result += byte - return result # # Some AE types are immedeately coerced into something # we like better (and which is equivalent) # unpacker_coercions = { - b2i(typeComp) : typeFloat, - b2i(typeColorTable) : typeAEList, - b2i(typeDrawingArea) : typeAERecord, - b2i(typeFixed) : typeFloat, - b2i(typeExtended) : typeFloat, - b2i(typePixelMap) : typeAERecord, - b2i(typeRotation) : typeAERecord, - b2i(typeStyledText) : typeAERecord, - b2i(typeTextStyles) : typeAERecord, + str(typeComp) : typeFloat, + str(typeColorTable) : typeAEList, + str(typeDrawingArea) : typeAERecord, + str(typeFixed) : typeFloat, + str(typeExtended) : typeFloat, + str(typePixelMap) : typeAERecord, + str(typeRotation) : typeAERecord, + str(typeStyledText) : typeAERecord, + str(typeTextStyles) : typeAERecord, }; # @@ -133,8 +127,8 @@ """Unpack an AE descriptor to a python object""" t = desc.type - if b2i(t) in unpacker_coercions: - desc = desc.AECoerceDesc(unpacker_coercions[b2i(t)]) + if str(t) in unpacker_coercions: + desc = desc.AECoerceDesc(unpacker_coercions[str(t)]) t = desc.type # This is a guess by Jack.... if t == typeAEList: @@ -147,7 +141,7 @@ d = {} for i in range(desc.AECountItems()): keyword, item = desc.AEGetNthDesc(i+1, b'****') - d[b2i(keyword)] = unpack(item, formodulename) + d[str(keyword)] = unpack(item, formodulename) return d if t == typeAEText: record = desc.AECoerceDesc(b'reco') @@ -305,33 +299,33 @@ return aetypes.Keyword(keyword) def mkrange(dict): - return aetypes.Range(dict[b2i(b'star')], dict[b2i(b'stop')]) + return aetypes.Range(dict['star'], dict['stop']) def mkcomparison(dict): - return aetypes.Comparison(dict[b2i(b'obj1')], - dict[b2i(b'relo')].enum, - dict[b2i(b'obj2')]) + return aetypes.Comparison(dict['obj1'], + dict['relo'].enum, + dict['obj2']) def mklogical(dict): - return aetypes.Logical(dict[b2i(b'logc')], dict[b2i(b'term')]) + return aetypes.Logical(dict['logc'], dict['term']) def mkstyledtext(dict): - return aetypes.StyledText(dict[b2i(b'ksty')], dict[b2i(b'ktxt')]) + return aetypes.StyledText(dict['ksty'], dict['ktxt']) def mkaetext(dict): - return aetypes.AEText(dict[b2i(keyAEScriptTag)], - dict[b2i(keyAEStyles)], - dict[b2i(keyAEText)]) + return aetypes.AEText(dict[str(keyAEScriptTag)], + dict[str(keyAEStyles)], + dict[str(keyAEText)]) def mkinsertionloc(dict): - return aetypes.InsertionLoc(dict[b2i(keyAEObject)], - dict[b2i(keyAEPosition)]) + return aetypes.InsertionLoc(dict[str(keyAEObject)], + dict[str(keyAEPosition)]) def mkobject(dict): - want = dict[b2i(b'want')].type - form = dict[b2i(b'form')].enum - seld = dict[b2i(b'seld')] - fr = dict[b2i(b'from')] + want = dict['want'].type + form = dict['form'].enum + seld = dict['seld'] + fr = dict['from'] if form in (b'name', b'indx', b'rang', b'test'): if want == b'text': return aetypes.Text(seld, fr) if want == b'cha ': return aetypes.Character(seld, fr) @@ -351,15 +345,15 @@ # to __class__ is safe. Moreover, shouldn't there be a better # initializer for the classes in the suites? def mkobjectfrommodule(dict, modulename): - if (isinstance(dict[b2i(b'want')], type) and - issubclass(dict[b2i(b'want')], ObjectSpecifier)): + if (isinstance(dict['want'], type) and + issubclass(dict['want'], ObjectSpecifier)): # The type has already been converted to Python. Convert back:-( - classtype = dict[b2i(b'want')] - dict[b2i(b'want')] = aetypes.mktype(classtype.want) - want = dict[b2i(b'want')].type + classtype = dict['want'] + dict['want'] = aetypes.mktype(classtype.want) + want = dict['want'].type module = __import__(modulename) codenamemapper = module._classdeclarations - classtype = codenamemapper.get(b2i(want), None) + classtype = codenamemapper.get(str(want), None) newobj = mkobject(dict) if classtype: assert issubclass(classtype, ObjectSpecifier) @@ -370,7 +364,7 @@ if modulename: module = __import__(modulename) codenamemapper = module._classdeclarations - classtype = codenamemapper.get(b2i(typecode), None) + classtype = codenamemapper.get(str(typecode), None) if classtype: return classtype return aetypes.mktype(typecode)