From: <pj...@us...> - 2007-08-31 22:10:19
|
Revision: 3462 http://jython.svn.sourceforge.net/jython/?rev=3462&view=rev Author: pjenvey Date: 2007-08-31 15:09:57 -0700 (Fri, 31 Aug 2007) Log Message: ----------- o split the top half of createFromPyClass into its own method: unmarshalCode o make compileSource and createFromCode public instead of package private refs patch #1783554 (zipimporter) Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2007-08-31 21:46:13 UTC (rev 3461) +++ trunk/jython/src/org/python/core/imp.java 2007-08-31 22:09:57 UTC (rev 3462) @@ -79,19 +79,7 @@ static PyObject createFromPyClass(String name, InputStream fp, boolean testing, String fileName) { - byte[] data = readBytes(fp); - int n = data.length; - - int api = (data[n - 4] << 24) + (data[n - 3] << 16) - + (data[n - 2] << 8) + data[n - 1]; - if (api != APIVersion) { - if (testing) { - return null; - } else { - throw Py.ImportError("invalid api version(" + api + " != " - + APIVersion + ") in: " + name); - } - } + byte[] data = unmarshalCode(name, fp, testing); PyCode code; try { code = BytecodeLoader.makeCode(name + "$py", data, fileName); @@ -107,7 +95,25 @@ return createFromCode(name, code, fileName); } + + public static byte[] unmarshalCode(String name, InputStream fp, + boolean testing) { + byte[] data = readBytes(fp); + int n = data.length; + int api = (data[n - 4] << 24) + (data[n - 3] << 16) + + (data[n - 2] << 8) + data[n - 1]; + if (api != APIVersion) { + if (testing) { + return null; + } else { + throw Py.ImportError("invalid api version(" + api + " != " + + APIVersion + ") in: " + name); + } + } + return data; + } + public static byte[] compileSource(String name, File file, String sourceFilename, String compiledFilename) { if (sourceFilename == null) { @@ -166,7 +172,7 @@ } } - static byte[] compileSource(String name, + public static byte[] compileSource(String name, InputStream fp, String filename) { ByteArrayOutputStream ofp = new ByteArrayOutputStream(); @@ -214,7 +220,7 @@ * Returns a module with the given name whose contents are the results of * running c. __file__ is set to whatever is in c. */ - static PyObject createFromCode(String name, PyCode c){ + public static PyObject createFromCode(String name, PyCode c){ return createFromCode(name, c, null); } @@ -226,7 +232,7 @@ * File(moduleLocation).getAbsoultePath(). If c comes from a remote file or * is a jar moduleLocation should be the full uri for c. */ - static PyObject createFromCode(String name, PyCode c, String moduleLocation) { + public static PyObject createFromCode(String name, PyCode c, String moduleLocation) { PyModule module = addModule(name); PyTableCode code = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-08-31 23:22:10
|
Revision: 3464 http://jython.svn.sourceforge.net/jython/?rev=3464&view=rev Author: pjenvey Date: 2007-08-31 16:22:05 -0700 (Fri, 31 Aug 2007) Log Message: ----------- r3462 mistakenly changed createFromPyClass's behavior with invalid byte code versions and testing == true, restore it Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2007-08-31 22:15:04 UTC (rev 3463) +++ trunk/jython/src/org/python/core/imp.java 2007-08-31 23:22:05 UTC (rev 3464) @@ -80,6 +80,9 @@ static PyObject createFromPyClass(String name, InputStream fp, boolean testing, String fileName) { byte[] data = unmarshalCode(name, fp, testing); + if (testing && data == null) { + return null; + } PyCode code; try { code = BytecodeLoader.makeCode(name + "$py", data, fileName); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-12-15 00:23:03
|
Revision: 3806 http://jython.svn.sourceforge.net/jython/?rev=3806&view=rev Author: pjenvey Date: 2007-12-14 16:22:58 -0800 (Fri, 14 Dec 2007) Log Message: ----------- whitespace Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2007-12-14 13:02:53 UTC (rev 3805) +++ trunk/jython/src/org/python/core/imp.java 2007-12-15 00:22:58 UTC (rev 3806) @@ -479,7 +479,7 @@ sourceFile.getAbsolutePath()); } // If no source, try loading precompiled - Py.writeDebug(IMPORT_LOG, "trying precompiled with no source" + Py.writeDebug(IMPORT_LOG, "trying precompiled with no source " + compiledFile.getPath()); if(compiledFile.isFile() && caseok(compiledFile, compiledName, compiledName.length())) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-12-17 00:12:06
|
Revision: 3823 http://jython.svn.sourceforge.net/jython/?rev=3823&view=rev Author: pjenvey Date: 2007-12-16 16:12:03 -0800 (Sun, 16 Dec 2007) Log Message: ----------- use a module's compiled source filename for its __file__ when it's loaded from there, like CPython does Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2007-12-16 22:19:44 UTC (rev 3822) +++ trunk/jython/src/org/python/core/imp.java 2007-12-17 00:12:03 UTC (rev 3823) @@ -468,7 +468,7 @@ PyObject ret = createFromPyClass(modName, makeStream(compiledFile), true, - sourceFile.getAbsolutePath()); + compiledFile.getAbsolutePath()); if(ret != null) { return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2007-12-17 00:28:37
|
Revision: 3824 http://jython.svn.sourceforge.net/jython/?rev=3824&view=rev Author: pjenvey Date: 2007-12-16 16:28:36 -0800 (Sun, 16 Dec 2007) Log Message: ----------- woops, revert r3823 as it breaks tracebacks. this will need more work Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2007-12-17 00:12:03 UTC (rev 3823) +++ trunk/jython/src/org/python/core/imp.java 2007-12-17 00:28:36 UTC (rev 3824) @@ -468,7 +468,7 @@ PyObject ret = createFromPyClass(modName, makeStream(compiledFile), true, - compiledFile.getAbsolutePath()); + sourceFile.getAbsolutePath()); if(ret != null) { return ret; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-01-03 23:51:03
|
Revision: 3962 http://jython.svn.sourceforge.net/jython/?rev=3962&view=rev Author: pjenvey Date: 2008-01-03 15:51:02 -0800 (Thu, 03 Jan 2008) Log Message: ----------- o patch #1861974 from tristanlk: fix packages' __file__ when imported from byte code. fixes #1861973 o doc the fact that __file__ is technically wrong in that situation Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2008-01-03 23:21:00 UTC (rev 3961) +++ trunk/jython/src/org/python/core/imp.java 2008-01-03 23:51:02 UTC (rev 3962) @@ -451,6 +451,12 @@ } if (sourceFile.isFile() && caseok(sourceFile, sourceName, sourceName.length())) { + String filename; + if (pkg) { + filename = new File(new File(displayDirName, name), sourceName).getPath(); + } else { + filename = new File(displayDirName, sourceName).getPath(); + } if(compiledFile.isFile() && caseok(compiledFile, compiledName, compiledName.length())) { Py.writeDebug(IMPORT_LOG, "trying precompiled " @@ -458,7 +464,9 @@ long pyTime = sourceFile.lastModified(); long classTime = compiledFile.lastModified(); if(classTime >= pyTime) { - String filename = new File(displayDirName, sourceName).getPath(); + // XXX: filename should use compiledName here (not + // sourceName), but this currently breaks source + // code printed out in tracebacks PyObject ret = createFromPyClass(modName, makeStream(compiledFile), true, filename); if(ret != null) { @@ -466,12 +474,6 @@ } } } - String filename; - if (pkg) { - filename = new File(new File(displayDirName, name), sourceName).getPath(); - } else { - filename = new File(displayDirName, sourceName).getPath(); - } return createFromSource(modName, makeStream(sourceFile), filename, compiledFile.getPath()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-03-08 05:53:52
|
Revision: 4193 http://jython.svn.sourceforge.net/jython/?rev=4193&view=rev Author: pjenvey Date: 2008-03-07 21:53:48 -0800 (Fri, 07 Mar 2008) Log Message: ----------- fix __import__ to actually handle the fromlist argument fixes #1006 Modified Paths: -------------- trunk/jython/src/org/python/core/imp.java Modified: trunk/jython/src/org/python/core/imp.java =================================================================== --- trunk/jython/src/org/python/core/imp.java 2008-03-07 00:13:52 UTC (rev 4192) +++ trunk/jython/src/org/python/core/imp.java 2008-03-08 05:53:48 UTC (rev 4193) @@ -683,6 +683,18 @@ if (top) { return topMod; } + + if (fromlist != null && fromlist != Py.None) { + StringBuffer modNameBuffer = new StringBuffer(name); + for (PyObject submodName : fromlist.asIterable()) { + if (mod.__findattr__(submodName.toString()) != null + || submodName.toString().equals("*")) { + continue; + } + String fullName = modNameBuffer.toString() + "." + submodName.toString(); + import_next(mod, modNameBuffer, submodName.toString(), fullName, null); + } + } return mod; } @@ -759,54 +771,21 @@ */ public static PyObject[] importFromAs(String mod, String[] names, String[] asnames, PyFrame frame) { - // StringBuffer sb = new StringBuffer(); - // for(int i=0; i<names.length; i++) - // sb.append(names[i] + " "); - // System.out.println("importFrom(" + mod + ", [" + sb + "]"); + PyObject[] pyNames = new PyObject[names.length]; + for (int i = 0; i < names.length; i++) { + pyNames[i] = Py.newString(names[i]); + } - PyObject[] pynames = new PyObject[names.length]; - for (int i = 0; i < names.length; i++) - pynames[i] = Py.newString(names[i]); - - PyObject module = __builtin__.__import__(mod, frame.f_globals, frame - .getf_locals(), new PyTuple(pynames)); + PyObject module = __builtin__.__import__(mod, frame.f_globals, frame.getf_locals(), + new PyTuple(pyNames)); PyObject[] submods = new PyObject[names.length]; - List wrongNames = new ArrayList(1); for (int i = 0; i < names.length; i++) { PyObject submod = module.__findattr__(names[i]); if (submod == null) { - String submodName = mod + '.' + names[i]; - submod = __builtin__.__import__(submodName, null, null, nonEmptyFromlist); + throw Py.ImportError("cannot import name " + names[i]); } - if (submod == null) { - if (module instanceof PyJavaPackage) { - if (JavaImportHelper.tryAddPackage(mod + "." + names[i], null)) { - submod = module.__findattr__(names[i]); - } - } - } - if (submod == null) { - wrongNames.add(names[i]); - } else { - submods[i] = submod; - } + submods[i] = submod; } - int size = wrongNames.size(); - if (size > 0) { - StringBuffer buf = new StringBuffer(20); - buf.append("cannot import name"); - if (size > 1) { - buf.append("s"); - } - Iterator wrongNamesIterator = wrongNames.iterator(); - buf.append(" "); - buf.append(wrongNamesIterator.next()); - while (wrongNamesIterator.hasNext()) { - buf.append(", "); - buf.append(wrongNamesIterator.next()); - } - throw Py.ImportError(buf.toString()); - } return submods; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |