[Pythonmac-SIG] convert binary plist to xml string
Bob Ippolito
bob at redivi.com
Mon May 16 19:40:49 CEST 2005
On May 16, 2005, at 1:31 PM, Bill Janssen wrote:
>> first, second, third, fourth, fifth, ..... = struct.unpack
>> ("iiIIiIiiILllfd", data)
>>
>> It is SO EASY to screw this up. Pick the wrong type code, or
>> misalign the type and field. It needs to look more like something
>> sane:
>>
>> class Point(struct.BigEndianStruct):
>> x = struct.SInt32()
>> y = struct.SInt32()
>>
>
> Why not (for yourself) just add a module which addresses some of this?
> As in:
>
> from unpacking import *
>
> def getPoint (bvar):
> unpack = unpacking(bvar)
> x = unpack(S_INT_32)
> y = unpack(S_INT_32)
I have (sitting in macholib), but it still doesn't address the
shortcomings of the struct module. For example, you can use the
struct module to unpack unaligned data types but only if you do it
one element at a time and you have to break up all the strings, etc.
It can't unpack pascal strings, there's no hooks to plug in for
variable length data structures, etc. There's also plenty of data
types it doesn't cover (bit vectors, whatever else).
Anyway, my point was that the struct module is horrible. It's
certainly possible to write something better that may or may not use
it internally, but such a thing isn't generally available and
certainly isn't in the standard library.
-bob
More information about the Pythonmac-SIG
mailing list