Issue1718975

classification
Title: Patch for os.path.normcase bug 1648449
Type: Severity: normal
Components: Library Versions:
Milestone:
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: Nosy List: cgroves, pekka.klarck, pjenvey
Priority: normal Keywords: patch

Created on 2007-05-14.22:37:35 by pekka.klarck, last changed 2008-02-24.04:18:20 by pjenvey.

Files
File name Uploaded Description Edit Remove
normcase.patch pekka.klarck, 2007-05-14.22:37:35
Messages
msg2721 (view) Author: Pekka Klärck (pekka.klarck) Date: 2007-05-14.22:37:35
Unfortunately there isn't any direct way to ask is the system case insensitive from the JVM. This patch is implemented so that at the end of the javapath.py there's 

_CASE_INSENSITIVE = samefile('foo', 'FOO')

and normcase itself has the following code.

def normcase(path):
    if _CASE_INSENSITIVE:
        path = path.lower()
    return path


If having a new module global attribute doesn't sound like a good idea normcase can of course be implemented as follows.

def normcase(path):
    if samefile('foo', 'FOO'):
        path = path.lower()
    return path


If extra samefile call everyting normcase is used is considered waste there's at least one more possible way.

if samefile('foo', 'FOO'):
    def normcase(path):
        return path.lower()
else:
    def normcase(path):
        return path
msg2722 (view) Author: Pekka Klärck (pekka.klarck) Date: 2007-05-14.22:39:13
Note that the attached patch contains also argument type check for splitext that has been missing. Didn't want to create another patch only for that.
msg2723 (view) Author: Charlie Groves (cgroves) Date: 2007-05-20.05:51:37
This doesn't work for me on Windows if 'foo'(or some case variant thereof) doesn't already exist.  That makes sense to me since without a real path to base its calculations on, how is Java going to normalize to the existing case for a given filename?  We could get around this by calling java.io.File.createTempFile and doing our path calculations based on that.   Of course, then we'd have to handle not being able to create temp files at all.
msg2724 (view) Author: Pekka Klärck (pekka.klarck) Date: 2007-05-20.09:56:20
Charlie, you are absolutely right. I promise to test my pathches better in the future. Just need to get Jython devenv somehow setup to my work machine too since it's the only Windows I have.

I actually first implemented this patch using following test. Unfortunately that's not good either because os.curdir may also be '/' in posix and in that case the check below would return true.

File(os.curdir.upper()).getCanonicalPath() == File(os.curdir.lower()).getCanonicalPath()


You mentioned temp files and I got an idea that perhaps this could be implemented using the system temp directory -- there's no need to create it so there's no error checking required. Based on a little prototyping on console, copied below, it seems to work.

C:\Temp>jython
Jython 2.2b2 on java1.5.0_11
Type "copyright", "credits" or "license" for more information.
>>> from java.io import File
>>> from java.lang import System
>>> tmp = System.getProperty('java.io.tmpdir')
'C:\\DOCUME~1\\pekkalau\\LOCALS~1\\Temp\\'
>>> File(tmp.upper()).getCanonicalPath()
'C:\\Documents and Settings\\pekkalau\\Local Settings\\Temp'
>>> File(tmp.lower()).getCanonicalPath()
'C:\\Documents and Settings\\pekkalau\\Local Settings\\Temp'


Unfortunately I don't have time to write a new patch for this because I'm going to a business trip to China for two weeks today. I only take my work machine with me so I don't have Jython devenv with me.
msg3044 (view) Author: Philip Jenvey (pjenvey) Date: 2008-02-24.04:18:20
fixed in r4171: we use the platform dependent path module (ntpath on 
Windows) now
History
Date User Action Args
2008-02-24 04:18:20pjenveysetstatus: open -> closed
nosy: + pjenvey
resolution: fixed
messages: + msg3044
components: + Library, - None
2007-05-14 22:37:35pekka.klarckcreate