[Pythonmac-SIG] CFURL Pain

has hengist.podd at virgin.net
Wed Mar 2 15:00:54 CET 2005


Bob wrote:

>FSSpec is legacy.  It should not ever be used in any code except to 
>reference nonexistent files or to deal with legacy APIs.  You 
>shouldn't use them if the API will take an FSRef or an Alias.

Neither FSRef or Alias can be used to refer to non-existent files. 
FileURL does, but I'm not sure it can yet be used safely in place of 
FSSpecs in all cases, plus their standard Carbon.CF implementation is 
busted. FSSpecs suck, but I'm not sure they can be completely ignored 
just yet - any time I've tried to streamline aem/appscript to save 
the user from dealing with crap like this I've ended up having to 
re-expose it again in all its ugliness after something else ralphed 
on the 'clean and elegant' version. Rock, hard place.

What's really needed is for MacPython to provide a standard 
high-level File class that abstracts over all this mess so module 
authors can have a solid and reliable API to implement against and 
end users don't normally need to futz directly with this stuff. No 
doubt an interesting and challenging problem for anyone that wanted 
to tackle it.


>  In this case, the API *asks* for an Alias.  So, yeah, you do 
>actually want an Alias.

No, the TextEdit dictionary says 'alias', but the dictionary is 
merely documentation, not the API itself, and dictionaries are 
regularly incorrect. It should almost certainly read 'file'. IIRC, 
the sdef format doesn't even list 'alias' as one of the standard 
primitive types, so I've no idea where TextEdit gets it from. 
Probably a blow on the head or something.

Cocoa Scripting APIs are _also_ frequently buggy and ill-designed, 
and specifying files was one of its classic blunders in earlier 
incarnations which they've been trying to rectify ever since. So it 
is possible that they've buggered things up differently in 10.3 such 
that you do have to specify an existing file in a 'save' command; I 
don't have 10.3 so can't check offhand. If they have, I'm sure 
there's bugs filed on that as well, but I can't recall hearing 
anything about it.

Nevertheless, 'save' commands have always traditionally accepted a 
file handle specifying an as-yet non-existent file for saving 
documents to a new file, and ignoring periodic Apple incompetence I 
don't believe this policy has formally changed for one moment. Apply 
one dose of healthy skepticism and a large dollop of plain common 
sense - both absolutely essential when it comes to Mac application 
scripting - and this should be obvious.

has
-- 
http://freespace.virgin.net/hamish.sanderson/


More information about the Pythonmac-SIG mailing list