From: <fwi...@us...> - 2007-06-06 18:28:50
|
Revision: 3249 http://svn.sourceforge.net/jython/?rev=3249&view=rev Author: fwierzbicki Date: 2007-06-06 11:28:48 -0700 (Wed, 06 Jun 2007) Log Message: ----------- svn merge -r 3188:3202 https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython Modified Paths: -------------- branches/2.3/Lib/test/regrtest.py branches/2.3/NEWS branches/2.3/build.xml branches/2.3/src/org/python/compiler/Module.java branches/2.3/src/org/python/core/CollectionIter.java branches/2.3/src/org/python/core/CollectionIter2.java branches/2.3/src/org/python/core/Py.java branches/2.3/src/org/python/core/PyObject.java branches/2.3/src/org/python/core/PySystemState.java branches/2.3/src/org/python/core/__builtin__.java branches/2.3/src/org/python/modules/py_compile.java branches/2.3/src/org/python/util/JLineConsole.java branches/2.3/src/org/python/util/PyServlet.java branches/2.3/src/org/python/util/PythonInterpreter.java Modified: branches/2.3/Lib/test/regrtest.py =================================================================== --- branches/2.3/Lib/test/regrtest.py 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/Lib/test/regrtest.py 2007-06-06 18:28:48 UTC (rev 3249) @@ -1054,7 +1054,6 @@ test_cpickle test_descr test_descrtut - test_doctest2 test_frozen test_marshal test_new @@ -1066,7 +1065,6 @@ test_threaded_import test_trace test_weakref - test_zlib ''', } Modified: branches/2.3/NEWS =================================================================== --- branches/2.3/NEWS 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/NEWS 2007-06-06 18:28:48 UTC (rev 3249) @@ -31,6 +31,7 @@ - [ 663592 ] Problems calling an overriden class in the constructor - [ 448398 ] open('test.txt', 'w').write('test') fails - [ 1671373 ] A "$_PyInner.class" file in a package causes import to fail + - [ 1671431 ] dir function does not work with database connection object Patches applied - [ 1681774 ] str.decode, unicode.encode and str(u'') fixes - [ 1682423 ] Convert PyModule to a new-style class Modified: branches/2.3/build.xml =================================================================== --- branches/2.3/build.xml 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/build.xml 2007-06-06 18:28:48 UTC (rev 3249) @@ -626,6 +626,7 @@ <patternset> <includesfile name="${jython.base.dir}/build.Lib.include.properties" /> <exclude name="test/output/test_sax"/> + <exclude name="test/output/test_zlib"/> </patternset> </fileset> </copy> Modified: branches/2.3/src/org/python/compiler/Module.java =================================================================== --- branches/2.3/src/org/python/compiler/Module.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/compiler/Module.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -555,19 +555,15 @@ } public void addMain() throws IOException { - Code c = classfile.addMethod("main", "(" + $str + ")V", - ClassFile.PUBLIC | ClassFile.STATIC); - - - int mref_self = c.pool.Fieldref(classfile.name, - "self", - "L"+classfile.name+";"); - c.getstatic(mref_self); + Code c = classfile.addMethod("main", "(" + $strArr + ")V", + ClassFile.PUBLIC | ClassFile.STATIC); + c.new_(c.pool.Class(classfile.name)); + c.dup(); + c.ldc(classfile.name); + c.invokespecial(c.pool.Methodref(classfile.name, "<init>", "(" + $str + ")V")); c.aload(0); - c.invokestatic(c.pool.Methodref( - "org/python/core/Py", - "do_main", - "(" + $pyRunnable + $strArr + ")V")); + c.invokestatic(c.pool.Methodref("org/python/core/Py", "runMain", "(" + + $pyRunnable + $strArr + ")V")); c.return_(); } @@ -632,7 +628,7 @@ public void write(OutputStream stream) throws IOException { addInit(); addRunnable(); - //addMain(); + addMain(); addFunctions(); Modified: branches/2.3/src/org/python/core/CollectionIter.java =================================================================== --- branches/2.3/src/org/python/core/CollectionIter.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/core/CollectionIter.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -2,7 +2,9 @@ package org.python.core; -import java.util.*; +import java.util.Dictionary; +import java.util.Enumeration; +import java.util.Vector; class CollectionIter extends PyObject { PyObject findCollection(Object object) { Modified: branches/2.3/src/org/python/core/CollectionIter2.java =================================================================== --- branches/2.3/src/org/python/core/CollectionIter2.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/core/CollectionIter2.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -2,7 +2,10 @@ package org.python.core; -import java.util.*; +import java.lang.reflect.Method; +import java.util.Collection; +import java.util.Iterator; +import java.util.Map; class CollectionIter2 extends CollectionIter { CollectionIter2() throws Exception { @@ -19,7 +22,18 @@ if (object instanceof Iterator) { return new IteratorIter(((Iterator) object)); } - + try { + // TODO - Once we depend on Java 5 we can replace this with a check + // for the Iterable interface + Method m = object.getClass().getMethod("iterator", new Class[0]); + if (Iterator.class.isAssignableFrom(m.getReturnType())) { + return new IteratorIter((Iterator) m.invoke(object, + new Object[0])); + } + } catch (Exception e) { + // Looks like one of the many reflection based exceptions ocurred so + // we won't get an Iterator this way + } return null; } } Modified: branches/2.3/src/org/python/core/Py.java =================================================================== --- branches/2.3/src/org/python/core/Py.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/core/Py.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -1,10 +1,21 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import org.python.parser.ast.modType; +import java.io.ByteArrayOutputStream; +import java.io.File; +import java.io.FileOutputStream; +import java.io.InputStream; +import java.io.ObjectStreamException; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.Serializable; +import java.io.StreamCorruptedException; +import java.io.Writer; import java.lang.reflect.InvocationTargetException; -import java.io.*; +import org.python.compiler.Module; +import org.python.parser.ast.modType; + public final class Py { static boolean frozen; @@ -927,6 +938,27 @@ Py.runCode(code, dict, dict); } + /** + * Initializes a default PythonInterpreter and runs the code from + * {@link PyRunnable#getMain} as __main__ + * + * Called by the code generated in {@link Module#addMain()} + */ + public static void runMain(PyRunnable main, String[] args) throws Exception + { + initProperties(args, null, null, null, null, main.getClass() + .getClassLoader()); + try { + imp.createFromCode("__main__", main.getMain()); + } catch (PyException e) { + Py.getSystemState().callExitFunc(); + if (Py.matchException(e, Py.SystemExit)) + return; + throw e; + } + Py.getSystemState().callExitFunc(); + } + public static void runMain(Class mainClass, String[] args, String[] packages, String[] props, @@ -1719,9 +1751,8 @@ { try { ByteArrayOutputStream ostream = new ByteArrayOutputStream(); - org.python.compiler.Module.compile(node, ostream, name, filename, - linenumbers, printResults, - false,cflags); + Module.compile(node, ostream, name, filename, linenumbers, + printResults, false, cflags); saveClassFile(name, ostream); @@ -1753,8 +1784,8 @@ public static PyObject compile_command_flags(String string, String filename, String kind, CompilerFlags cflags,boolean stdprompt) { - org.python.parser.ast.modType node = - parser.partialParse(string+"\n", kind, filename, cflags, stdprompt); + modType node = parser.partialParse(string + "\n", kind, filename, + cflags, stdprompt); if (node == null) return Py.None; Modified: branches/2.3/src/org/python/core/PyObject.java =================================================================== --- branches/2.3/src/org/python/core/PyObject.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/core/PyObject.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -1119,8 +1119,9 @@ for (; (name = lst_iter.__iternext__())!= null; ) { accum.__setitem__(name, Py.None); } + } else { + accum.update(obj); } - accum.update(obj); } protected void __rawdir__(PyDictionary accum) { Modified: branches/2.3/src/org/python/core/PySystemState.java =================================================================== --- branches/2.3/src/org/python/core/PySystemState.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/core/PySystemState.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -110,9 +110,9 @@ exit(Py.None); } - public PyObject modules; // = new PyStringMap(); + public PyObject modules; public PyList path; - public PyObject builtins; + public static PyObject builtins; public PyList meta_path; public PyList path_hooks; @@ -279,8 +279,6 @@ if(builtins == null){ builtins = new PyStringMap(); __builtin__.fillWithBuiltins(builtins); - }else{ - builtins = Py.defaultSystemState.builtins; } PyModule __builtin__ = new PyModule("__builtin__", builtins); modules.__setitem__("__builtin__", __builtin__); @@ -477,7 +475,7 @@ if (classLoader != null) Py.defaultSystemState.setClassLoader(classLoader); - Py.initClassExceptions(Py.defaultSystemState.builtins); + Py.initClassExceptions(PySystemState.builtins); // Make sure that Exception classes have been loaded new PySyntaxError("", 1,1,"", ""); } Modified: branches/2.3/src/org/python/core/__builtin__.java =================================================================== --- branches/2.3/src/org/python/core/__builtin__.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/core/__builtin__.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -305,7 +305,6 @@ public class __builtin__ { public static void fillWithBuiltins(PyObject dict) { /* newstyle */ - dict.__setitem__("object", PyType.fromClass(PyObject.class)); dict.__setitem__("type", PyType.fromClass(PyType.class)); dict.__setitem__("bool", PyType.fromClass(PyBoolean.class)); Modified: branches/2.3/src/org/python/modules/py_compile.java =================================================================== --- branches/2.3/src/org/python/modules/py_compile.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/modules/py_compile.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -24,9 +24,20 @@ if (dot != -1) { name = name.substring(0, dot); } + // Make the compiled classfile's name the fully qualified with a package by + // walking up the directory tree looking for __init__.py files. Don't + // check for __init__$py.class since we're compiling source here and the + // existence of a class file without corresponding source probably doesn't + // indicate a package. + File dir = file.getParentFile(); + while (dir != null && (new File(dir, "__init__.py").exists())) { + name = dir.getName() + "." + name; + dir = dir.getParentFile(); + } byte[] bytes = org.python.core.imp.compileSource(name, file, dfile, cfile); - org.python.core.imp.cacheCompiledSource(filename, null, bytes); + org.python.core.imp.cacheCompiledSource(filename, cfile, bytes); return bytes.length > 0; } + } Modified: branches/2.3/src/org/python/util/JLineConsole.java =================================================================== --- branches/2.3/src/org/python/util/JLineConsole.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/util/JLineConsole.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -44,5 +44,5 @@ return line.endsWith("\n") ? line.substring(0, line.length() - 1) : line; } - private ConsoleReader reader; + protected ConsoleReader reader; } Modified: branches/2.3/src/org/python/util/PyServlet.java =================================================================== --- branches/2.3/src/org/python/util/PyServlet.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/util/PyServlet.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -94,20 +94,17 @@ File.separator + "lib"); } - PythonInterpreter.initialize(baseProps, props, - new String[0]); + PySystemState.initialize(baseProps, props, new String[0]); reset(); - PySystemState sys = Py.getSystemState(); - sys.add_package("javax.servlet"); - sys.add_package("javax.servlet.http"); - sys.add_package("javax.servlet.jsp"); - sys.add_package("javax.servlet.jsp.tagext"); + PySystemState.add_package("javax.servlet"); + PySystemState.add_package("javax.servlet.http"); + PySystemState.add_package("javax.servlet.jsp"); + PySystemState.add_package("javax.servlet.jsp.tagext"); - sys.add_classdir(rootPath + "WEB-INF" + - File.separator + "classes"); + PySystemState.add_classdir(rootPath + "WEB-INF" + File.separator + "classes"); - sys.add_extdir(rootPath + "WEB-INF" + File.separator + "lib", true); + PySystemState.add_extdir(rootPath + "WEB-INF" + File.separator + "lib", true); } /** @@ -122,8 +119,7 @@ { req.setAttribute("pyservlet", this); - String spath = (String)req.getAttribute( - "javax.servlet.include.servlet_path"); + String spath = (String) req.getAttribute("javax.servlet.include.servlet_path"); if (spath == null) { spath = ((HttpServletRequest) req).getServletPath(); if (spath == null || spath.length() == 0) { @@ -147,11 +143,11 @@ destroyCache(); interp = new PythonInterpreter(null, new PySystemState()); cache.clear(); + PySystemState sys = Py.getSystemState(); sys.path.append(new PyString(rootPath)); - String modulesDir = rootPath + "WEB-INF" + - File.separator + "jython"; + String modulesDir = rootPath + "WEB-INF" + File.separator + "jython"; sys.path.append(new PyString(modulesDir)); } @@ -187,21 +183,20 @@ try { interp.execfile(path); PyObject cls = interp.get(name); - if (cls == null) - throw new ServletException("No callable (class or function) "+ - "named " + name + " in " + path); - + if (cls == null) { + throw new ServletException("No callable (class or function) named " + name + " in " + + path); + } PyObject pyServlet = cls.__call__(); Object o = pyServlet.__tojava__(HttpServlet.class); - if (o == Py.NoConversion) - throw new ServletException("The value from " + name + - "must extend HttpServlet"); + if (o == Py.NoConversion) { + throw new ServletException("The value from " + name + " must extend HttpServlet"); + } servlet = (HttpServlet)o; servlet.init(getServletConfig()); } catch (PyException e) { - throw new ServletException("Could not create "+ - "Jython servlet" + e.toString()); + throw new ServletException(e); } CacheEntry entry = new CacheEntry(servlet, file.lastModified()); cache.put(path, entry); Modified: branches/2.3/src/org/python/util/PythonInterpreter.java =================================================================== --- branches/2.3/src/org/python/util/PythonInterpreter.java 2007-05-30 05:19:19 UTC (rev 3248) +++ branches/2.3/src/org/python/util/PythonInterpreter.java 2007-06-06 18:28:48 UTC (rev 3249) @@ -19,20 +19,19 @@ protected CompilerFlags cflags = null; /** - * Initialize the jython runtime. This method should only be - * called once, and should be call before any other python objects - * are created (included a PythonInterpreter). - * - * @param preProperties A set of properties. Typically - * System.getProperties() is used. - * @param postProperties An other set of properties. Values like - * python.home, python.path and all other - * values from the registry files can be - * added to this property set. PostProperties - * will override system properties and - * registry properties. - * @param argv Command line argument. These values will - * assigned to sys.argv. + * Initializes the jython runtime. This should only be called once, and + * should be called before any other python objects are created (including a + * PythonInterpreter). + * + * @param preProperties + * A set of properties. Typically System.getProperties() is used. + * @param postProperties + * An other set of properties. Values like python.home, + * python.path and all other values from the registry files can + * be added to this property set. PostProperties will override + * system properties and registry properties. + * @param argv + * Command line argument. These values will assigned to sys.argv. */ public static void initialize(Properties preProperties, Properties postProperties, @@ -60,7 +59,6 @@ } public PythonInterpreter(PyObject dict, PySystemState systemState) { - PySystemState.initialize(); if (dict == null) dict = new PyStringMap(); if (systemState == null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |