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

Graham Dumpleton graham.dumpleton at gmail.com
Fri May 11 20:06:57 EDT 2007


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?

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.

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.

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.

Graham

On 12/05/07, simon holness <simon.holness at gmail.com> wrote:
> Hi,
>
> I've found an apparent issue with apache.import_module() - it seems to
> key the module on a case sensitive path/name even if the operating
> system (i.e. windows) doesn't. Thus a module can be wrongly loaded
> twice by using different capitalisation in different import requests.
>
> For most applications this will not be an issue since the separately
> loaded modules will be distinct. If, however, and application is
> relying on a module being loaded only once per interpreter (yeah,
> guess which case I've got) it can cause problems.
>
> This can be trivially reproduced by importing the same module twice
> with differing pathnames.
>
> e.g.
>
> mytest.psp
> -------------------------
> <%
> mod1 = apache.import_module("c:\\work\\Webroot\\mymodule.py") # nb cap W
> mod2 = apache.import_module("c:\\work\\webroot\\mymodule.py")
> %>
> <html>
> <head><title></title></head>
> <body>go read your apache error log to see what got loaded</body>
> </html>
> ------------------------
> mymodule.py
> ------------------------
> # I'm a very boring module
> pass
> ------------------------
>
> error.log contains
> ------------------------
> ....
> ... Importing module 'c:\\work\\Webroot\\mymodule.py'
> ... Importing module 'c:\\work\\webroot\\mymodule.py'
>
> This, obviously, won't be an issue on any case-sensitive OS (*nix).
>
> Having had a quick look at the code (and run a very simple test) it
> appears that altering importer.py line 454 to
>
> file = os.path.normcase(os.path.normpath(file))
>
> fixes the issue.
> I haven't looked to see if there are other places where the path would
> need to be normalised. Possibly in _setup_current_cache() ?
>
> normcase() should be safe & correct on both types of system.
>
> Cheers
> Simon Holness
> _______________________________________________
> 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