From: <cg...@us...> - 2009-01-07 18:12:52
|
Revision: 5869 http://jython.svn.sourceforge.net/jython/?rev=5869&view=rev Author: cgroves Date: 2009-01-07 18:12:46 +0000 (Wed, 07 Jan 2009) Log Message: ----------- Use the path to the imported item as __file__, not the package path Modified Paths: -------------- trunk/jython/Lib/test/test_classpathimporter.py trunk/jython/src/org/python/core/ClasspathPyImporter.java trunk/jython/src/org/python/core/util/importer.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/Lib/test/test_classpathimporter.py =================================================================== --- trunk/jython/Lib/test/test_classpathimporter.py 2009-01-07 18:04:18 UTC (rev 5868) +++ trunk/jython/Lib/test/test_classpathimporter.py 2009-01-07 18:12:46 UTC (rev 5869) @@ -18,22 +18,24 @@ except KeyError: pass - def setClassLoaderAndCheck(self, jar): + def setClassLoaderAndCheck(self, jar, prefix): Thread.currentThread().contextClassLoader = test_support.make_jar_classloader(jar) import flat_in_jar self.assertEquals(flat_in_jar.value, 7) import jar_pkg + self.assertEquals(prefix + '/jar_pkg/__init__$py.class', jar_pkg.__file__) from jar_pkg import prefer_compiled + self.assertEquals(prefix + '/jar_pkg/prefer_compiled$py.class', prefer_compiled.__file__) self.assert_(prefer_compiled.compiled) self.assertRaises(NameError, __import__, 'flat_bad') self.assertRaises(NameError, __import__, 'jar_pkg.bad') def test_default_pyclasspath(self): - self.setClassLoaderAndCheck("classimport.jar") + self.setClassLoaderAndCheck("classimport.jar", "__pyclasspath__") def test_path_in_pyclasspath(self): sys.path = ['__pyclasspath__/Lib'] - self.setClassLoaderAndCheck("classimport_Lib.jar") + self.setClassLoaderAndCheck("classimport_Lib.jar", "__pyclasspath__/Lib") def test_main(): test_support.run_unittest(ClasspathImporterTestCase) Modified: trunk/jython/src/org/python/core/ClasspathPyImporter.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporter.java 2009-01-07 18:04:18 UTC (rev 5868) +++ trunk/jython/src/org/python/core/ClasspathPyImporter.java 2009-01-07 18:12:46 UTC (rev 5869) @@ -110,6 +110,11 @@ } @Override + protected String makeFilePath(String fullname) { + return path + fullname.replace('.', '/'); + } + + @Override protected String makePackagePath(String fullname) { return path; } Modified: trunk/jython/src/org/python/core/util/importer.java =================================================================== --- trunk/jython/src/org/python/core/util/importer.java 2009-01-07 18:04:18 UTC (rev 5868) +++ trunk/jython/src/org/python/core/util/importer.java 2009-01-07 18:12:46 UTC (rev 5869) @@ -55,6 +55,12 @@ protected abstract String makeFilename(String fullname); /** + * Given a full module name, return the potential file path including the archive (without + * extension). + */ + protected abstract String makeFilePath(String fullname); + + /** * Returns an entry for a filename from makeFilename with a potential suffix such that this * importer can make a bundle with it, or null if fullFilename doesn't exist in this importer. */ @@ -156,7 +162,7 @@ */ protected final ModuleCodeData getModuleCode(String fullname) { String path = makeFilename(fullname); - String fullPath = makePackagePath(fullname); + String fullPath = makeFilePath(fullname); if (path.length() < 0) { return null; @@ -186,7 +192,7 @@ try { codeBytes = imp.readCode(fullname, bundle.inputStream, true); } catch (IOException ioe) { - throw Py.ImportError(ioe.getMessage() + "[path=" + fullPath + searchPath + "]"); + throw Py.ImportError(ioe.getMessage() + "[path=" + fullSearchPath + "]"); } } else { codeBytes = imp.compileSource(fullname, bundle.inputStream, fullSearchPath); Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-01-07 18:04:18 UTC (rev 5868) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2009-01-07 18:12:46 UTC (rev 5869) @@ -423,6 +423,11 @@ } @Override + protected String makeFilePath(String fullname) { + return makePackagePath(fullname); + } + + @Override protected PyObject makeEntry(String fullFilename) { return files.__finditem__(fullFilename); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |