[Python-Dev] os.path.normcase rationale?

James Y Knight foom at fuhm.net
Sat Sep 25 01:36:42 CEST 2010


On Sep 24, 2010, at 10:53 AM, Paul Moore wrote:
> On 24 September 2010 15:29, Guido van Rossum <guido at python.org> wrote:
>> I don't think we should try to reimplement what the filesystem does. I
>> think we should just ask the filesystem (how exactly I haven't figured
>> out yet but I expect it will be more OS-specific than
>> filesystem-specific). It will have to be a new API -- normcase() at
>> least is *intended* to return a case-flattened name on OSes where
>> case-preserving filesystems are the default, and changing it to look
>> at the filesystem would break too much code. For a new use case we
>> need a new API.
> 
> I dug into this once, and as far as I could tell, it's possible to get
> the information on Windows, but there's no way on Linux to "ask the
> filesystem". From my researches, the standard interfaces a filesystem
> has to implement on Linux don't offer any means of asking this
> question.
> 
> Of course, (a) I'm no Linux expert so what do I know, and (b) it may
> well be possible to come up with a "good enough" solution by ignoring
> pathologically annoying theoretical cases.
> 
> I'm happy to provide Windows code if someone needs it.
> Paul

An OSX code sketch is available here (summary: call FSPathMakeRef to get an FSRef from a path string, then FSRefMakePath to make it back into a path, which will then have the correct case). And note that it only works if the file actually exists.

http://stackoverflow.com/questions/370186/how-do-i-find-the-correct-case-of-a-filename

It would indeed be useful to have that be available in Python.

James


More information about the Python-Dev mailing list