[mod_python] import_module is case sensitive even if the OS isn't

Mike Looijmans nlv11281 at natlab.research.philips.com
Mon May 14 09:20:24 EDT 2007

There is a system call that discloses whether a file system is case sensitive or not. However, the 
problem is not trivial, as there may be links to other devices in the path. For example, 
C:\mnt\somedir might point to another drive with a case sensitive filesystem, which would make the 
"mnt" word case insensitive and the "somedir" word case sensitive. I doubt that the normcase() 
function can cope with that, but i did not even know of its existance up until now.

I'm using an ext2 filesystem under Windows 2000 on a harddisk, and that's local and case sensitive 

Probably the safest thing is to open the file and ask whether it's the same file.

The same question then would apply to unix/linux systems, would you want the module loaded as 
"/real/path.py" to be considered the same module as "/softlink/path.py" ?

With all of that - i think it's reasonable to require the same module to be spelled the same way. 
The cure seems more harmful than the disease, since it allows the module importer to "see" through 
links and unexpectedly share globals in those modules.

Mike Looijmans
Philips Natlab / Topic Automation

Graham Dumpleton wrote:
> Anyone else got any comments on whether normcase() should be applied?
> I'm don't use Windows so don't really know what is best.
> ---------- Forwarded message ----------
> From: Simon Holness <simon.holness at gmail.com>
> Date: 14-May-2007 20:24
> Subject: Re: [mod_python] import_module is case sensitive even if the OS 
> isn't
> To: Graham Dumpleton <graham.dumpleton at gmail.com>
> On 5/12/07, Graham Dumpleton <graham.dumpleton at gmail.com> wrote:
>> The _check_directory() method will also need to be changed in some way
>> to ensure the integrity checks work also. Ie.
>>     if directory in sys.path:
>> need to change to:
>>     if directory in map(os.path.normcase, sys.path):
>> What happens though if Windows is being asked to mount a remote file
>> system which is case sensitive and files were being loaded from there.
>> Are files on such a file system seen as case sensitive. If they are
>> then the changes can't be made. Can anyone comment on the remote file
>> system example and how case is handled for files from that?
> Windows copes really badly, is the short answer.
> If you smb mount a case-sensitive filesystem and have a clash of paths
> based on differeing case alone, windows will only (afaict) allow you
> to navigate into the lowercase version.
> E.g. if I mount
> /work/test/file1
> /work/Test/file2
> I can never get windows to find file2 ... listing /work/Test gives file1.
>> Also, are there any native file systems on Windows that are case
>> sensitive. On Mac OS X the default file system is case insensitive,
>> but one can use case sensitive local file systems as well.
> How does normcase work in this situation?
> I assume its behaviour is based on the sensitivity of the OS not the
> filesystem in question? So for OS X I presume normcase leaves paths
> unchanged?
>> Finally, with such a change log messages and error pages are going to
>> now show lower case paths which may confuse people if the original
>> path used mixed case.
> True. Only on case-insensitive OS's of course, where it shouldn't be a
> real problem.
>> It is because of these issues that I may have originally not applied
>> os.path.normcase() to paths and basically taken the viewpoint that
>> users should just get their paths consistent in the first place as too
>> hard otherwise.
> Fair point, but unfortunately paths aren't always constructed in
> simple ways. For example, while windows is case-insensitive for path
> navigation it is case sensitive for path generation and reporting. So
> it's not a matter of the user being consistent with themselves, but
> with the OS (and potentially any other libraries) they're using. In
> the case I ran into, for example, I'd used lowercase for the drive
> letter in one place and this differed from the upper case which
> windows uses (from an auto-generated path I was using in a different
> location). Luckily I was looking into the subject of module loading
> and so noticed the path difference in the apache log notices, but I'd
> guess most people wouldn't spot this easily.
> I can certainly see your point. Maybe, if you're not keen on the code
> change being made, just a documentation change to note that you must
> be consistent with the OS with respect to case or it may load the same
> file as multiple modules?
> Cheers
> Simon
> _______________________________________________
> Mod_python mailing list
> Mod_python at modpython.org
> http://mailman.modpython.org/mailman/listinfo/mod_python

More information about the Mod_python mailing list