From: Finn B. <bc...@us...> - 2001-11-27 11:22:10
|
Update of /cvsroot/jython/jython/org/python/core In directory usw-pr-cvs1:/tmp/cvs-serv5608 Modified Files: imp.java SyspathArchive.java Log Message: Make the ".zip file on sys.path" support match the expected behaviour in CPython-2.3. This trigger for a .zip/.jar file search is: '/path/to/file.zip' or '/path/to/file.zip/path/in/archive' Index: imp.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/imp.java,v retrieving revision 2.54 retrieving revision 2.55 diff -C2 -d -r2.54 -r2.55 *** imp.java 2001/10/28 17:13:43 2.54 --- imp.java 2001/11/27 11:22:07 2.55 *************** *** 343,356 **** if (isDir) return false; ! String dir = entry.toString(); ! int idx = dir.indexOf('!'); ! if (idx > 0) { ! dir = dir.substring(0, idx); ! } ! if (dir.length() < 5) { ! return false; ! } ! String ext = dir.substring(dir.length() - 4); ! return ext.equalsIgnoreCase(".zip") || ext.equalsIgnoreCase(".jar"); } --- 343,347 ---- if (isDir) return false; ! return SyspathArchive.getArchiveName(entry.toString()) != null; } Index: SyspathArchive.java =================================================================== RCS file: /cvsroot/jython/jython/org/python/core/SyspathArchive.java,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SyspathArchive.java 2001/07/26 20:23:09 1.1 --- SyspathArchive.java 2001/11/27 11:22:07 1.2 *************** *** 9,16 **** public SyspathArchive(String archiveName) throws IOException { super(archiveName); ! int idx = archiveName.indexOf('!'); ! if (idx > 0) { ! archiveName = archiveName.substring(0, idx); ! } zipFile = new ZipFile(new File(archiveName)); Py.getSystemState().packageManager.addJar(archiveName); --- 9,13 ---- public SyspathArchive(String archiveName) throws IOException { super(archiveName); ! archiveName = getArchiveName(archiveName); zipFile = new ZipFile(new File(archiveName)); Py.getSystemState().packageManager.addJar(archiveName); *************** *** 22,37 **** } public SyspathArchive makeSubfolder(String folder) { ! return new SyspathArchive(zipFile, super.toString() + "!" + folder); } private String makeEntry(String entry) { String archive = super.toString(); ! int idx = archive.indexOf('!'); ! if (idx < 0) { return entry; } - String folder = archive.substring(idx+1); - return folder + "/" + entry; } --- 19,54 ---- } + static String getArchiveName(String dir) { + String lowerName = dir.toLowerCase(); + int idx = lowerName.indexOf(".zip"); + if (idx < 0) { + idx = lowerName.indexOf(".jar"); + } + if (idx < 0) { + return null; + } + + if (idx == dir.length() - 4) { + return dir; + } + char ch = dir.charAt(idx+4); + if (ch == File.separatorChar || ch == '/') { + return dir.substring(0, idx+4); + } + return null; + } + public SyspathArchive makeSubfolder(String folder) { ! return new SyspathArchive(zipFile, super.toString() + "/" + folder); } private String makeEntry(String entry) { String archive = super.toString(); ! String folder = getArchiveName(super.toString()); ! if (archive.length() == folder.length()) { return entry; + } else { + return archive.substring(folder.length()+1) + "/" + entry; } } |