From: <pj...@us...> - 2008-08-20 00:28:58
|
Revision: 5212 http://jython.svn.sourceforge.net/jython/?rev=5212&view=rev Author: pjenvey Date: 2008-08-20 00:28:55 +0000 (Wed, 20 Aug 2008) Log Message: ----------- o rename unmarshalCode -> readCode, as it doesn't relate to Python's marshal o zipimport shouldn't cacheCompiledSource (it's just been silently failing), and use java enums Modified Paths: -------------- trunk/jython/Lib/pkgutil.py trunk/jython/src/org/python/core/imp.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/Lib/pkgutil.py =================================================================== --- trunk/jython/Lib/pkgutil.py 2008-08-19 23:34:29 UTC (rev 5211) +++ trunk/jython/Lib/pkgutil.py 2008-08-20 00:28:55 UTC (rev 5212) @@ -22,7 +22,7 @@ # accessed by _imp here def read_jython_code(fullname, file, filename): - data = _imp.unmarshalCode(filename, file, False) + data = _imp.readCode(filename, file, False) return BytecodeLoader.makeCode(fullname + "$py", data, filename) def simplegeneric(func): Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2008-08-19 23:34:29 UTC (rev 5211) +++ trunk/jython/src/org/python/core/imp.java 2008-08-20 00:28:55 UTC (rev 5212) @@ -87,7 +87,7 @@ static PyObject createFromPyClass(String name, InputStream fp, boolean testing, String fileName) { - byte[] data = unmarshalCode(name, fp, testing); + byte[] data = readCode(name, fp, testing); if (testing && data == null) { return null; } @@ -107,8 +107,7 @@ return createFromCode(name, code, fileName); } - public static byte[] unmarshalCode(String name, InputStream fp, - boolean testing) { + public static byte[] readCode(String name, InputStream fp, boolean testing) { byte[] data = readBytes(fp); int n = data.length; Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-08-19 23:34:29 UTC (rev 5211) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-08-20 00:28:55 UTC (rev 5212) @@ -6,6 +6,7 @@ import java.io.InputStream; import java.util.Date; import java.util.Enumeration; +import java.util.EnumSet; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -51,19 +52,22 @@ /** zip_searchorder defines how we search for a module in the Zip * archive */ - static final int IS_SOURCE = 0; - static final int IS_BYTECODE = 1; - static final int IS_PACKAGE = 2; + static enum EntryType { + IS_SOURCE, IS_BYTECODE, IS_PACKAGE + }; static final SearchOrderEntry[] zip_searchorder = new SearchOrderEntry[] { - new SearchOrderEntry(File.separator + "__init__$py.class", IS_PACKAGE | IS_BYTECODE), - new SearchOrderEntry(File.separator + "__init__.py", IS_PACKAGE | IS_SOURCE), - new SearchOrderEntry("$py.class", IS_BYTECODE), - new SearchOrderEntry(".py", IS_SOURCE), - new SearchOrderEntry("", 0) + new SearchOrderEntry(File.separator + "__init__$py.class", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_BYTECODE)), + new SearchOrderEntry(File.separator + "__init__.py", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_SOURCE)), + new SearchOrderEntry("$py.class", EnumSet.of(EntryType.IS_BYTECODE)), + new SearchOrderEntry(".py", EnumSet.of(EntryType.IS_SOURCE)), }; /** Module information */ - static enum ModuleInfo {ERROR, NOT_FOUND, MODULE, PACKAGE}; + static enum ModuleInfo { + ERROR, NOT_FOUND, MODULE, PACKAGE + }; /** Pathname of the Zip archive */ @ExposedGet @@ -366,7 +370,7 @@ if (tocEntry == null) continue; - if ((entry.type & IS_PACKAGE) == IS_PACKAGE) { + if (entry.type.contains(EntryType.IS_PACKAGE)) { return ModuleInfo.PACKAGE; } return ModuleInfo.MODULE; @@ -399,8 +403,8 @@ continue; } - boolean ispackage = (entry.type & IS_PACKAGE) == IS_PACKAGE; - boolean isbytecode = (entry.type & IS_BYTECODE) == IS_BYTECODE; + boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); + boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); if (isbytecode && isOutdatedBytecode(searchPath, tocEntry)) { continue; @@ -410,7 +414,7 @@ ZipBundle zipBundle = getDataStream(searchPath); byte[] codeBytes; if (isbytecode) { - codeBytes = imp.unmarshalCode(fullname, zipBundle.inputStream, true); + codeBytes = imp.readCode(fullname, zipBundle.inputStream, true); } else { codeBytes = imp.compileSource(fullname, zipBundle.inputStream, pathToEntry); @@ -422,7 +426,6 @@ continue; } - imp.cacheCompiledSource(pathToEntry, null, codeBytes); PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, pathToEntry); return new ModuleCodeData(code, ispackage, pathToEntry); } @@ -661,9 +664,9 @@ */ protected static class SearchOrderEntry { public String suffix; - public int type; + public EnumSet type; - public SearchOrderEntry(String suffix, int type) { + public SearchOrderEntry(String suffix, EnumSet type) { this.suffix = suffix; this.type = type; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |