[Pythonmac-SIG] Some new tools: plistservices, userdefaults, and CFPython

Sarwat Khan sarwat at sarwat.net
Fri Sep 5 22:36:51 EDT 2003


On Friday, September 5, 2003, at 08:11  PM, Bob Ippolito wrote:
>
> >>> import Carbon.CF
> >>> data = Carbon.CF.CFDataCreate('some arbitrary data...')
> >>> data.CFDataGetData()
> 'some arbitrary data...'

The problem is that pycfbridge.c's PyCF_Python2CF won't convert a 
Python instance to a CFData object and backwards. It looks like it 
won't work with Python CFTypeRefs either.

Also, it didn't help that I didn't know that pycfbridge existed when I 
wrote CFPython :) Not that it took much time anyway. Note that 
userdefaults also works with the Python 2.2 that ships with Mac OS X 
10.2.

>> Although if you think it has a useful future a module, let me know; I 
>> wrote it because it was an easier way of writing the userdefaults 
>> module. I haven't considered it to be anything else.
>
> I see that now, but I still think you should simply use the 
> CFDataGetData/CFDataCreate methods when you need a CFData, and write a 
> simple CFDate extension module to add that functionality to Carbon.CF.

Hmm. So far I've been a member of the MacPython community for 25.5 
hours now (according to the timestamp on the Welcome email) so keep in 
mind that this is all pretty new to me :) I've been using Python on 
Unix for some time (installing python on OS X myself as needed and on 
FreeBSD, etc).

A Python data instance isn't necessarily going to be a CFData object. 
If you take a look at the defaultsdemo.py in the userdefaults-1 
distribution, it defines several possible data classes. plistservices 
defines another. In my BitTorrent implementation, I define 'data' to be 
anything that raises a unicode exception while trying to encode 'str' 
objects into UTF-8.

So the problem is not that I need a CFDataRef instance, it's more of an 
issue of object classification. Python doesn't really have a 'data' 
type like NSData, you're expected to use str to hold bytes. However, 
you can't assume that every str you come across is binary data, which 
is why pycfbridge doesn't handle CFData.

Also, userdefaults.py manipulates user defaults without plat-mac... I'm 
kind of hoping that people using other platforms will be interested in 
the module too.

And yeah, someone should write the datetime<=>CFDate code for 
pycfbridge... feel free to swipe my code :P It's just a few lines. 
Again, I don't know who's in charge of that stuff.

I think this email response has lost coherence; I had dinner in-between 
writing it.

(hey look at that, userdefaults.UserDefaults.dataForKey's 
implementation is a few revisions too old...)

{sarwat khan : http://sarwat.net}




More information about the Pythonmac-SIG mailing list