From: <bc...@wo...> - 2001-05-28 18:01:52
|
On Mon, 28 May 2001 18:39:39 +0200 (MET DST), you wrote: >Hi > >[Finn on jython-users] >> >> >I have the following situation, which strikes me as bizarre: >> >> I have been unable to reproduce the problem with just your example >> (included below). OTOH case-sensitive import doesn't work right (when >> compared to all versions of CPython) on case-insensitive filesystems. >> >I'm asking myself if it would make sense to implement the new CPython >policy also in Jython Yes. >(anyway, that would be a low prio thing) > >File.canonicalPath seems to do the right thing (at least under Windows) >in order to implement that. Yep. Below is my suggested patch. I'm a little worried about what File.getCanonicalFile() return on platforms other than windows/unix. regards, finn Index: registry =================================================================== RCS file: /cvsroot/jython/jython/registry,v retrieving revision 2.13 diff -u -r2.13 registry --- registry 2001/05/28 16:56:37 2.13 +++ registry 2001/05/28 16:56:56 @@ -55,6 +55,14 @@ #python.options.internalTablesImpl = soft #python.options.internalTablesImpl = weak +# Setting this to true will force Jython will use the first module +# found on sys.path where java File.isFile() returns true. +# Setting this to true has no effect on unix-type filesystems. +# On Windows/HPS+ systems, setting it to true will enable Jython-2.0 +# behaviour. +python.options.caseok = false + + # Use this registry entry to control the list of builtin modules; you # can add, remove, or override builtin modules. The value for this # registry key is a comma separated list of module entries, each entry Index: org/python/core/Options.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/Options.java,v retrieving revision 2.7 diff -u -r2.7 Options.java --- org/python/core/Options.java 2001/03/04 18:04:31 2.7 +++ org/python/core/Options.java 2001/05/28 16:56:59 @@ -73,6 +73,14 @@ */ public static String proxyDebugDirectory = null; + /** + * If true, Jython will use the first module found on sys.path + * where java File.isFile() returns true. Setting this to true + * have no effect on unix-type filesystems. On Windows/HPS+ + * systems setting it to true will enable Jython-2.0 behaviour. + */ + public static boolean caseok = false; + // // ####### END OF OPTIONS // @@ -143,6 +151,10 @@ throw Py.ValueError("Illegal verbose option setting: '"+ prop+"'"); } + + Options.caseok = + getBooleanOption("options.caseok", Options.pollStandardIn); + // additional initializations which must happen after the registry // is guaranteed to be initialized. JavaAccessibility.initialize(); Index: org/python/core/imp.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/imp.java,v retrieving revision 2.42 diff -u -r2.42 imp.java --- org/python/core/imp.java 2001/05/27 18:49:15 2.42 +++ org/python/core/imp.java 2001/05/28 16:57:29 @@ -294,7 +294,7 @@ // First check for packages File dir = new File(dirName, name); - if (dir.isDirectory() && + if (dir.isDirectory() && caseok(dir, name) && (new File(dir, "__init__.py").isFile() || new File(dir, "__init__$py.class").isFile())) { @@ -313,8 +313,8 @@ File classFile = new File(dirName, className); Py.writeDebug("import", "trying source " + pyFile.getPath()); - if (pyFile.isFile()) { - if (classFile.isFile()) { + if (pyFile.isFile() && caseok(pyFile, pyName)) { + if (classFile.isFile() && caseok(classFile, className)) { Py.writeDebug("import", "trying precompiled " + classFile.getPath()); long pyTime = pyFile.lastModified(); @@ -333,12 +333,22 @@ // If no source, try loading precompiled Py.writeDebug("import", "trying " + classFile.getPath()); - if (classFile.isFile()) { + if (classFile.isFile() && caseok(classFile, className)) { return createFromPyClass(modName, makeStream(classFile), false, classFile.getPath()); } } return null; + } + + private static boolean caseok(File file, String filename) { + if (Options.caseok) + return true; + try { + return filename.equals(file.getCanonicalFile().getName()); + } catch (IOException exc) { + return false; + } } static PyObject loadFromClassLoader(String name, |