[Pythonmac-SIG] AppleEvents in MacPython 2.3?

Larry Meyn Larry.A.Meyn at nasa.gov
Fri Aug 15 16:26:56 EDT 2003


Jack,

Thanks! This should should work great for my application. Although I'm 
wanting paths to new files, I'm only placing them in existing 
directories and your function can give me robust OS 9 paths for those.

Larry

On Friday, August 15, 2003, at 02:58 PM, Jack Jansen wrote:
>
> This will work for 90% of the paths, but fail on all sorts of 
> exceptional
> ones. Some of the problems:
> - It doesn't handle ':' in unix filenames (should be converted to /)
> - It only handles 7-bit ascii (unix filenames use utf8 encoding, OS9 
> paths
>   use MacRoman or another encoding)
> - It will fail for filenames longer than 32 (or 31) characters
>
>
> What you should do is create an FSSpec for the file, and recursively 
> get
> the pathname components from it. Here it is:
>
> def makeOS9abspath(path):
> 	"""Returns an ":" delimited, OS 9 style absolute path.
> 	"""
> 	import Carbon.File, os.path
> 	
> 	rv = []
> 	fss = Carbon.File.FSSpec(path)
> 	while 1:
> 		vrefnum, dirid, filename = fss.as_tuple()
> 		rv.insert(0, filename)
> 		if dirid == 1: break
> 		fss = Carbon.File.FSSpec((vrefnum, dirid, ""))
> 	if len(rv) == 1:
> 		rv.append('')
> 	return ':'.join(rv)
>
> This one still has a problem in that it will not work if path doesn't 
> yet
> exist, on OSX FSSpec(path) goes via FSRef's, and these are only 
> defined on
> existing files. The bad news is that I don't think there is a 100% 
> failsafe
> way to create an OS9 path for a nonexisting item on OSX (given a UTF8 
> unix
> path).
> --
> - Jack Jansen        <Jack.Jansen at oratrix.com>        
> http://www.cwi.nl/~jack -
> - If I can't dance I don't want to be part of your revolution -- Emma 
> Goldman -
>
>
> _______________________________________________
> Pythonmac-SIG maillist  -  Pythonmac-SIG at python.org
> http://mail.python.org/mailman/listinfo/pythonmac-sig
>
>


Larry Meyn
Aerospace Operations Modeling Office

M/S 210-10                      Phone:  (650) 604-5038
NASA Ames Research Center       Fax:    (650) 604-0222
Moffett Field, CA 94035-1000    E-mail: Larry.A.Meyn at nasa.gov
                                 E-Fax:  (425) 944-5526 sent via e-mail
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: text/enriched
Size: 2147 bytes
Desc: not available
Url : http://mail.python.org/pipermail/pythonmac-sig/attachments/20030815/b0752440/attachment.bin


More information about the Pythonmac-SIG mailing list