[Pythonmac-SIG] convert binary plist to xml string

Bob Ippolito bob at redivi.com
Mon May 9 01:10:37 CEST 2005


On May 8, 2005, at 6:40 PM, Florian Munz wrote:

> Nicholas Riley <njriley at uiuc.edu> wrote:
>
>
>> In [3]: plist, format, error =
>> NSPropertyListSerialization.propertyListFromData_mutabilityOption_for 
>> ma
>> t_errorDescription_(NSData.dataWithContentsOfMappedFile_ 
>> (os.path.expand
>> user('~/Library/Preferences/com.apple.keychainsync.plist')),
>> NSPropertyListImmutable, 0)
>>
>> In [4]: plist Out[4]: {KeychainSyncList = (); }
>>
>> In [5]: data, error =
>> NSPropertyListSerialization.dataFromPropertyList_format_errorDescript 
>> ion_(
>> plist, NSPropertyListXMLFormat_v1_0)
>>
>> [...]
>>
>
> thanks, that works exactly the way I need it. I found out you can get
> the string faster if you convert the NSData right away:
>
> s = NSString.alloc().initWithData_encoding_(data,  
> NSUTF8StringEncoding)

There's plenty of other ways to say that..  In 1.3 you should be able  
to do this:
s = unicode(buffer(data), 'utf-8')

Or before you could do:
s = unicode(data.bytes(), 'utf-8')

-bob



More information about the Pythonmac-SIG mailing list