You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2009-01-28 20:32:28
|
Revision: 5996 http://jython.svn.sourceforge.net/jython/?rev=5996&view=rev Author: fwierzbicki Date: 2009-01-28 20:32:23 +0000 (Wed, 28 Jan 2009) Log Message: ----------- move JavaPackage sets and gets to BasePackageManager. Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-28 18:20:59 UTC (rev 5995) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-28 20:32:23 UTC (rev 5996) @@ -46,7 +46,12 @@ // for default cache (local fs based) impl protected File cachedir; - public BasePackageManager(JavaPackage top, File cachedir, boolean respectJavaAccessibility, List<String> classpaths, List<String> jarpaths) { + public BasePackageManager(JavaPackage top, + File cachedir, + boolean respectJavaAccessibility, + List<String> classpaths, + List<String> jarpaths) { + this.respectJavaAccessibility = respectJavaAccessibility; this.searchPath = new ArrayList(); this.topLevelPackage = top; @@ -65,9 +70,23 @@ } public abstract Object makeJavaPackage(String name, String classes, String jarfile); - public abstract Class findClass(String pkg, String name, String reason); + /** + * @return the topLevelPackage + */ + public JavaPackage getTopLevelPackage() { + return topLevelPackage; + } + + /** + * @param topLevelPackage the topLevelPackage to set + */ + public void setTopLevelPackage(JavaPackage topLevelPackage) { + this.topLevelPackage = topLevelPackage; + } + + public void addJar(String jarfile, boolean cache) { addJarToPackages(new File(jarfile), cache); if (cache) { Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-28 18:20:59 UTC (rev 5995) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-28 20:32:23 UTC (rev 5996) @@ -45,7 +45,11 @@ public class SysPackageManager extends BasePackageManager { public SysPackageManager(File cachedir, Properties registry) { - super(new PyJavaPackage(""), cachedir, Options.respectJavaAccessibility, findClassPaths(registry), findJarPaths(registry)); + super(new PyJavaPackage(""), + cachedir, + Options.respectJavaAccessibility, + findClassPaths(registry), + findJarPaths(registry)); } private static List<String> findClassPaths(Properties registry) { @@ -86,20 +90,6 @@ return paths; } - /** - * @return the topLevelPackage - */ - public JavaPackage getTopLevelPackage() { - return topLevelPackage; - } - - /** - * @param topLevelPackage the topLevelPackage to set - */ - public void setTopLevelPackage(JavaPackage topLevelPackage) { - this.topLevelPackage = topLevelPackage; - } - public Class findClass(String pkg, String name, String reason) { if (pkg != null && pkg.length() > 0) { name = pkg + '.' + name; @@ -161,7 +151,6 @@ return false; } - /** * Helper for {@link #doDir(PyJavaPackage,boolean,boolean)}. Scans for * package jpkg content over the directories in path. Add to ret the founded @@ -271,8 +260,6 @@ return basic; } - /* From old PackageManager */ - /** * Basic helper implementation of {@link #doDir}. It merges information * from jpkg {@link JavaPackage#clsSet} and {@link JavaPackage#__dict__}. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-28 18:21:03
|
Revision: 5995 http://jython.svn.sourceforge.net/jython/?rev=5995&view=rev Author: fwierzbicki Date: 2009-01-28 18:20:59 +0000 (Wed, 28 Jan 2009) Log Message: ----------- more purging of python-ness from package caching -- unfortunately means more casting internally. Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/JavaImporter.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyModule.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/JavaImporter.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/JavaImporter.java 2009-01-28 17:42:03 UTC (rev 5994) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/JavaImporter.java 2009-01-28 18:20:59 UTC (rev 5995) @@ -36,7 +36,7 @@ public PyObject find_module(String name, PyObject path) { Py.writeDebug("import", "trying " + name + " in packagemanager for path " + path); - PyObject ret = PySystemState.packageManager.lookupName(name.intern()); + PyObject ret = (PyObject)PySystemState.packageManager.lookupName(name.intern()); if (ret != null) { Py.writeComment("import", "'" + name + "' as java package"); return this; @@ -45,7 +45,7 @@ } public PyObject load_module(String name) { - return PySystemState.packageManager.lookupName(name.intern()); + return (PyObject)PySystemState.packageManager.lookupName(name.intern()); } /** Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java 2009-01-28 17:42:03 UTC (rev 5994) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java 2009-01-28 18:20:59 UTC (rev 5995) @@ -108,7 +108,7 @@ } public PyObject __dir__() { - return __mgr__.doDir(this,false,false); + return (PyObject)__mgr__.doDir(this,false,false); } /** @@ -120,7 +120,7 @@ * @return list of member names */ public PyObject fillDir() { - return __mgr__.doDir(this,true,false); + return (PyObject)__mgr__.doDir(this,true,false); } Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyModule.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyModule.java 2009-01-28 17:42:03 UTC (rev 5994) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyModule.java 2009-01-28 18:20:59 UTC (rev 5995) @@ -112,7 +112,7 @@ } if (attr == null) { - attr = PySystemState.packageManager.lookupName(fullName); + attr = (PyObject)PySystemState.packageManager.lookupName(fullName); } if (attr != null) { Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-28 17:42:03 UTC (rev 5994) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-28 18:20:59 UTC (rev 5995) @@ -3,8 +3,7 @@ package org.python.core.packagecache; -import org.python.core.PyList; -import org.python.core.PyObject; +import java.util.List; public interface PackageManager { @@ -45,16 +44,14 @@ * Reports the specified package content names. Should be overriden. Used by * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. * - * @return resulting list of names (PyList of PyString) + * @return resulting list of names (List of PyString) * @param jpkg queried package * @param instantiate if true then instatiate reported names in package dict * @param exclpkgs exclude packages (just when instantiate is false) */ - //XXX - PyList doDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs); + List doDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs); - //XXX - PyObject lookupName(String name); + Object lookupName(String name); /** * Creates package/updates statically known classes info. Uses Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-28 17:42:03 UTC (rev 5994) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-28 18:20:59 UTC (rev 5995) @@ -167,7 +167,7 @@ * package jpkg content over the directories in path. Add to ret the founded * classes/pkgs. Filter out classes using {@link #filterByName},{@link #filterByAccess}. */ - protected void doDir(List path, PyList ret, JavaPackage jpkg, + protected void doDir(List path, List ret, JavaPackage jpkg, boolean instantiate, boolean exclpkgs) { String child = jpkg.getName().replace('.', File.separatorChar); @@ -214,7 +214,7 @@ // for opt maybe we should some hash-set for ret if (((PyStringMap)jpkg.getMembers()).has_key(name) || ((PyStringMap)jpkg.getClasses()).has_key(name) - || ret.__contains__(name)) { + || ret.contains(name)) { continue; } @@ -248,16 +248,16 @@ } } - ret.append(name); + ret.add(name); } } } - public PyList doDir(JavaPackage jpkg, boolean instantiate, + public List doDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs) { - PyList basic = basicDoDir(jpkg, instantiate, exclpkgs); - PyList ret = new PyList(); + List basic = basicDoDir(jpkg, instantiate, exclpkgs); + List ret = new PyList(); doDir(this.getSearchPath(), ret, jpkg, instantiate, exclpkgs); @@ -267,7 +267,8 @@ doDir(system.path, ret, jpkg, instantiate, exclpkgs); } - return merge(basic, ret); + basic.addAll(ret); + return basic; } /* From old PackageManager */ @@ -276,7 +277,7 @@ * Basic helper implementation of {@link #doDir}. It merges information * from jpkg {@link JavaPackage#clsSet} and {@link JavaPackage#__dict__}. */ - protected PyList basicDoDir(JavaPackage jpkg, boolean instantiate, + protected List basicDoDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs) { PyStringMap dict = (PyStringMap)jpkg.getMembers(); PyStringMap cls = (PyStringMap)jpkg.getClasses(); @@ -308,18 +309,6 @@ return dict.keys(); } - /** - * Helper merging list2 into list1. Returns list1. - */ - protected PyList merge(PyList list1, PyList list2) { - for (int i = 0; i < list2.__len__(); i++) { - PyObject name = list2.pyget(i); - list1.append(name); - } - - return list1; - } - public PyObject lookupName(String name) { PyObject top = (PyObject)this.getTopLevelPackage(); do { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-28 17:42:11
|
Revision: 5994 http://jython.svn.sourceforge.net/jython/?rev=5994&view=rev Author: fwierzbicki Date: 2009-01-28 17:42:03 +0000 (Wed, 28 Jan 2009) Log Message: ----------- Removed more Python-specific code while still keeping a working package cache. Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Added Paths: ----------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/JavaPackage.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java Removed Paths: ------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java 2009-01-28 16:26:16 UTC (rev 5993) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -3,7 +3,8 @@ package org.python.core; -import org.python.core.packagecache.PyPackageManager; +import org.python.core.packagecache.PackageManager; +import org.python.core.packagecache.JavaPackage; import java.util.StringTokenizer; @@ -11,7 +12,7 @@ * A representation of java package. */ -public class PyJavaPackage extends PyObject { +public class PyJavaPackage extends PyObject implements JavaPackage{ public String __name__; @@ -26,7 +27,7 @@ /** (Control) package manager whose hierarchy contains this java pkg. */ - public PyPackageManager __mgr__; + public PackageManager __mgr__; public PyJavaPackage(String name) { this(name, null, null); @@ -36,12 +37,11 @@ this(name, null, jarfile); } - public PyJavaPackage(String name,PyPackageManager mgr) { + public PyJavaPackage(String name,PackageManager mgr) { this(name, mgr, null); } - - public PyJavaPackage(String name,PyPackageManager mgr,String jarfile) { + public PyJavaPackage(String name,PackageManager mgr,String jarfile) { __file__ = jarfile; __name__ = name; @@ -56,11 +56,11 @@ __dict__.__setitem__("__name__", new PyString(__name__)); } - public PyJavaPackage addPackage(String name) { + public JavaPackage addPackage(String name) { return addPackage(name, null); } - public PyJavaPackage addPackage(String name, String jarfile) { + public JavaPackage addPackage(String name, String jarfile) { int dot = name.indexOf('.'); String firstName=name; String lastName=null; @@ -85,7 +85,7 @@ else return p; } - public PyObject addClass(String name, Class<?> c) { + public Object addClass(String name, Class<?> c) { PyObject ret = Py.java2py(c); __dict__.__setitem__(name.intern(), ret); return ret; @@ -113,7 +113,7 @@ /** * Used for 'from xyz import *', dynamically dir pkg filling up __dict__. It uses - * {@link PyPackageManager#doDir} implementation furnished by the control package manager with + * {@link PackageManager#doDir} implementation furnished by the control package manager with * instantiate true. The package manager should load classes with {@link #addClass} in the * package. * @@ -131,11 +131,11 @@ if (__mgr__.packageExists(__name__,name)) { __mgr__.notifyPackageImport(__name__,name); - return addPackage(name); + return (PyObject)addPackage(name); } Class c = __mgr__.findClass(__name__,name); - if (c != null) return addClass(name,c); + if (c != null) return (PyObject)addClass(name,c); if (name == "__name__") return new PyString(__name__); if (name == "__dict__") return __dict__; @@ -151,8 +151,8 @@ public void __setattr__(String attr, PyObject value) { if (attr == "__mgr__") { - PyPackageManager newMgr = Py.tojava(value, - PyPackageManager.class); + PackageManager newMgr = Py.tojava(value, + PackageManager.class); if (newMgr == null) { throw Py.TypeError("cannot set java package __mgr__ to None"); } @@ -170,4 +170,15 @@ public String toString() { return "<java package "+__name__+" "+Py.idstr(this)+">"; } + + public String getName() { return __name__; } + public Object dir() { return __dir__(); } + public Object getClasses() { return clsSet; } + public Object getMembers() { return __dict__; } + public void setPackageManager (PackageManager mgr) { __mgr__ = mgr; } + //public Object addClass(String string, Class<?> clazz); + //public JavaPackage addPackage(String name); + //public JavaPackage addPackage(String name, String jarfile); + //public void addPlaceholders(String classes); + } Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java 2009-01-28 16:26:16 UTC (rev 5993) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -21,7 +21,7 @@ import org.python.Version; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; -import org.python.core.packagecache.PyPackageManager; +import org.python.core.packagecache.PackageManager; import org.python.core.packagecache.SysPackageManager; import org.python.modules.Setup; import org.python.modules.zipimport.zipimporter; @@ -80,7 +80,7 @@ private static Map<String,String> builtinNames; public static PyTuple builtin_module_names = null; - public static PyPackageManager packageManager; + public static PackageManager packageManager; private static File cachedir; private static PyList defaultPath; @@ -1019,7 +1019,7 @@ } public static PyJavaPackage add_package(String n) { - return add_package(n, null); + return (PyJavaPackage)add_package(n, null); } public static PyJavaPackage add_package(String n, String contents) { Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-28 16:26:16 UTC (rev 5993) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -31,8 +31,10 @@ /** * Base package manager. */ -public abstract class BasePackageManager { +public abstract class BasePackageManager implements PackageManager { + protected JavaPackage topLevelPackage; + /* from old PackageManager */ protected List searchPath; @@ -44,8 +46,22 @@ // for default cache (local fs based) impl protected File cachedir; - public BasePackageManager(boolean respectJavaAccessibility) { + public BasePackageManager(JavaPackage top, File cachedir, boolean respectJavaAccessibility, List<String> classpaths, List<String> jarpaths) { this.respectJavaAccessibility = respectJavaAccessibility; + this.searchPath = new ArrayList(); + this.topLevelPackage = top; + top.setPackageManager(this); + if (useCacheDir(cachedir)) { + initCache(); + for (String c : classpaths) { + addClassPath(c); + } + for (String j : jarpaths) { + addJarPath(j); + } + saveCache(); + } + } public abstract Object makeJavaPackage(String name, String classes, String jarfile); @@ -164,7 +180,6 @@ } } - //Copied from CachedJarsPackageManager /** * Filter class/pkg by name helper method - hook. The default impl. is used * by {@link #addJarToPackages} in order to filter out classes whose name Added: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/JavaPackage.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/JavaPackage.java (rev 0) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/JavaPackage.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -0,0 +1,23 @@ +// Released to the public domain by Frank Wierzbicki Jan 3, 2009 +package org.python.core.packagecache; + +import java.util.Map; + +public interface JavaPackage { + public String getName(); + + /* XXX: should return List */ + public Object dir(); + + /* XXX: should return Set or Map */ + public Object getClasses(); + + /* XXX: should return Map */ + public Object getMembers(); + + public Object addClass(String string, Class<?> clazz); + public JavaPackage addPackage(String name); + public JavaPackage addPackage(String name, String jarfile); + public void addPlaceholders(String classes); + void setPackageManager(PackageManager mgr); +} Copied: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java (from rev 5986, trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java) =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java (rev 0) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -0,0 +1,70 @@ +// Copyright (c) Corporation for National Research Initiatives +// Copyright 2000 Samuele Pedroni + +package org.python.core.packagecache; + +import org.python.core.PyList; +import org.python.core.PyObject; + +public interface PackageManager { + + Class findClass(String pkg, String name, String reason); + + Class findClass(String pkg, String name); + + void notifyPackageImport(String pkg, String name); + + boolean packageExists(String pkg, String name); + + /** + * Append a directory to the list of directories searched for java packages + * and java classes. + * + * @param dir A directory. + */ + void addDirectory(java.io.File dir); + + /** + * Append a directory to the list of directories searched for java packages + * and java classes. + * + * @param dir A directory name. + */ + void addJarDir(String dir, boolean cache); + + /** + * Append a jar file to the list of locations searched for java packages and + * java classes. + * + * @param jarfile A directory name. + */ + void addJar(String jarfile, boolean cache); + + + /** + * Reports the specified package content names. Should be overriden. Used by + * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. + * + * @return resulting list of names (PyList of PyString) + * @param jpkg queried package + * @param instantiate if true then instatiate reported names in package dict + * @param exclpkgs exclude packages (just when instantiate is false) + */ + //XXX + PyList doDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs); + + //XXX + PyObject lookupName(String name); + + /** + * Creates package/updates statically known classes info. Uses + * {@link PyJavaPackage#addPackage(java.lang.String, java.lang.String) }, + * {@link PyJavaPackage#addPlaceholders}. + * + * @param name package name + * @param classes comma-separated string + * @param jarfile involved jarfile; can be null + * @return created/updated package + */ + Object makeJavaPackage(String name, String classes, String jarfile); +} Deleted: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java 2009-01-28 16:26:16 UTC (rev 5993) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -1,70 +0,0 @@ -// Copyright (c) Corporation for National Research Initiatives -// Copyright 2000 Samuele Pedroni - -package org.python.core.packagecache; - -import org.python.core.PyJavaPackage; -import org.python.core.PyList; -import org.python.core.PyObject; - -public interface PyPackageManager { - - Class findClass(String pkg, String name, String reason); - - Class findClass(String pkg, String name); - - void notifyPackageImport(String pkg, String name); - - boolean packageExists(String pkg, String name); - - /** - * Append a directory to the list of directories searched for java packages - * and java classes. - * - * @param dir A directory. - */ - void addDirectory(java.io.File dir); - - /** - * Append a directory to the list of directories searched for java packages - * and java classes. - * - * @param dir A directory name. - */ - void addJarDir(String dir, boolean cache); - - /** - * Append a jar file to the list of locations searched for java packages and - * java classes. - * - * @param jarfile A directory name. - */ - void addJar(String jarfile, boolean cache); - - - /** - * Reports the specified package content names. Should be overriden. Used by - * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. - * - * @return resulting list of names (PyList of PyString) - * @param jpkg queried package - * @param instantiate if true then instatiate reported names in package dict - * @param exclpkgs exclude packages (just when instantiate is false) - */ - PyList doDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs); - - //XXX - PyObject lookupName(String name); - - /** - * Creates package/updates statically known classes info. Uses - * {@link PyJavaPackage#addPackage(java.lang.String, java.lang.String) }, - * {@link PyJavaPackage#addPlaceholders}. - * - * @param name package name - * @param classes comma-separated string - * @param jarfile involved jarfile; can be null - * @return created/updated package - */ - Object makeJavaPackage(String name, String classes, String jarfile); -} Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-28 16:26:16 UTC (rev 5993) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-28 17:42:03 UTC (rev 5994) @@ -18,6 +18,7 @@ import java.net.URL; import java.net.URLConnection; import java.security.AccessControlException; +import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -41,30 +42,16 @@ /** * System package manager. Used by org.python.core.PySystemState. */ -public class SysPackageManager extends BasePackageManager implements PyPackageManager{ +public class SysPackageManager extends BasePackageManager { - protected PyJavaPackage topLevelPackage; - public SysPackageManager(File cachedir, Properties registry) { - super(Options.respectJavaAccessibility); - /* from PathPackageManager constructor */ - this.searchPath = new PyList(); - - /* from old PackageManager constructor */ - this.topLevelPackage = new PyJavaPackage("", this); - - if (useCacheDir(cachedir)) { - initCache(); - findAllPackages(registry); - saveCache(); - } + super(new PyJavaPackage(""), cachedir, Options.respectJavaAccessibility, findClassPaths(registry), findJarPaths(registry)); } - protected void findAllPackages(Properties registry) { + private static List<String> findClassPaths(Properties registry) { + List<String> classpaths = new ArrayList<String>(); String paths = registry.getProperty("python.packages.paths", "java.class.path,sun.boot.class.path"); - String directories = registry.getProperty( - "python.packages.directories", "java.ext.dirs"); String fakepath = registry .getProperty("python.packages.fakepath", null); StringTokenizer tok = new StringTokenizer(paths, ","); @@ -74,36 +61,42 @@ if (tmp == null) { continue; } - addClassPath(tmp); + classpaths.add(tmp); } - tok = new StringTokenizer(directories, ","); + if (fakepath != null) { + classpaths.add(fakepath); + } + return classpaths; + } + + private static List<String> findJarPaths(Properties registry) { + List<String> paths = new ArrayList<String>(); + String directories = registry.getProperty( + "python.packages.directories", "java.ext.dirs"); + StringTokenizer tok = new StringTokenizer(directories, ","); while (tok.hasMoreTokens()) { String entry = tok.nextToken().trim(); String tmp = registry.getProperty(entry); if (tmp == null) { continue; } - addJarPath(tmp); + paths.add(tmp); } - - if (fakepath != null) { - addClassPath(fakepath); - } + return paths; } - /** * @return the topLevelPackage */ - public PyJavaPackage getTopLevelPackage() { + public JavaPackage getTopLevelPackage() { return topLevelPackage; } /** * @param topLevelPackage the topLevelPackage to set */ - public void setTopLevelPackage(PyJavaPackage topLevelPackage) { + public void setTopLevelPackage(JavaPackage topLevelPackage) { this.topLevelPackage = topLevelPackage; } @@ -174,9 +167,9 @@ * package jpkg content over the directories in path. Add to ret the founded * classes/pkgs. Filter out classes using {@link #filterByName},{@link #filterByAccess}. */ - protected void doDir(List path, PyList ret, PyJavaPackage jpkg, + protected void doDir(List path, PyList ret, JavaPackage jpkg, boolean instantiate, boolean exclpkgs) { - String child = jpkg.__name__.replace('.', File.separatorChar); + String child = jpkg.getName().replace('.', File.separatorChar); for (int i = 0; i < path.size(); i++) { String dir = path.get(i).toString(); @@ -220,7 +213,7 @@ } // for opt maybe we should some hash-set for ret - if (jpkg.__dict__.has_key(name) || jpkg.clsSet.has_key(name) + if (((PyStringMap)jpkg.getMembers()).has_key(name) || ((PyStringMap)jpkg.getClasses()).has_key(name) || ret.__contains__(name)) { continue; } @@ -251,7 +244,7 @@ if (pkgCand) { jpkg.addPackage(jname); } else { - jpkg.addClass(jname, Py.findClass(jpkg.__name__ + "." + jname)); + jpkg.addClass(jname, Py.findClass(jpkg.getName() + "." + jname)); } } @@ -259,10 +252,9 @@ } } - } - public PyList doDir(PyJavaPackage jpkg, boolean instantiate, + public PyList doDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs) { PyList basic = basicDoDir(jpkg, instantiate, exclpkgs); PyList ret = new PyList(); @@ -282,12 +274,12 @@ /** * Basic helper implementation of {@link #doDir}. It merges information - * from jpkg {@link PyJavaPackage#clsSet} and {@link PyJavaPackage#__dict__}. + * from jpkg {@link JavaPackage#clsSet} and {@link JavaPackage#__dict__}. */ - protected PyList basicDoDir(PyJavaPackage jpkg, boolean instantiate, + protected PyList basicDoDir(JavaPackage jpkg, boolean instantiate, boolean exclpkgs) { - PyStringMap dict = jpkg.__dict__; - PyStringMap cls = jpkg.clsSet; + PyStringMap dict = (PyStringMap)jpkg.getMembers(); + PyStringMap cls = (PyStringMap)jpkg.getClasses(); if (!instantiate) { PyList ret = cls.keys(); @@ -309,7 +301,7 @@ for (PyObject pyname : cls.keys().asIterable()) { if (!dict.has_key(pyname)) { String name = pyname.toString(); - jpkg.addClass(name, Py.findClass(jpkg.__name__ + "." + name)); + jpkg.addClass(name, Py.findClass(jpkg.getName() + "." + name)); } } @@ -328,9 +320,8 @@ return list1; } - public PyObject lookupName(String name) { - PyObject top = this.getTopLevelPackage(); + PyObject top = (PyObject)this.getTopLevelPackage(); do { int dot = name.indexOf('.'); String firstName = name; @@ -359,9 +350,9 @@ * @param jarfile involved jarfile; can be null * @return created/updated package */ - public Object makeJavaPackage(String name, String classes, + public JavaPackage makeJavaPackage(String name, String classes, String jarfile) { - PyJavaPackage p = this.getTopLevelPackage(); + JavaPackage p = this.getTopLevelPackage(); if (name.length() != 0) p = p.addPackage(name, jarfile); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-01-28 16:26:20
|
Revision: 5993 http://jython.svn.sourceforge.net/jython/?rev=5993&view=rev Author: amak Date: 2009-01-28 16:26:16 +0000 (Wed, 28 Jan 2009) Log Message: ----------- Fix and unit test for bug 1244. Problem letting system choose the port for binding UDP socket http://bugs.jython.org/issue1244 Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py branches/Release_2_2maint/jython/Lib/test/test_socket.py Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2009-01-28 16:05:59 UTC (rev 5992) +++ branches/Release_2_2maint/jython/Lib/socket.py 2009-01-28 16:26:16 UTC (rev 5993) @@ -372,7 +372,7 @@ def __init__(self, port=None, address=None, reuse_addr=0): self.jchannel = java.nio.channels.DatagramChannel.open() self.jsocket = self.jchannel.socket() - if port: + if port is not None: if address is not None: local_address = java.net.InetSocketAddress(address, port) else: Modified: branches/Release_2_2maint/jython/Lib/test/test_socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/test/test_socket.py 2009-01-28 16:05:59 UTC (rev 5992) +++ branches/Release_2_2maint/jython/Lib/test/test_socket.py 2009-01-28 16:26:16 UTC (rev 5993) @@ -789,6 +789,21 @@ self.serv_conn.send(MSG) self.serv_conn.send('and ' + MSG) +class UDPBindTest(unittest.TestCase): + + HOST = HOST + PORT = PORT + + def setUp(self): + self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) + + def testBindEphemeral(self): + self.sock.bind( (self.HOST, 0) ) # let system choose a free port + self.failUnless(self.sock.getsockname()[1] != 0, "Binding to port zero should have allocated an ephemeral port number") + + def tearDown(self): + self.sock.close() + class BasicUDPTest(ThreadedUDPSocketTest): def __init__(self, methodName='runTest'): @@ -1576,6 +1591,7 @@ TestInvalidUsage, TestTCPAddressParameters, TestUDPAddressParameters, + UDPBindTest, BasicUDPTest, UDPTimeoutTest, NonBlockingTCPTests, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-01-28 16:06:23
|
Revision: 5992 http://jython.svn.sourceforge.net/jython/?rev=5992&view=rev Author: amak Date: 2009-01-28 16:05:59 +0000 (Wed, 28 Jan 2009) Log Message: ----------- Fix and unit test for bug 1244. Problem letting system choose the port for binding UDP socket http://bugs.jython.org/issue1244 Modified Paths: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-01-27 05:06:54 UTC (rev 5991) +++ trunk/jython/Lib/socket.py 2009-01-28 16:05:59 UTC (rev 5992) @@ -384,7 +384,7 @@ def __init__(self, port=None, address=None, reuse_addr=0): self.jchannel = java.nio.channels.DatagramChannel.open() self.jsocket = self.jchannel.socket() - if port: + if port is not None: if address is not None: local_address = java.net.InetSocketAddress(address, port) else: Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2009-01-27 05:06:54 UTC (rev 5991) +++ trunk/jython/Lib/test/test_socket.py 2009-01-28 16:05:59 UTC (rev 5992) @@ -813,7 +813,22 @@ def _testDup(self): self.serv_conn.send(MSG) self.serv_conn.send('and ' + MSG) + +class UDPBindTest(unittest.TestCase): + + HOST = HOST + PORT = PORT + def setUp(self): + self.sock = socket.socket(socket.AF_INET,socket.SOCK_DGRAM) + + def testBindEphemeral(self): + self.sock.bind( (self.HOST, 0) ) # let system choose a free port + self.failUnless(self.sock.getsockname()[1] != 0, "Binding to port zero should have allocated an ephemeral port number") + + def tearDown(self): + self.sock.close() + class BasicUDPTest(ThreadedUDPSocketTest): def __init__(self, methodName='runTest'): @@ -1609,6 +1624,7 @@ TestInvalidUsage, TestTCPAddressParameters, TestUDPAddressParameters, + UDPBindTest, BasicUDPTest, UDPTimeoutTest, NonBlockingTCPTests, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-27 05:06:58
|
Revision: 5991 http://jython.svn.sourceforge.net/jython/?rev=5991&view=rev Author: fwierzbicki Date: 2009-01-27 05:06:54 +0000 (Tue, 27 Jan 2009) Log Message: ----------- Oops missed a py-specific method in BasdPackageManager. Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-27 04:54:32 UTC (rev 5990) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-27 05:06:54 UTC (rev 5991) @@ -80,7 +80,7 @@ } } - private void addJarPath(String path) { + protected void addJarPath(String path) { StringTokenizer tok = new StringTokenizer(path, java.io.File.pathSeparator); while (tok.hasMoreTokens()) { @@ -90,38 +90,6 @@ } } - protected void findAllPackages(Properties registry) { - String paths = registry.getProperty("python.packages.paths", - "java.class.path,sun.boot.class.path"); - String directories = registry.getProperty( - "python.packages.directories", "java.ext.dirs"); - String fakepath = registry - .getProperty("python.packages.fakepath", null); - StringTokenizer tok = new StringTokenizer(paths, ","); - while (tok.hasMoreTokens()) { - String entry = tok.nextToken().trim(); - String tmp = registry.getProperty(entry); - if (tmp == null) { - continue; - } - addClassPath(tmp); - } - - tok = new StringTokenizer(directories, ","); - while (tok.hasMoreTokens()) { - String entry = tok.nextToken().trim(); - String tmp = registry.getProperty(entry); - if (tmp == null) { - continue; - } - addJarPath(tmp); - } - - if (fakepath != null) { - addClassPath(fakepath); - } - } - public void notifyPackageImport(String pkg, String name) { if (pkg != null && pkg.length() > 0) { name = pkg + '.' + name; Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-27 04:54:32 UTC (rev 5990) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-27 05:06:54 UTC (rev 5991) @@ -60,6 +60,39 @@ } } + protected void findAllPackages(Properties registry) { + String paths = registry.getProperty("python.packages.paths", + "java.class.path,sun.boot.class.path"); + String directories = registry.getProperty( + "python.packages.directories", "java.ext.dirs"); + String fakepath = registry + .getProperty("python.packages.fakepath", null); + StringTokenizer tok = new StringTokenizer(paths, ","); + while (tok.hasMoreTokens()) { + String entry = tok.nextToken().trim(); + String tmp = registry.getProperty(entry); + if (tmp == null) { + continue; + } + addClassPath(tmp); + } + + tok = new StringTokenizer(directories, ","); + while (tok.hasMoreTokens()) { + String entry = tok.nextToken().trim(); + String tmp = registry.getProperty(entry); + if (tmp == null) { + continue; + } + addJarPath(tmp); + } + + if (fakepath != null) { + addClassPath(fakepath); + } + } + + /** * @return the topLevelPackage */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-27 04:54:36
|
Revision: 5990 http://jython.svn.sourceforge.net/jython/?rev=5990&view=rev Author: fwierzbicki Date: 2009-01-27 04:54:32 +0000 (Tue, 27 Jan 2009) Log Message: ----------- BasePackageManager now completely untethered from Py internals. Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java 2009-01-27 02:26:20 UTC (rev 5989) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java 2009-01-27 04:54:32 UTC (rev 5990) @@ -1023,7 +1023,7 @@ } public static PyJavaPackage add_package(String n, String contents) { - return packageManager.makeJavaPackage(n, contents, null); + return (PyJavaPackage)packageManager.makeJavaPackage(n, contents, null); } /** Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-27 02:26:20 UTC (rev 5989) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-27 04:54:32 UTC (rev 5990) @@ -18,6 +18,8 @@ import java.net.URL; import java.net.URLConnection; import java.security.AccessControlException; +import java.util.ArrayList; +import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Map.Entry; @@ -26,52 +28,30 @@ import java.util.zip.ZipEntry; import java.util.zip.ZipInputStream; -import org.python.core.Options; -import org.python.core.Py; -import org.python.core.PyJavaPackage; -import org.python.core.PyList; -import org.python.core.PyObject; -import org.python.core.PyString; -import org.python.core.PyStringMap; -import org.python.core.PySystemState; -import org.python.core.imp; -import org.python.core.util.RelativeFile; -import org.python.util.Generic; - /** * Base package manager. */ public abstract class BasePackageManager { /* from old PackageManager */ - protected PyList searchPath; - protected PyJavaPackage topLevelPackage; + protected List searchPath; protected boolean indexModified; + protected boolean respectJavaAccessibility; protected Map<String,JarXEntry> jarfiles; // for default cache (local fs based) impl protected File cachedir; - protected void message(String msg) { - Py.writeMessage("*sys-package-mgr*", msg); + public BasePackageManager(boolean respectJavaAccessibility) { + this.respectJavaAccessibility = respectJavaAccessibility; } - protected void warning(String warn) { - Py.writeWarning("*sys-package-mgr*", warn); - } - - protected void comment(String msg) { - Py.writeComment("*sys-package-mgr*", msg); - } - - protected void debug(String msg) { - Py.writeDebug("*sys-package-mgr*", msg); - } - public abstract Object makeJavaPackage(String name, String classes, String jarfile); + public abstract Class findClass(String pkg, String name, String reason); + public void addJar(String jarfile, boolean cache) { addJarToPackages(new File(jarfile), cache); if (cache) { @@ -146,231 +126,40 @@ if (pkg != null && pkg.length() > 0) { name = pkg + '.' + name; } - Py.writeComment("import", "'" + name + "' as java package"); + comment("import " + "'" + name + "' as java package"); } public Class findClass(String pkg, String name) { Class c = findClass(pkg, name, "java class"); if (c != null) { - Py.writeComment("import", "'" + name + "' as java class"); + comment("import " + "'" + name + "' as java class"); } return c; } - public Class findClass(String pkg, String name, String reason) { - if (pkg != null && pkg.length() > 0) { - name = pkg + '.' + name; - } - return Py.findClassEx(name, reason); - } - /** - * Dynamically check if pkg.name exists as java pkg in the controlled - * hierarchy. Should be overriden. - * - * @param pkg parent pkg name - * @param name candidate name - * @return true if pkg exists - */ - public boolean packageExists(String pkg, String name) { - if (packageExists(this.getSearchPath(), pkg, name)) { - return true; - } - - PySystemState system = Py.getSystemState(); - - if (system.getClassLoader() == null - && packageExists(Py.getSystemState().path, pkg, name)) { - return true; - } - - return false; - } - - - /** - * Helper for {@link #packageExists(java.lang.String,java.lang.String)}. - * Scans for package pkg.name the directories in path. - */ - protected boolean packageExists(PyList path, String pkg, String name) { - String child = pkg.replace('.', File.separatorChar) + File.separator - + name; - - for (int i = 0; i < path.__len__(); i++) { - String dir = path.pyget(i).__str__().toString(); - - File f = new RelativeFile(dir, child); - if (f.isDirectory() && imp.caseok(f, name)) { - /* - * Figure out if we have a directory a mixture of python and - * java or just an empty directory (which means Java) or a - * directory with only Python source (which means Python). - */ - PackageExistsFileFilter m = new PackageExistsFileFilter(); - f.listFiles(m); - boolean exists = m.packageExists(); - if (exists) { - Py.writeComment("import", "java package as '" - + f.getAbsolutePath() + "'"); - } - return exists; - } - } - return false; - } - - /** * @return the searchPath */ - public PyList getSearchPath() { + public List getSearchPath() { return searchPath; } /** * @param searchPath the searchPath to set */ - public void setSearchPath(PyList searchPath) { + public void setSearchPath(List searchPath) { this.searchPath = searchPath; } /** - * @return the topLevelPackage - */ - public PyJavaPackage getTopLevelPackage() { - return topLevelPackage; - } - - /** - * @param topLevelPackage the topLevelPackage to set - */ - public void setTopLevelPackage(PyJavaPackage topLevelPackage) { - this.topLevelPackage = topLevelPackage; - } - - class PackageExistsFileFilter implements FilenameFilter { - private boolean java; - - private boolean python; - - public boolean accept(File dir, String name) { - if(name.endsWith(".py") || name.endsWith("$py.class") || name.endsWith("$_PyInner.class")) { - python = true; - }else if (name.endsWith(".class")) { - java = true; - } - return false; - } - - public boolean packageExists() { - if (this.python && !this.java) { - return false; - } - return true; - } - } - - /** - * Helper for {@link #doDir(PyJavaPackage,boolean,boolean)}. Scans for - * package jpkg content over the directories in path. Add to ret the founded - * classes/pkgs. Filter out classes using {@link #filterByName},{@link #filterByAccess}. - */ - protected void doDir(PyList path, PyList ret, PyJavaPackage jpkg, - boolean instantiate, boolean exclpkgs) { - String child = jpkg.__name__.replace('.', File.separatorChar); - - for (int i = 0; i < path.__len__(); i++) { - String dir = path.pyget(i).__str__().toString(); - if (dir.length() == 0) { - dir = null; - } - - File childFile = new File(dir, child); - - String[] list = childFile.list(); - if (list == null) { - continue; - } - - doList: for (int j = 0; j < list.length; j++) { - String jname = list[j]; - - File cand = new File(childFile, jname); - - int jlen = jname.length(); - - boolean pkgCand = false; - - if (cand.isDirectory()) { - if (!instantiate && exclpkgs) { - continue; - } - pkgCand = true; - } else { - if (!jname.endsWith(".class")) { - continue; - } - jlen -= 6; - } - - jname = jname.substring(0, jlen); - PyString name = new PyString(jname); - - if (filterByName(jname, pkgCand)) { - continue; - } - - // for opt maybe we should some hash-set for ret - if (jpkg.__dict__.has_key(name) || jpkg.clsSet.has_key(name) - || ret.__contains__(name)) { - continue; - } - - if (!Character.isJavaIdentifierStart(jname.charAt(0))) { - continue; - } - - for (int k = 1; k < jlen; k++) { - if (!Character.isJavaIdentifierPart(jname.charAt(k))) { - continue doList; - } - } - - if (!pkgCand) { - try { - int acc = checkAccess(new BufferedInputStream( - new FileInputStream(cand))); - if ((acc == -1) || filterByAccess(jname, acc)) { - continue; - } - } catch (IOException e) { - continue; - } - } - - if (instantiate) { - if (pkgCand) { - jpkg.addPackage(jname); - } else { - jpkg.addClass(jname, Py.findClass(jpkg.__name__ + "." + jname)); - } - } - - ret.append(name); - - } - } - - } - - /** * Add directory dir (if exists) to {@link #searchPath}. */ public void addDirectory(File dir) { try { if (dir.getPath().length() == 0) { - this.getSearchPath().append(Py.EmptyString); + this.getSearchPath().add(""); } else { - this.getSearchPath().append(new PyString(dir.getCanonicalPath())); + this.getSearchPath().add(dir.getCanonicalPath()); } } catch (IOException e) { warning("skipping bad directory, '" + dir + "'"); @@ -392,10 +181,10 @@ * true if path refers to a jar. */ public void addClassPath(String path) { - PyList paths = new PyString(path).split(java.io.File.pathSeparator); + String[] paths = path.split(java.io.File.pathSeparator); - for (int i = 0; i < paths.__len__(); i++) { - String entry = paths.pyget(i).toString(); + for (int i = 0; i < paths.length; i++) { + String entry = paths[i].toString(); if (entry.endsWith(".jar") || entry.endsWith(".zip")) { addJarToPackages(new File(entry), true); } else { @@ -481,7 +270,7 @@ List<String>[] vec = zipPackages.get(packageName); if (vec == null) { - vec = new List[] { Generic.list(), Generic.list() }; + vec = new List[] { new ArrayList(), new ArrayList() }; zipPackages.put(packageName, vec); } int access = checkAccess(zip); @@ -494,7 +283,7 @@ // Extract all of the packages in a single jarfile private Map<String, String> getZipPackages(InputStream jarin) throws IOException { - Map<String, List<String>[]> zipPackages = Generic.map(); + Map<String, List<String>[]> zipPackages = new HashMap<String, List<String>[]>(); ZipInputStream zip = new ZipInputStream(jarin); @@ -505,7 +294,7 @@ } // Turn each vector into a comma-separated String - Map<String, String> transformed = Generic.map(); + Map<String, String> transformed = new HashMap<String, String>(); for (String key : zipPackages.keySet()) { List<String>[] vec = zipPackages.get(key); String classes = listToString(vec[0]); @@ -673,7 +462,7 @@ String classes = entry.getValue(); int idx = classes.indexOf('@'); - if (idx >= 0 && Options.respectJavaAccessibility) { + if (idx >= 0 && respectJavaAccessibility) { classes = classes.substring(0, idx); } @@ -699,7 +488,7 @@ deleteCacheFile(cachefile); return null; } - Map<String, String> packs = Generic.map(); + Map<String, String> packs = new HashMap<String, String>(); try { while (true) { String packageName = istream.readUTF(); @@ -744,7 +533,7 @@ */ protected void initCache() { this.indexModified = false; - this.jarfiles = Generic.map(); + this.jarfiles = new HashMap<String,JarXEntry>(); try { DataInputStream istream = inOpenIndex(); @@ -997,4 +786,20 @@ return istream.readShort(); } + //Do nothing by default. + protected void message(String msg) { + } + + //Do nothing by default. + protected void warning(String warn) { + } + + //Do nothing by default. + protected void comment(String msg) { + } + + //Do nothing by default. + protected void debug(String msg) { + } + } Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-27 02:26:20 UTC (rev 5989) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-27 04:54:32 UTC (rev 5990) @@ -43,7 +43,10 @@ */ public class SysPackageManager extends BasePackageManager implements PyPackageManager{ + protected PyJavaPackage topLevelPackage; + public SysPackageManager(File cachedir, Properties registry) { + super(Options.respectJavaAccessibility); /* from PathPackageManager constructor */ this.searchPath = new PyList(); @@ -57,6 +60,175 @@ } } + /** + * @return the topLevelPackage + */ + public PyJavaPackage getTopLevelPackage() { + return topLevelPackage; + } + + /** + * @param topLevelPackage the topLevelPackage to set + */ + public void setTopLevelPackage(PyJavaPackage topLevelPackage) { + this.topLevelPackage = topLevelPackage; + } + + public Class findClass(String pkg, String name, String reason) { + if (pkg != null && pkg.length() > 0) { + name = pkg + '.' + name; + } + return Py.findClassEx(name, reason); + } + + /** + * Dynamically check if pkg.name exists as java pkg in the controlled + * hierarchy. Should be overriden. + * + * @param pkg parent pkg name + * @param name candidate name + * @return true if pkg exists + */ + public boolean packageExists(String pkg, String name) { + if (packageExists(this.getSearchPath(), pkg, name)) { + return true; + } + + PySystemState system = Py.getSystemState(); + + if (system.getClassLoader() == null + && packageExists(Py.getSystemState().path, pkg, name)) { + return true; + } + + return false; + } + + /** + * Helper for {@link #packageExists(java.lang.String,java.lang.String)}. + * Scans for package pkg.name the directories in path. + */ + protected boolean packageExists(List path, String pkg, String name) { + String child = pkg.replace('.', File.separatorChar) + File.separator + + name; + + for (int i = 0; i < path.size(); i++) { + String dir = path.get(i).toString(); + + File f = new RelativeFile(dir, child); + if (f.isDirectory() && imp.caseok(f, name)) { + /* + * Figure out if we have a directory a mixture of python and + * java or just an empty directory (which means Java) or a + * directory with only Python source (which means Python). + */ + PackageExistsFileFilter m = new PackageExistsFileFilter(); + f.listFiles(m); + boolean exists = m.packageExists(); + if (exists) { + Py.writeComment("import", "java package as '" + + f.getAbsolutePath() + "'"); + } + return exists; + } + } + return false; + } + + + /** + * Helper for {@link #doDir(PyJavaPackage,boolean,boolean)}. Scans for + * package jpkg content over the directories in path. Add to ret the founded + * classes/pkgs. Filter out classes using {@link #filterByName},{@link #filterByAccess}. + */ + protected void doDir(List path, PyList ret, PyJavaPackage jpkg, + boolean instantiate, boolean exclpkgs) { + String child = jpkg.__name__.replace('.', File.separatorChar); + + for (int i = 0; i < path.size(); i++) { + String dir = path.get(i).toString(); + if (dir.length() == 0) { + dir = null; + } + + File childFile = new File(dir, child); + + String[] list = childFile.list(); + if (list == null) { + continue; + } + + doList: for (int j = 0; j < list.length; j++) { + String jname = list[j]; + + File cand = new File(childFile, jname); + + int jlen = jname.length(); + + boolean pkgCand = false; + + if (cand.isDirectory()) { + if (!instantiate && exclpkgs) { + continue; + } + pkgCand = true; + } else { + if (!jname.endsWith(".class")) { + continue; + } + jlen -= 6; + } + + jname = jname.substring(0, jlen); + PyString name = new PyString(jname); + + if (filterByName(jname, pkgCand)) { + continue; + } + + // for opt maybe we should some hash-set for ret + if (jpkg.__dict__.has_key(name) || jpkg.clsSet.has_key(name) + || ret.__contains__(name)) { + continue; + } + + if (!Character.isJavaIdentifierStart(jname.charAt(0))) { + continue; + } + + for (int k = 1; k < jlen; k++) { + if (!Character.isJavaIdentifierPart(jname.charAt(k))) { + continue doList; + } + } + + if (!pkgCand) { + try { + int acc = checkAccess(new BufferedInputStream( + new FileInputStream(cand))); + if ((acc == -1) || filterByAccess(jname, acc)) { + continue; + } + } catch (IOException e) { + continue; + } + } + + if (instantiate) { + if (pkgCand) { + jpkg.addPackage(jname); + } else { + jpkg.addClass(jname, Py.findClass(jpkg.__name__ + "." + jname)); + } + } + + ret.append(name); + + } + } + + } + public PyList doDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs) { PyList basic = basicDoDir(jpkg, instantiate, exclpkgs); @@ -166,4 +338,42 @@ return p; } + protected void message(String msg) { + Py.writeMessage("*sys-package-mgr*", msg); + } + + protected void warning(String warn) { + Py.writeWarning("*sys-package-mgr*", warn); + } + + protected void comment(String msg) { + Py.writeComment("*sys-package-mgr*", msg); + } + + protected void debug(String msg) { + Py.writeDebug("*sys-package-mgr*", msg); + } + + class PackageExistsFileFilter implements FilenameFilter { + private boolean java; + + private boolean python; + + public boolean accept(File dir, String name) { + if(name.endsWith(".py") || name.endsWith("$py.class") || name.endsWith("$_PyInner.class")) { + python = true; + }else if (name.endsWith(".class")) { + java = true; + } + return false; + } + + public boolean packageExists() { + if (this.python && !this.java) { + return false; + } + return true; + } + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-27 03:22:18
|
Revision: 5988 http://jython.svn.sourceforge.net/jython/?rev=5988&view=rev Author: zyasoft Date: 2009-01-27 02:16:49 +0000 (Tue, 27 Jan 2009) Log Message: ----------- Fixed opcode support for LOAD/STORE/DELETE_NAME and BUILD_CLASS. Modified Paths: -------------- branches/pbcvm/Tools/pbcvm/extract.py branches/pbcvm/src/org/python/core/PyBytecode.java Modified: branches/pbcvm/Tools/pbcvm/extract.py =================================================================== --- branches/pbcvm/Tools/pbcvm/extract.py 2009-01-27 01:45:48 UTC (rev 5987) +++ branches/pbcvm/Tools/pbcvm/extract.py 2009-01-27 02:16:49 UTC (rev 5988) @@ -93,7 +93,7 @@ values.append((attr, "["+', '.join(co_consts)+"]")) else: values.append((attr, repr(getattr(code, attr)))) - _codeobjs[code] = "PyBytecode(\n" + ',\n'.join([' '* 4 + v + ' # ' + attr for (attr, v) in values])+")" + _codeobjs[code] = "PyBytecode(\n" + '\n'.join([' '* 4 + v + ', # ' + attr for (attr, v) in values])+"\n )" return "_codeobjs[%r]" % (name,) Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-27 01:45:48 UTC (rev 5987) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-27 02:16:49 UTC (rev 5988) @@ -193,7 +193,7 @@ System.err.println(co_name + ":" + count + "," + f.f_lasti + "> opcode: " + getOpname().__getitem__(Py.newInteger(opcode)) + - (opcode > Opcode.HAVE_ARGUMENT ? ", oparg: " + oparg : "") + + (opcode >= Opcode.HAVE_ARGUMENT ? ", oparg: " + oparg : "") + ", stack: " + stack.toString() + ", blocks: " + stringify_blocks(f)); } @@ -267,7 +267,7 @@ } opcode = co_code[next_instr]; - if (opcode > Opcode.HAVE_ARGUMENT) { + if (opcode >= Opcode.HAVE_ARGUMENT) { next_instr += 2; oparg = (co_code[next_instr] << 8) + co_code[next_instr - 1]; } @@ -705,18 +705,18 @@ case Opcode.BUILD_CLASS: { PyObject methods = stack.pop(); - PyObject bases[] = (new PyTuple(stack.pop())).getArray(); + PyObject bases[] = ((PyTuple)(stack.pop())).getArray(); // new PyTuple(stack.pop())).getArray(); String name = stack.pop().toString(); stack.push(Py.makeClass(name, bases, methods)); break; } case Opcode.STORE_NAME: - f.setlocal(oparg, stack.pop()); + f.setlocal(co_names[oparg], stack.pop()); break; case Opcode.DELETE_NAME: - f.dellocal(oparg); + f.dellocal(co_names[oparg]); break; case Opcode.UNPACK_SEQUENCE: { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-27 02:59:52
|
Revision: 5987 http://jython.svn.sourceforge.net/jython/?rev=5987&view=rev Author: zyasoft Date: 2009-01-27 01:45:48 +0000 (Tue, 27 Jan 2009) Log Message: ----------- Fixed raising of exceptions and PyStack.rot Modified Paths: -------------- branches/pbcvm/Tools/pbcvm/extract.py branches/pbcvm/src/org/python/core/PyBytecode.java Modified: branches/pbcvm/Tools/pbcvm/extract.py =================================================================== --- branches/pbcvm/Tools/pbcvm/extract.py 2009-01-26 18:11:57 UTC (rev 5986) +++ branches/pbcvm/Tools/pbcvm/extract.py 2009-01-27 01:45:48 UTC (rev 5987) @@ -62,7 +62,6 @@ functions.append(("%s.%s" % (classname, methodname), method)) return functions -# what if we are passed a builtin? need to identify that signature def extract_code_obj(f_or_code): if inspect.iscode(f_or_code): code = f_or_code @@ -91,12 +90,10 @@ co_consts.append(extract_def(const)) else: co_consts.append(repr(const)) - values.append("["+', '.join(co_consts)+"]") - elif attr == 'co_lnotab': - values.append(repr(None)) + values.append((attr, "["+', '.join(co_consts)+"]")) else: - values.append(repr(getattr(code, attr))) - _codeobjs[code] = "PyBytecode(\n" + ',\n'.join([' '* 4 + v for v in values])+")" + values.append((attr, repr(getattr(code, attr)))) + _codeobjs[code] = "PyBytecode(\n" + ',\n'.join([' '* 4 + v + ' # ' + attr for (attr, v) in values])+")" return "_codeobjs[%r]" % (name,) Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 18:11:57 UTC (rev 5986) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-27 01:45:48 UTC (rev 5987) @@ -17,8 +17,8 @@ } return opname; } - private boolean debug = false; + public PyObject _debug(int maxCount) { debug = maxCount > 0; this.maxCount = maxCount; @@ -66,7 +66,6 @@ co_code = codestring.toCharArray(); co_lnotab = null; // ignore } - private static final String[] __members__ = { "co_name", "co_argcount", "co_varnames", "co_filename", "co_firstlineno", @@ -173,15 +172,6 @@ } } - private static Why do_raise(ThreadState ts, PyObject type, PyObject value, PyTraceback traceback) { - PyException pye = type == null ? ts.exception : new PyException(type, value, traceback); - if (traceback == null) { - return Why.EXCEPTION; - } else { - return Why.RERAISE; - } - } - private static String stringify_blocks(PyFrame f) { if (f.f_exits == null || f.f_blockstate[0] == 0) { return "[]"; @@ -635,22 +625,22 @@ PyTraceback tb = (PyTraceback) (stack.pop()); PyObject value = stack.pop(); PyObject type = stack.pop(); - why = do_raise(ts, type, value, tb); + PyException.doRaise(type, value, tb); break; } case 2: { PyObject value = stack.pop(); PyObject type = stack.pop(); - why = do_raise(ts, type, value, null); + PyException.doRaise(type, value, null); break; } case 1: { PyObject type = stack.pop(); - why = do_raise(ts, type, null, null); + PyException.doRaise(type, null, null); break; } case 0: - why = do_raise(ts, null, null, null); + PyException.doRaise(null, null, null); break; default: throw Py.SystemError("bad RAISE_VARARGS oparg"); @@ -798,6 +788,7 @@ case Opcode.BUILD_MAP: stack.push(new PyDictionary()); + break; case Opcode.LOAD_ATTR: stack.push(stack.pop().__getattr__(co_names[oparg])); @@ -1073,6 +1064,7 @@ while (why != Why.NOT && blocksLeft(f)) { PyTryBlock b = popBlock(f); +// System.err.println("Processing block: " + b); assert (why != Why.YIELD); if (b.b_type == Opcode.SETUP_LOOP && why == Why.CONTINUE) { pushBlock(f, b); @@ -1282,7 +1274,9 @@ void rot(int n) { int end = stack.size(); List<PyObject> lastN = stack.subList(end - n, end); - Collections.rotate(lastN, n); +// System.err.print("rot(" + n + "): " + lastN.toString() + " -> "); + Collections.rotate(lastN, n - 1); +// System.err.println("rot(" + n + "): " + lastN.toString()); } int size() { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-27 02:44:12
|
Revision: 5989 http://jython.svn.sourceforge.net/jython/?rev=5989&view=rev Author: zyasoft Date: 2009-01-27 02:26:20 +0000 (Tue, 27 Jan 2009) Log Message: ----------- Fixed RAISE_VARARGS opcode to raise exceptions properly. Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBytecode.java Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-27 02:16:49 UTC (rev 5988) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-27 02:26:20 UTC (rev 5989) @@ -625,27 +625,22 @@ PyTraceback tb = (PyTraceback) (stack.pop()); PyObject value = stack.pop(); PyObject type = stack.pop(); - PyException.doRaise(type, value, tb); - break; + throw PyException.doRaise(type, value, tb); } case 2: { PyObject value = stack.pop(); PyObject type = stack.pop(); - PyException.doRaise(type, value, null); - break; + throw PyException.doRaise(type, value, null); } case 1: { PyObject type = stack.pop(); - PyException.doRaise(type, null, null); - break; + throw PyException.doRaise(type, null, null); } case 0: - PyException.doRaise(null, null, null); - break; + throw PyException.doRaise(null, null, null); default: throw Py.SystemError("bad RAISE_VARARGS oparg"); } - break; case Opcode.LOAD_LOCALS: stack.push(f.f_locals); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-26 18:12:02
|
Revision: 5986 http://jython.svn.sourceforge.net/jython/?rev=5986&view=rev Author: fwierzbicki Date: 2009-01-26 18:11:57 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Another try at separating out the Python specific bits of PackageManager. Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Added Paths: ----------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java Removed Paths: ------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java Added: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java (rev 0) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/BasePackageManager.java 2009-01-26 18:11:57 UTC (rev 5986) @@ -0,0 +1,1000 @@ +// Copyright (c) Corporation for National Research Initiatives +// Copyright 2000 Samuele Pedroni + +package org.python.core.packagecache; + +import java.io.BufferedInputStream; +import java.io.BufferedOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.EOFException; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.lang.reflect.Modifier; +import java.net.URL; +import java.net.URLConnection; +import java.security.AccessControlException; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; +import java.util.Properties; +import java.util.StringTokenizer; +import java.util.zip.ZipEntry; +import java.util.zip.ZipInputStream; + +import org.python.core.Options; +import org.python.core.Py; +import org.python.core.PyJavaPackage; +import org.python.core.PyList; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyStringMap; +import org.python.core.PySystemState; +import org.python.core.imp; +import org.python.core.util.RelativeFile; +import org.python.util.Generic; + +/** + * Base package manager. + */ +public abstract class BasePackageManager { + + /* from old PackageManager */ + protected PyList searchPath; + protected PyJavaPackage topLevelPackage; + + protected boolean indexModified; + + protected Map<String,JarXEntry> jarfiles; + + // for default cache (local fs based) impl + protected File cachedir; + + protected void message(String msg) { + Py.writeMessage("*sys-package-mgr*", msg); + } + + protected void warning(String warn) { + Py.writeWarning("*sys-package-mgr*", warn); + } + + protected void comment(String msg) { + Py.writeComment("*sys-package-mgr*", msg); + } + + protected void debug(String msg) { + Py.writeDebug("*sys-package-mgr*", msg); + } + + public abstract Object makeJavaPackage(String name, String classes, String jarfile); + + public void addJar(String jarfile, boolean cache) { + addJarToPackages(new File(jarfile), cache); + if (cache) { + saveCache(); + } + } + + public void addJarDir(String jdir, boolean cache) { + addJarDir(jdir, cache, cache); + } + + private void addJarDir(String jdir, boolean cache, boolean saveCache) { + File file = new File(jdir); + if (!file.isDirectory()) { + return; + } + String[] files = file.list(); + for (int i = 0; i < files.length; i++) { + String entry = files[i]; + if (entry.endsWith(".jar") || entry.endsWith(".zip")) { + addJarToPackages(new File(jdir, entry), cache); + } + } + if (saveCache) { + saveCache(); + } + } + + private void addJarPath(String path) { + StringTokenizer tok = new StringTokenizer(path, + java.io.File.pathSeparator); + while (tok.hasMoreTokens()) { + // ??pending: do jvms trim? how is interpreted entry=""? + String entry = tok.nextToken(); + addJarDir(entry, true, false); + } + } + + protected void findAllPackages(Properties registry) { + String paths = registry.getProperty("python.packages.paths", + "java.class.path,sun.boot.class.path"); + String directories = registry.getProperty( + "python.packages.directories", "java.ext.dirs"); + String fakepath = registry + .getProperty("python.packages.fakepath", null); + StringTokenizer tok = new StringTokenizer(paths, ","); + while (tok.hasMoreTokens()) { + String entry = tok.nextToken().trim(); + String tmp = registry.getProperty(entry); + if (tmp == null) { + continue; + } + addClassPath(tmp); + } + + tok = new StringTokenizer(directories, ","); + while (tok.hasMoreTokens()) { + String entry = tok.nextToken().trim(); + String tmp = registry.getProperty(entry); + if (tmp == null) { + continue; + } + addJarPath(tmp); + } + + if (fakepath != null) { + addClassPath(fakepath); + } + } + + public void notifyPackageImport(String pkg, String name) { + if (pkg != null && pkg.length() > 0) { + name = pkg + '.' + name; + } + Py.writeComment("import", "'" + name + "' as java package"); + } + + public Class findClass(String pkg, String name) { + Class c = findClass(pkg, name, "java class"); + if (c != null) { + Py.writeComment("import", "'" + name + "' as java class"); + } + return c; + } + + public Class findClass(String pkg, String name, String reason) { + if (pkg != null && pkg.length() > 0) { + name = pkg + '.' + name; + } + return Py.findClassEx(name, reason); + } + + /** + * Dynamically check if pkg.name exists as java pkg in the controlled + * hierarchy. Should be overriden. + * + * @param pkg parent pkg name + * @param name candidate name + * @return true if pkg exists + */ + public boolean packageExists(String pkg, String name) { + if (packageExists(this.getSearchPath(), pkg, name)) { + return true; + } + + PySystemState system = Py.getSystemState(); + + if (system.getClassLoader() == null + && packageExists(Py.getSystemState().path, pkg, name)) { + return true; + } + + return false; + } + + + /** + * Helper for {@link #packageExists(java.lang.String,java.lang.String)}. + * Scans for package pkg.name the directories in path. + */ + protected boolean packageExists(PyList path, String pkg, String name) { + String child = pkg.replace('.', File.separatorChar) + File.separator + + name; + + for (int i = 0; i < path.__len__(); i++) { + String dir = path.pyget(i).__str__().toString(); + + File f = new RelativeFile(dir, child); + if (f.isDirectory() && imp.caseok(f, name)) { + /* + * Figure out if we have a directory a mixture of python and + * java or just an empty directory (which means Java) or a + * directory with only Python source (which means Python). + */ + PackageExistsFileFilter m = new PackageExistsFileFilter(); + f.listFiles(m); + boolean exists = m.packageExists(); + if (exists) { + Py.writeComment("import", "java package as '" + + f.getAbsolutePath() + "'"); + } + return exists; + } + } + return false; + } + + /** + * @return the searchPath + */ + public PyList getSearchPath() { + return searchPath; + } + + /** + * @param searchPath the searchPath to set + */ + public void setSearchPath(PyList searchPath) { + this.searchPath = searchPath; + } + + /** + * @return the topLevelPackage + */ + public PyJavaPackage getTopLevelPackage() { + return topLevelPackage; + } + + /** + * @param topLevelPackage the topLevelPackage to set + */ + public void setTopLevelPackage(PyJavaPackage topLevelPackage) { + this.topLevelPackage = topLevelPackage; + } + + class PackageExistsFileFilter implements FilenameFilter { + private boolean java; + + private boolean python; + + public boolean accept(File dir, String name) { + if(name.endsWith(".py") || name.endsWith("$py.class") || name.endsWith("$_PyInner.class")) { + python = true; + }else if (name.endsWith(".class")) { + java = true; + } + return false; + } + + public boolean packageExists() { + if (this.python && !this.java) { + return false; + } + return true; + } + } + + /** + * Helper for {@link #doDir(PyJavaPackage,boolean,boolean)}. Scans for + * package jpkg content over the directories in path. Add to ret the founded + * classes/pkgs. Filter out classes using {@link #filterByName},{@link #filterByAccess}. + */ + protected void doDir(PyList path, PyList ret, PyJavaPackage jpkg, + boolean instantiate, boolean exclpkgs) { + String child = jpkg.__name__.replace('.', File.separatorChar); + + for (int i = 0; i < path.__len__(); i++) { + String dir = path.pyget(i).__str__().toString(); + if (dir.length() == 0) { + dir = null; + } + + File childFile = new File(dir, child); + + String[] list = childFile.list(); + if (list == null) { + continue; + } + + doList: for (int j = 0; j < list.length; j++) { + String jname = list[j]; + + File cand = new File(childFile, jname); + + int jlen = jname.length(); + + boolean pkgCand = false; + + if (cand.isDirectory()) { + if (!instantiate && exclpkgs) { + continue; + } + pkgCand = true; + } else { + if (!jname.endsWith(".class")) { + continue; + } + jlen -= 6; + } + + jname = jname.substring(0, jlen); + PyString name = new PyString(jname); + + if (filterByName(jname, pkgCand)) { + continue; + } + + // for opt maybe we should some hash-set for ret + if (jpkg.__dict__.has_key(name) || jpkg.clsSet.has_key(name) + || ret.__contains__(name)) { + continue; + } + + if (!Character.isJavaIdentifierStart(jname.charAt(0))) { + continue; + } + + for (int k = 1; k < jlen; k++) { + if (!Character.isJavaIdentifierPart(jname.charAt(k))) { + continue doList; + } + } + + if (!pkgCand) { + try { + int acc = checkAccess(new BufferedInputStream( + new FileInputStream(cand))); + if ((acc == -1) || filterByAccess(jname, acc)) { + continue; + } + } catch (IOException e) { + continue; + } + } + + if (instantiate) { + if (pkgCand) { + jpkg.addPackage(jname); + } else { + jpkg.addClass(jname, Py.findClass(jpkg.__name__ + "." + jname)); + } + } + + ret.append(name); + + } + } + + } + + /** + * Add directory dir (if exists) to {@link #searchPath}. + */ + public void addDirectory(File dir) { + try { + if (dir.getPath().length() == 0) { + this.getSearchPath().append(Py.EmptyString); + } else { + this.getSearchPath().append(new PyString(dir.getCanonicalPath())); + } + } catch (IOException e) { + warning("skipping bad directory, '" + dir + "'"); + } + } + + // ??pending: + // Uses simply split and not a StringTokenizer+trim to adhere to + // sun jvm parsing of classpath. + // E.g. "a;" is parsed by sun jvm as a, ""; the latter is interpreted + // as cwd. jview trims and cwd is per default in classpath. + // The logic here should work for both(...). Need to distinguish? + // This code does not avoid duplicates in searchPath. + // Should cause no problem (?). + + /** + * Adds "classpath" entry. Calls {@link #addDirectory} if path refers to a + * dir, {@link #addJarToPackages(java.io.File, boolean)} with param cache + * true if path refers to a jar. + */ + public void addClassPath(String path) { + PyList paths = new PyString(path).split(java.io.File.pathSeparator); + + for (int i = 0; i < paths.__len__(); i++) { + String entry = paths.pyget(i).toString(); + if (entry.endsWith(".jar") || entry.endsWith(".zip")) { + addJarToPackages(new File(entry), true); + } else { + File dir = new File(entry); + if (entry.length() == 0 || dir.isDirectory()) { + addDirectory(dir); + } + } + } + } + + //Copied from CachedJarsPackageManager + /** + * Filter class/pkg by name helper method - hook. The default impl. is used + * by {@link #addJarToPackages} in order to filter out classes whose name + * contains '$' (e.g. inner classes,...). Should be used or overriden by + * derived classes too. Also to be used in {@link #doDir}. + * + * @param name class/pkg name + * @param pkg if true, name refers to a pkg + * @return true if name must be filtered out + */ + protected boolean filterByName(String name, boolean pkg) { + return name.indexOf('$') != -1; + } + + /** + * Filter class by access perms helper method - hook. The default impl. is + * used by {@link #addJarToPackages} in order to filter out non-public + * classes. Should be used or overriden by derived classes too. Also to be + * used in {@link #doDir}. Access perms can be read with + * {@link #checkAccess}. + * + * @param name class name + * @param acc class access permissions as int + * @return true if name must be filtered out + */ + protected boolean filterByAccess(String name, int acc) { + return (acc & Modifier.PUBLIC) != Modifier.PUBLIC; + } + + private static String listToString(List<String> list) { + int n = list.size(); + StringBuilder ret = new StringBuilder(); + for (int i = 0; i < n; i++) { + ret.append(list.get(i)); + if (i < n - 1) { + ret.append(","); + } + } + return ret.toString(); + } + + // Add a single class from zipFile to zipPackages + // Only add valid, public classes + private void addZipEntry(Map<String, List<String>[]> zipPackages, ZipEntry entry, + ZipInputStream zip) throws IOException { + String name = entry.getName(); + // System.err.println("entry: "+name); + if (!name.endsWith(".class")) { + return; + } + + char sep = '/'; + int breakPoint = name.lastIndexOf(sep); + if (breakPoint == -1) { + breakPoint = name.lastIndexOf('\\'); + sep = '\\'; + } + + String packageName; + if (breakPoint == -1) { + packageName = ""; + } else { + packageName = name.substring(0, breakPoint).replace(sep, '.'); + } + + String className = name.substring(breakPoint + 1, name.length() - 6); + + if (filterByName(className, false)) { + return; + } + + List<String>[] vec = zipPackages.get(packageName); + if (vec == null) { + vec = new List[] { Generic.list(), Generic.list() }; + zipPackages.put(packageName, vec); + } + int access = checkAccess(zip); + if ((access != -1) && !filterByAccess(name, access)) { + vec[0].add(className); + } else { + vec[1].add(className); + } + } + + // Extract all of the packages in a single jarfile + private Map<String, String> getZipPackages(InputStream jarin) throws IOException { + Map<String, List<String>[]> zipPackages = Generic.map(); + + ZipInputStream zip = new ZipInputStream(jarin); + + ZipEntry entry; + while ((entry = zip.getNextEntry()) != null) { + addZipEntry(zipPackages, entry, zip); + zip.closeEntry(); + } + + // Turn each vector into a comma-separated String + Map<String, String> transformed = Generic.map(); + for (String key : zipPackages.keySet()) { + List<String>[] vec = zipPackages.get(key); + String classes = listToString(vec[0]); + if (vec[1].size() > 0) { + classes += '@' + listToString(vec[1]); + } + transformed.put(key, classes); + } + + return transformed; + } + + /** + * Gathers classes info from jar specified by jarurl URL. Eventually just + * using previously cached info. Eventually updated info is not cached. + * Persistent cache storage access goes through inOpenCacheFile() and + * outCreateCacheFile(). + */ + public void addJarToPackages(java.net.URL jarurl) { + addJarToPackages(jarurl, null, false); + } + + /** + * Gathers classes info from jar specified by jarurl URL. Eventually just + * using previously cached info. Eventually updated info is (re-)cached if + * param cache is true. Persistent cache storage access goes through + * inOpenCacheFile() and outCreateCacheFile(). + */ + public void addJarToPackages(URL jarurl, boolean cache) { + addJarToPackages(jarurl, null, cache); + } + + /** + * Gathers classes info from jar specified by File jarfile. Eventually just + * using previously cached info. Eventually updated info is not cached. + * Persistent cache storage access goes through inOpenCacheFile() and + * outCreateCacheFile(). + */ + public void addJarToPackages(File jarfile) { + addJarToPackages(null, jarfile, false); + } + + /** + * Gathers classes info from jar specified by File jarfile. Eventually just + * using previously cached info. Eventually updated info is (re-)cached if + * param cache is true. Persistent cache storage access goes through + * inOpenCacheFile() and outCreateCacheFile(). + */ + public void addJarToPackages(File jarfile, boolean cache) { + addJarToPackages(null, jarfile, cache); + } + + private void addJarToPackages(URL jarurl, File jarfile, boolean cache) { + try { + boolean caching = this.jarfiles != null; + + URLConnection jarconn = null; + boolean localfile = true; + + if (jarfile == null) { + jarconn = jarurl.openConnection(); + // This is necessary because 'file:' url-connections + // return always 0 through getLastModified (bug?). + // And in order to handle localfiles (from urls too) + // uniformly. + if (jarconn.getURL().getProtocol().equals("file")) { + // ??pending: need to use java2 URLDecoder.decode? + String jarfilename = jarurl.getFile(); + jarfilename = jarfilename.replace('/', File.separatorChar); + jarfile = new File(jarfilename); + } else { + localfile = false; + } + } + + if (localfile && !jarfile.exists()) { + return; + } + + Map<String, String> zipPackages = null; + + long mtime = 0; + String jarcanon = null; + JarXEntry entry = null; + boolean brandNew = false; + + if (caching) { + + if (localfile) { + mtime = jarfile.lastModified(); + jarcanon = jarfile.getCanonicalPath(); + } else { + mtime = jarconn.getLastModified(); + jarcanon = jarurl.toString(); + } + + entry = this.jarfiles.get(jarcanon); + + if ((entry == null || !(new File(entry.cachefile).exists())) + && cache) { + message("processing new jar, '" + jarcanon + "'"); + + String jarname; + if (localfile) { + jarname = jarfile.getName(); + } else { + jarname = jarurl.getFile(); + int slash = jarname.lastIndexOf('/'); + if (slash != -1) + jarname = jarname.substring(slash + 1); + } + jarname = jarname.substring(0, jarname.length() - 4); + + entry = new JarXEntry(jarname); + this.jarfiles.put(jarcanon, entry); + + brandNew = true; + } + + if (mtime != 0 && entry != null && entry.mtime == mtime) { + zipPackages = readCacheFile(entry, jarcanon); + } + + } + + if (zipPackages == null) { + caching = caching && cache; + + if (caching) { + this.indexModified = true; + if (entry.mtime != 0) { + message("processing modified jar, '" + jarcanon + "'"); + } + entry.mtime = mtime; + } + + InputStream jarin; + if (jarconn == null) { + jarin = new BufferedInputStream( + new FileInputStream(jarfile)); + } else { + jarin = jarconn.getInputStream(); + } + + zipPackages = getZipPackages(jarin); + + if (caching) { + writeCacheFile(entry, jarcanon, zipPackages, brandNew); + } + } + + addPackages(zipPackages, jarcanon); + } catch (IOException ioe) { + // silently skip any bad directories + warning("skipping bad jar, '" + + (jarfile != null ? jarfile.toString() : jarurl.toString()) + + "'"); + } + + } + + private void addPackages(Map<String,String> zipPackages, String jarfile) { + for (Entry<String,String> entry : zipPackages.entrySet()) { + String pkg = entry.getKey(); + String classes = entry.getValue(); + + int idx = classes.indexOf('@'); + if (idx >= 0 && Options.respectJavaAccessibility) { + classes = classes.substring(0, idx); + } + + makeJavaPackage(pkg, classes, jarfile); + } + } + + // Read in cache file storing package info for a single .jar + // Return null and delete this cachefile if it is invalid + private Map<String, String> readCacheFile(JarXEntry entry, String jarcanon) { + String cachefile = entry.cachefile; + long mtime = entry.mtime; + + debug("reading cache, '" + jarcanon + "'"); + + try { + DataInputStream istream = inOpenCacheFile(cachefile); + String old_jarcanon = istream.readUTF(); + long old_mtime = istream.readLong(); + if ((!old_jarcanon.equals(jarcanon)) || (old_mtime != mtime)) { + comment("invalid cache file: " + cachefile + ", " + jarcanon + + ":" + old_jarcanon + ", " + mtime + ":" + old_mtime); + deleteCacheFile(cachefile); + return null; + } + Map<String, String> packs = Generic.map(); + try { + while (true) { + String packageName = istream.readUTF(); + String classes = istream.readUTF(); + packs.put(packageName, classes); + } + } catch (EOFException eof) { + //ignore + } + istream.close(); + + return packs; + } catch (IOException ioe) { + // if (cachefile.exists()) cachefile.delete(); + return null; + } + } + + // Write a cache file storing package info for a single .jar + private void writeCacheFile(JarXEntry entry, String jarcanon, + Map<String,String> zipPackages, boolean brandNew) { + try { + DataOutputStream ostream = outCreateCacheFile(entry, brandNew); + ostream.writeUTF(jarcanon); + ostream.writeLong(entry.mtime); + comment("rewriting cachefile for '" + jarcanon + "'"); + + for (String packageName : zipPackages.keySet()) { + String classes = zipPackages.get(packageName); + ostream.writeUTF(packageName); + ostream.writeUTF(classes); + } + ostream.close(); + } catch (IOException ioe) { + warning("can't write cache file for '" + jarcanon + "'"); + } + } + + /** + * Initializes cache. Eventually reads back cache index. Index persistent + * storage is accessed through inOpenIndex(). + */ + protected void initCache() { + this.indexModified = false; + this.jarfiles = Generic.map(); + + try { + DataInputStream istream = inOpenIndex(); + if (istream == null) { + return; + } + + try { + while (true) { + String jarcanon = istream.readUTF(); + String cachefile = istream.readUTF(); + long mtime = istream.readLong(); + this.jarfiles.put(jarcanon, new JarXEntry(cachefile, mtime)); + } + } catch (EOFException eof) { + //ignore + } + istream.close(); + } catch (IOException ioe) { + warning("invalid index file"); + } + + } + + /** + * Write back cache index. Index persistent storage is accessed through + * outOpenIndex(). + */ + public void saveCache() { + if (jarfiles == null || !indexModified) { + return; + } + + indexModified = false; + + comment("writing modified index file"); + + try { + DataOutputStream ostream = outOpenIndex(); + for (Entry<String,JarXEntry> entry : jarfiles.entrySet()) { + String jarcanon = entry.getKey(); + JarXEntry xentry = entry.getValue(); + ostream.writeUTF(jarcanon); + ostream.writeUTF(xentry.cachefile); + ostream.writeLong(xentry.mtime); + } + ostream.close(); + } catch (IOException ioe) { + warning("can't write index file"); + } + } + + // hooks for changing cache storage + + /** + * To pass a cachefile id by ref. And for internal use. See + * outCreateCacheFile + */ + public static class JarXEntry extends Object { + /** cachefile id */ + public String cachefile; + + public long mtime; + + public JarXEntry(String cachefile) { + this.cachefile = cachefile; + } + + public JarXEntry(String cachefile, long mtime) { + this.cachefile = cachefile; + this.mtime = mtime; + } + + } + + /** + * Open cache index for reading from persistent storage - hook. Must Return + * null if this is absent. This default impl is part of the off-the-shelf + * local file-system cache impl. Can be overriden. + */ + protected DataInputStream inOpenIndex() throws IOException { + File indexFile = new File(this.cachedir, "packages.idx"); + + if (!indexFile.exists()) { + return null; + } + + DataInputStream istream = new DataInputStream(new BufferedInputStream( + new FileInputStream(indexFile))); + + return istream; + } + + /** + * Open cache index for writing back to persistent storage - hook. This + * default impl is part of the off-the-shelf local file-system cache impl. + * Can be overriden. + */ + protected DataOutputStream outOpenIndex() throws IOException { + File indexFile = new File(this.cachedir, "packages.idx"); + + return new DataOutputStream(new BufferedOutputStream( + new FileOutputStream(indexFile))); + } + + /** + * Open cache file for reading from persistent storage - hook. This default + * impl is part of the off-the-shelf local file-system cache impl. Can be + * overriden. + */ + protected DataInputStream inOpenCacheFile(String cachefile) + throws IOException { + return new DataInputStream(new BufferedInputStream(new FileInputStream( + cachefile))); + } + + /** + * Delete (invalidated) cache file from persistent storage - hook. This + * default impl is part of the off-the-shelf local file-system cache impl. + * Can be overriden. + */ + protected void deleteCacheFile(String cachefile) { + new File(cachefile).delete(); + } + + /** + * Create/open cache file for rewriting back to persistent storage - hook. + * If create is false, cache file is supposed to exist and must be opened + * for rewriting, entry.cachefile is a valid cachefile id. If create is + * true, cache file must be created. entry.cachefile is a flat jarname to be + * used to produce a valid cachefile id (to be put back in entry.cachefile + * on exit). This default impl is part of the off-the-shelf local + * file-system cache impl. Can be overriden. + */ + protected DataOutputStream outCreateCacheFile(JarXEntry entry, + boolean create) throws IOException { + File cachefile = null; + + if (create) { + int index = 1; + String suffix = ""; + String jarname = entry.cachefile; + while (true) { + cachefile = new File(this.cachedir, jarname + suffix + ".pkc"); + // System.err.println("try cachefile: "+cachefile); + if (!cachefile.exists()) { + break; + } + suffix = "$" + index; + index += 1; + } + entry.cachefile = cachefile.getCanonicalPath(); + } else + cachefile = new File(entry.cachefile); + + return new DataOutputStream(new BufferedOutputStream( + new FileOutputStream(cachefile))); + } + + /** + * Initialize off-the-shelf (default) local file-system cache impl. Must be + * called before {@link #initCache}. cachedir is the cache repository + * directory, this is eventually created. Returns true if dir works. + */ + protected boolean useCacheDir(File aCachedir1) { + if (aCachedir1 == null) { + return false; + } + try { + if(!aCachedir1.isDirectory() && aCachedir1.mkdirs() == false) { + warning("can't create package cache dir, '" + aCachedir1 + "'"); + return false; + } + } catch(AccessControlException ace) { + warning("The java security manager isn't allowing access to the package cache dir, '" + aCachedir1 + "'"); + return false; + } + + this.cachedir = aCachedir1; + + return true; + } + + /** + * Check that a given stream is a valid Java .class file. And return its + * access permissions as an int. + */ + static protected int checkAccess(java.io.InputStream cstream) + throws java.io.IOException { + java.io.DataInputStream istream = new java.io.DataInputStream(cstream); + + try { + int magic = istream.readInt(); + if (magic != 0xcafebabe) { + return -1; + } + } catch (EOFException eof) { + //Empty or 1 byte file. + return -1; + } + //int minor = + istream.readShort(); + //int major = + istream.readShort(); + + // Check versions??? + // System.out.println("magic: "+magic+", "+major+", "+minor); + int nconstants = istream.readShort(); + for (int i = 1; i < nconstants; i++) { + int cid = istream.readByte(); + // System.out.println(""+i+" : "+cid); + switch (cid) { + case 7: + istream.skipBytes(2); + break; + case 9: + case 10: + case 11: + istream.skipBytes(4); + break; + case 8: + istream.skipBytes(2); + break; + case 3: + case 4: + istream.skipBytes(4); + break; + case 5: + case 6: + istream.skipBytes(8); + i++; + break; + case 12: + istream.skipBytes(4); + break; + case 1: + // System.out.println("utf: "+istream.readUTF()+";"); + int slength = istream.readUnsignedShort(); + istream.skipBytes(slength); + break; + default: + // System.err.println("unexpected cid: "+cid+", "+i+", "+ + // nconstants); + // for (int j=0; j<10; j++) + // System.err.print(", "+istream.readByte()); + // System.err.println(); + return -1; + } + } + return istream.readShort(); + } + +} Deleted: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-26 17:17:52 UTC (rev 5985) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-26 18:11:57 UTC (rev 5986) @@ -1,37 +0,0 @@ -package org.python.core.packagecache; - -public interface PackageManager { - - Class findClass(String pkg, String name, String reason); - - Class findClass(String pkg, String name); - - void notifyPackageImport(String pkg, String name); - - boolean packageExists(String pkg, String name); - - /** - * Append a directory to the list of directories searched for java packages - * and java classes. - * - * @param dir A directory. - */ - void addDirectory(java.io.File dir); - - /** - * Append a directory to the list of directories searched for java packages - * and java classes. - * - * @param dir A directory name. - */ - void addJarDir(String dir, boolean cache); - - /** - * Append a jar file to the list of locations searched for java packages and - * java classes. - * - * @param jarfile A directory name. - */ - void addJar(String jarfile, boolean cache); - -} Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java 2009-01-26 17:17:52 UTC (rev 5985) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java 2009-01-26 18:11:57 UTC (rev 5986) @@ -7,9 +7,42 @@ import org.python.core.PyList; import org.python.core.PyObject; -public interface PyPackageManager extends PackageManager { +public interface PyPackageManager { + Class findClass(String pkg, String name, String reason); + + Class findClass(String pkg, String name); + + void notifyPackageImport(String pkg, String name); + + boolean packageExists(String pkg, String name); + /** + * Append a directory to the list of directories searched for java packages + * and java classes. + * + * @param dir A directory. + */ + void addDirectory(java.io.File dir); + + /** + * Append a directory to the list of directories searched for java packages + * and java classes. + * + * @param dir A directory name. + */ + void addJarDir(String dir, boolean cache); + + /** + * Append a jar file to the list of locations searched for java packages and + * java classes. + * + * @param jarfile A directory name. + */ + void addJar(String jarfile, boolean cache); + + + /** * Reports the specified package content names. Should be overriden. Used by * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. * @@ -33,5 +66,5 @@ * @param jarfile involved jarfile; can be null * @return created/updated package */ - PyJavaPackage makeJavaPackage(String name, String classes, String jarfile); + Object makeJavaPackage(String name, String classes, String jarfile); } Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-26 17:17:52 UTC (rev 5985) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-26 18:11:57 UTC (rev 5986) @@ -41,35 +41,8 @@ /** * System package manager. Used by org.python.core.PySystemState. */ -public class SysPackageManager implements PyPackageManager { +public class SysPackageManager extends BasePackageManager implements PyPackageManager{ - /* from old PackageManager */ - private PyList searchPath; - private PyJavaPackage topLevelPackage; - - private boolean indexModified; - - private Map<String,JarXEntry> jarfiles; - - // for default cache (local fs based) impl - private File cachedir; - - protected void message(String msg) { - Py.writeMessage("*sys-package-mgr*", msg); - } - - protected void warning(String warn) { - Py.writeWarning("*sys-package-mgr*", warn); - } - - protected void comment(String msg) { - Py.writeComment("*sys-package-mgr*", msg); - } - - protected void debug(String msg) { - Py.writeDebug("*sys-package-mgr*", msg); - } - public SysPackageManager(File cachedir, Properties registry) { /* from PathPackageManager constructor */ this.searchPath = new PyList(); @@ -84,98 +57,6 @@ } } - public void addJar(String jarfile, boolean cache) { - addJarToPackages(new File(jarfile), cache); - if (cache) { - saveCache(); - } - } - - public void addJarDir(String jdir, boolean cache) { - addJarDir(jdir, cache, cache); - } - - private void addJarDir(String jdir, boolean cache, boolean saveCache) { - File file = new File(jdir); - if (!file.isDirectory()) { - return; - } - String[] files = file.list(); - for (int i = 0; i < files.length; i++) { - String entry = files[i]; - if (entry.endsWith(".jar") || entry.endsWith(".zip")) { - addJarToPackages(new File(jdir, entry), cache); - } - } - if (saveCache) { - saveCache(); - } - } - - private void addJarPath(String path) { - StringTokenizer tok = new StringTokenizer(path, - java.io.File.pathSeparator); - while (tok.hasMoreTokens()) { - // ??pending: do jvms trim? how is interpreted entry=""? - String entry = tok.nextToken(); - addJarDir(entry, true, false); - } - } - - private void findAllPackages(Properties registry) { - String paths = registry.getProperty("python.packages.paths", - "java.class.path,sun.boot.class.path"); - String directories = registry.getProperty( - "python.packages.directories", "java.ext.dirs"); - String fakepath = registry - .getProperty("python.packages.fakepath", null); - StringTokenizer tok = new StringTokenizer(paths, ","); - while (tok.hasMoreTokens()) { - String entry = tok.nextToken().trim(); - String tmp = registry.getProperty(entry); - if (tmp == null) { - continue; - } - addClassPath(tmp); - } - - tok = new StringTokenizer(directories, ","); - while (tok.hasMoreTokens()) { - String entry = tok.nextToken().trim(); - String tmp = registry.getProperty(entry); - if (tmp == null) { - continue; - } - addJarPath(tmp); - } - - if (fakepath != null) { - addClassPath(fakepath); - } - } - - public void notifyPackageImport(String pkg, String name) { - if (pkg != null && pkg.length() > 0) { - name = pkg + '.' + name; - } - Py.writeComment("import", "'" + name + "' as java package"); - } - - public Class findClass(String pkg, String name) { - Class c = findClass(pkg, name, "java class"); - if (c != null) { - Py.writeComment("import", "'" + name + "' as java class"); - } - return c; - } - - public Class findClass(String pkg, String name, String reason) { - if (pkg != null && pkg.length() > 0) { - name = pkg + '.' + name; - } - return Py.findClassEx(name, reason); - } - public PyList doDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs) { PyList basic = basicDoDir(jpkg, instantiate, exclpkgs); @@ -192,770 +73,6 @@ return merge(basic, ret); } - /** - * Dynamically check if pkg.name exists as java pkg in the controlled - * hierarchy. Should be overriden. - * - * @param pkg parent pkg name - * @param name candidate name - * @return true if pkg exists - */ - public boolean packageExists(String pkg, String name) { - if (packageExists(this.getSearchPath(), pkg, name)) { - return true; - } - - PySystemState system = Py.getSystemState(); - - if (system.getClassLoader() == null - && packageExists(Py.getSystemState().path, pkg, name)) { - return true; - } - - return false; - } - - - /** - * Helper for {@link #packageExists(java.lang.String,java.lang.String)}. - * Scans for package pkg.name the directories in path. - */ - protected boolean packageExists(PyList path, String pkg, String name) { - String child = pkg.replace('.', File.separatorChar) + File.separator - + name; - - for (int i = 0; i < path.__len__(); i++) { - String dir = path.pyget(i).__str__().toString(); - - File f = new RelativeFile(dir, child); - if (f.isDirectory() && imp.caseok(f, name)) { - /* - * Figure out if we have a directory a mixture of python and - * java or just an empty directory (which means Java) or a - * directory with only Python source (which means Python). - */ - PackageExistsFileFilter m = new PackageExistsFileFilter(); - f.listFiles(m); - boolean exists = m.packageExists(); - if (exists) { - Py.writeComment("import", "java package as '" - + f.getAbsolutePath() + "'"); - } - return exists; - } - } - return false; - } - - /** - * @return the searchPath - */ - public PyList getSearchPath() { - return searchPath; - } - - /** - * @param searchPath the searchPath to set - */ - public void setSearchPath(PyList searchPath) { - this.searchPath = searchPath; - } - - /** - * @return the topLevelPackage - */ - public PyJavaPackage getTopLevelPackage() { - return topLevelPackage; - } - - /** - * @param topLevelPackage the topLevelPackage to set - */ - public void setTopLevelPackage(PyJavaPackage topLevelPackage) { - this.topLevelPackage = topLevelPackage; - } - - class PackageExistsFileFilter implements FilenameFilter { - private boolean java; - - private boolean python; - - public boolean accept(File dir, String name) { - if(name.endsWith(".py") || name.endsWith("$py.class") || name.endsWith("$_PyInner.class")) { - python = true; - }else if (name.endsWith(".class")) { - java = true; - } - return false; - } - - public boolean packageExists() { - if (this.python && !this.java) { - return false; - } - return true; - } - } - - /** - * Helper for {@link #doDir(PyJavaPackage,boolean,boolean)}. Scans for - * package jpkg content over the directories in path. Add to ret the founded - * classes/pkgs. Filter out classes using {@link #filterByName},{@link #filterByAccess}. - */ - protected void doDir(PyList path, PyList ret, PyJavaPackage jpkg, - boolean instantiate, boolean exclpkgs) { - String child = jpkg.__name__.replace('.', File.separatorChar); - - for (int i = 0; i < path.__len__(); i++) { - String dir = path.pyget(i).__str__().toString(); - if (dir.length() == 0) { - dir = null; - } - - File childFile = new File(dir, child); - - String[] list = childFile.list(); - if (list == null) { - continue; - } - - doList: for (int j = 0; j < list.length; j++) { - String jname = list[j]; - - File cand = new File(childFile, jname); - - int jlen = jname.length(); - - boolean pkgCand = false; - - if (cand.isDirectory()) { - if (!instantiate && exclpkgs) { - continue; - } - pkgCand = true; - } else { - if (!jname.endsWith(".class")) { - continue; - } - jlen -= 6; - } - - jname = jname.substring(0, jlen); - PyString name = new PyString(jname); - - if (filterByName(jname, pkgCand)) { - continue; - } - - // for opt maybe we should some hash-set for ret - if (jpkg.__dict__.has_key(name) || jpkg.clsSet.has_key(name) - || ret.__contains__(name)) { - continue; - } - - if (!Character.isJavaIdentifierStart(jname.charAt(0))) { - continue; - } - - for (int k = 1; k < jlen; k++) { - if (!Character.isJavaIdentifierPart(jname.charAt(k))) { - continue doList; - } - } - - if (!pkgCand) { - try { - int acc = checkAccess(new BufferedInputStream( - new FileInputStream(cand))); - if ((acc == -1) || filterByAccess(jname, acc)) { - continue; - } - } catch (IOException e) { - continue; - } - } - - if (instantiate) { - if (pkgCand) { - jpkg.addPackage(jname); - } else { - jpkg.addClass(jname, Py.findClass(jpkg.__name__ + "." + jname)); - } - } - - ret.append(name); - - } - } - - } - - /** - * Add directory dir (if exists) to {@link #searchPath}. - */ - public void addDirectory(File dir) { - try { - if (dir.getPath().length() == 0) { - this.getSearchPath().append(Py.EmptyString); - } else { - this.getSearchPath().append(new PyString(dir.getCanonicalPath())); - } - } catch (IOException e) { - warning("skipping bad directory, '" + dir + "'"); - } - } - - // ??pending: - // Uses simply split and not a StringTokenizer+trim to adhere to - // sun jvm parsing of classpath. - // E.g. "a;" is parsed by sun jvm as a, ""; the latter is interpreted - // as cwd. jview trims and cwd is per default in classpath. - // The logic here should work for both(...). Need to distinguish? - // This code does not avoid duplicates in searchPath. - // Should cause no problem (?). - - /** - * Adds "classpath" entry. Calls {@link #addDirectory} if path refers to a - * dir, {@link #addJarToPackages(java.io.File, boolean)} with param cache - * true if path refers to a jar. - */ - public void addClassPath(String path) { - PyList paths = new PyString(path).split(java.io.File.pathSeparator); - - for (int i = 0; i < paths.__len__(); i++) { - String entry = paths.pyget(i).toString(); - if (entry.endsWith(".jar") || entry.endsWith(".zip")) { - addJarToPackages(new File(entry), true); - } else { - File dir = new File(entry); - if (entry.length() == 0 || dir.isDirectory()) { - addDirectory(dir); - } - } - } - } - - //Copied from CachedJarsPackageManager - /** - * Filter class/pkg by name helper method - hook. The default impl. is used - * by {@link #addJarToPackages} in order to filter out classes whose name - * contains '$' (e.g. inner classes,...). Should be used or overriden by - * derived classes too. Also to be used in {@link #doDir}. - * - * @param name class/pkg name - * @param pkg if true, name refers to a pkg - * @return true if name must be filtered out - */ - protected boolean filterByName(String name, boolean pkg) { - return name.indexOf('$') != -1; - } - - /** - * Filter class by access perms helper method - hook. The default impl. is - * used by {@link #addJarToPackages} in order to filter out non-public - * classes. Should be used or overriden by derived classes too. Also to be - * used in {@link #doDir}. Access perms can be read with - * {@link #checkAccess}. - * - * @param name class name - * @param acc class access permissions as int - * @return true if name must be filtered out - */ - protected boolean filterByAccess(String name, int acc) { - return (acc & Modifier.PUBLIC) != Modifier.PUBLIC; - } - - private static String listToString(List<String> list) { - int n = list.size(); - StringBuilder ret = new StringBuilder(); - for (int i = 0; i < n; i++) { - ret.append(list.get(i)); - if (i < n - 1) { - ret.append(","); - } - } - return ret.toString(); - } - - // Add a single class from zipFile to zipPackages - // Only add valid, public classes - private void addZipEntry(Map<String, List<String>[]> zipPackages, ZipEntry entry, - ZipInputStream zip) throws IOException { - String name = entry.getName(); - // System.err.println("entry: "+name); - if (!name.endsWith(".class")) { - return; - } - - char sep = '/'; - int breakPoint = name.lastIndexOf(sep); - if (breakPoint == -1) { - breakPoint = name.lastIndexOf('\\'); - sep = '\\'; - } - - String packageName; - if (breakPoint == -1) { - packageName = ""; - } else { - packageName = name.substring(0, breakPoint).replace(sep, '.'); - } - - String className = name.substring(breakPoint + 1, name.length() - 6); - - if (filterByName(className, false)) { - return; - } - - List<String>[] vec = zipPackages.get(packageName); - if (vec == null) { - vec = new List[] { Generic.list(), Generic.list() }; - zipPackages.put(packageName, vec); - } - int access = checkAccess(zip); - if ((access != -1) && !filterByAccess(name, access)) { - vec[0].add(className); - } else { - vec[1].add(className); - } - } - - // Extract all of the packages in a single jarfile - private Map<String, String> getZipPackages(InputStream jarin) throws IOException { - Map<String, List<String>[]> zipPackages = Generic.map(); - - ZipInputStream zip = new ZipInputStream(jarin); - - ZipEntry entry; - while ((entry = zip.getNextEntry()) != null) { - addZipEntry(zipPackages, entry, zip); - zip.closeEntry(); - } - - // Turn each vector into a comma-separated String - Map<String, String> transformed = Generic.map(); - for (String key : zipPackages.keySet()) { - List<String>[] vec = zipPackages.get(key); - String classes = listToString(vec[0]); - if (vec[1].size() > 0) { - classes += '@' + listToString(vec[1]); - } - transformed.put(key, classes); - } - - return transformed; - } - - /** - * Gathers classes info from jar specified by jarurl URL. Eventually just - * using previously cached info. Eventually updated info is not cached. - * Persistent cache storage access goes through inOpenCacheFile() and - * outCreateCacheFile(). - */ - public void addJarToPackages(java.net.URL jarurl) { - addJarToPackages(jarurl, null, false); - } - - /** - * Gathers classes info from jar specified by jarurl URL. Eventually just - * using previously cached info. Eventually updated info is (re-)cached if - * param cache is true. Persistent cache storage access goes through - * inOpenCacheFile() and outCreateCacheFile(). - */ - public void addJarToPackages(URL jarurl, boolean cache) { - addJarToPackages(jarurl, null, cache); - } - - /** - * Gathers classes info from jar specified by File jarfile. Eventually just - * using previously cached info. Eventually updated info is not cached. - * Persistent cache storage access goes through inOpenCacheFile() and - * outCreateCacheFile(). - */ - public void addJarToPackages(File jarfile) { - addJarToPackages(null, jarfile, false); - } - - /** - * Gathers classes info from jar specified by File jarfile. Eventually just - * using previously cached info. Eventually updated info is (re-)cached if - * param cache is true. Persistent cache storage access goes through - * inOpenCacheFile() and outCreateCacheFile(). - */ - public void addJarToPackages(File jarfile, boolean cache) { - addJarToPackages(null, jarfile, cache); - } - - private void addJarToPackages(URL jarurl, File jarfile, boolean cache) { - try { - boolean caching = this.jarfiles != null; - - URLConnection jarconn = null; - boolean localfile = true; - - if (jarfile == null) { - jarconn = jarurl.openConnection(); - // This is necessary because 'file:' url-connections - // return always 0 through getLastModified (bug?). - // And in order to handle localfiles (from urls too) - // uniformly. - if (jarconn.getURL().getProtocol().equals("file")) { - // ??pending: need to use java2 URLDecoder.decode? - String jarfilename = jarurl.getFile(); - jarfilename = jarfilename.replace('/', File.separatorChar); - jarfile = new File(jarfilename); - } else { - localfile = false; - } - } - - if (localfile && !jarfile.exists()) { - return; - } - - Map<String, String> zipPackages = null; - - long mtime = 0; - String jarcanon = null; - JarXEntry entry = null; - boolean brandNew = false; - - if (caching) { - - if (localfile) { - mtime = jarfile.lastModified(); - jarcanon = jarfile.getCanonicalPath(); - } else { - mtime = jarconn.getLastModified(); - jarcanon = jarurl.toString(); - } - - entry = this.jarfiles.get(jarcanon); - - if ((entry == null || !(new File(entry.cachefile).exists())) - && cache) { - message("processing new jar, '" + jarcanon + "'"); - - String jarname; - if (localfile) { - jarname = jarfile.getName(); - } else { - jarname = jarurl.getFile(); - int slash = jarname.lastIndexOf('/'); - if (slash != -1) - jarname = jarname.substring(slash + 1); - } - jarname = jarname.substring(0, jarname.length() - 4); - - entry = new JarXEntry(jarname); - this.jarfiles.put(jarcanon, entry); - - brandNew = true; - } - - if (mtime != 0 && entry != null && entry.mtime == mtime) { - zipPackages = readCacheFile(entry, jarcanon); - } - - } - - if (zipPackages == null) { - caching = caching && cache; - - if (caching) { - this.indexModified = true; - if (entry.mtime != 0) { - message("processing modified jar, '" + jarcanon + "'"); - } - entry.mtime = mtime; - } - - InputStream jarin; - if (jarconn == null) { - jarin = new BufferedInputStream( - new FileInputStream(jarfile)); - } else { - jarin = jarconn.getInputStream(); - } - - zipPackages = getZipPackages(jarin); - - if (caching) { - writeCacheFile(entry, jarcanon, zipPackages, brandNew); - } - } - - addPackages(zipPackages, jarcanon); - } catch (IOException ioe) { - // silently skip any bad directories - ... [truncated message content] |
From: <am...@us...> - 2009-01-26 17:17:55
|
Revision: 5985 http://jython.svn.sourceforge.net/jython/?rev=5985&view=rev Author: amak Date: 2009-01-26 17:17:52 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Deleting an old version of the socket and select modules from the sandbox. These modules have long since been moved to trunk, and have evolved significantly. Removed Paths: ------------- trunk/sandbox/kennedya/asynch_sockets/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-26 05:02:26
|
Revision: 5984 http://jython.svn.sourceforge.net/jython/?rev=5984&view=rev Author: zyasoft Date: 2009-01-26 05:02:21 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Added extract tool (to be run by CPython) for creating test modules. Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBytecode.java Added Paths: ----------- branches/pbcvm/Tools/pbcvm/ branches/pbcvm/Tools/pbcvm/extract.py Added: branches/pbcvm/Tools/pbcvm/extract.py =================================================================== --- branches/pbcvm/Tools/pbcvm/extract.py (rev 0) +++ branches/pbcvm/Tools/pbcvm/extract.py 2009-01-26 05:02:21 UTC (rev 5984) @@ -0,0 +1,106 @@ +"""Given a module, codegens a new module where all functions imported +from it (using __all__ ?) are replaced with functions tied to +PyBytecode, including references to code objs in co_consts. Other +objects are simply imported from the original object. Hopefully this +provides an opportunity to test something two different ways, which +seems nice.""" + +import inspect +import sys +from collections import defaultdict + +attrs = ["co_" + x for x in """ + argcount nlocals stacksize flags + code consts names varnames + filename name firstlineno lnotab +""".split()] # add freevars cellvars? + +# this has to be instantiated per module! so simply move into a class +_codeobjs = {} +_codeobjs_names = {} +counters = defaultdict(int) + +# XXX - need to capture with a toposort the dependencies of +# recursive code objects and emit in that order + +def extract(mod): + functionobjs = candidate_functions(mod) + for name, f in functionobjs: + #print >> sys.stderr, "Extracting", f + extract_code_obj(f) + codes = {} + for code, definition in _codeobjs.iteritems(): + codes[_codeobjs_names[code]] = definition + print "from %s import *" % mod.__name__ + print "from org.python.core import PyBytecode, PyFunction" + print + print "_codeobjs = {}" + print + for name, obj in sorted(codes.iteritems()): + print "_codeobjs[%r] = %s" % (name, obj) + print + for name, f in functionobjs: + print "%s.func_code = _codeobjs[%r]" % (name, _codeobjs_names[f.func_code]) + + print + print 'if __name__ == "__main__":' + print ' test_main()' + + +def candidate_functions(mod): + """functions and methods we will retrieve code objects""" + + functions = inspect.getmembers(mod, inspect.isfunction) + functions = [(name, f) for (name, f) in functions if not inspect.isbuiltin(f)] + + classes = inspect.getmembers(mod, inspect.isclass) + for classname, cls in classes: + #print >> sys.stderr, "Extracting from", cls + for methodname, method in inspect.getmembers(cls, inspect.ismethod): + #print >> sys.stderr, "Extracting method", method + if inspect.getmodule(method) == mod: + functions.append(("%s.%s" % (classname, methodname), method)) + return functions + +# what if we are passed a builtin? need to identify that signature +def extract_code_obj(f_or_code): + if inspect.iscode(f_or_code): + code = f_or_code + else: + code = f_or_code.func_code + extract_def(code) + +def extract_def(code): + if code in _codeobjs_names: + print >> sys.stderr, "Already seen", code + return "_codeobjs[%r]" % (_codeobjs_names[code],) + + co_name = code.co_name + print >> sys.stderr, "Processing", code + name = co_name + "." + str(counters[co_name]) + counters[co_name] += 1 + _codeobjs_names[code] = name + # need to treat co_consts specially - maybe use pickling if repr is not suitable? + values = [] + for attr in attrs: + if attr == 'co_consts': + co_consts = [] + for const in getattr(code, attr): + if inspect.iscode(const): + print >> sys.stderr, "Extracting code const " + str(const) + co_consts.append(extract_def(const)) + else: + co_consts.append(repr(const)) + values.append("["+', '.join(co_consts)+"]") + elif attr == 'co_lnotab': + values.append(repr(None)) + else: + values.append(repr(getattr(code, attr))) + _codeobjs[code] = "PyBytecode(\n" + ',\n'.join([' '* 4 + v for v in values])+")" + return "_codeobjs[%r]" % (name,) + + +if __name__ == '__main__': + modname = sys.argv[1] + mod = __import__(modname) + extract(mod) Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 03:36:25 UTC (rev 5983) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 05:02:21 UTC (rev 5984) @@ -38,7 +38,7 @@ // follows new.code's interface public PyBytecode(int argcount, int nlocals, int stacksize, int flags, String codestring, PyObject[] constants, String[] names, String varnames[], - String filename, String name, int firstlineno, PyObject[] lnotab) { + String filename, String name, int firstlineno, String lnotab) { this(argcount, nlocals, stacksize, flags, codestring, constants, names, varnames, filename, name, firstlineno, lnotab, null, null); @@ -46,7 +46,7 @@ public PyBytecode(int argcount, int nlocals, int stacksize, int flags, String codestring, PyObject[] constants, String[] names, String varnames[], - String filename, String name, int firstlineno, PyObject[] lnotab, + String filename, String name, int firstlineno, String lnotab, String[] cellvars, String[] freevars) { co_argcount = nargs = argcount; co_varnames = varnames; @@ -56,18 +56,6 @@ co_cellvars = cellvars; co_freevars = freevars; co_name = name; - -// need to look at how this is used, since it's not part of the standard new.code interface -// this.varargs = varargs; -// if (varargs) { -// co_argcount -= 1; -// co_flags |= CO_VARARGS; -// } -// this.varkwargs = varkwargs; -// if (varkwargs) { -// co_argcount -= 1; -// co_flags |= CO_VARKEYWORDS; -// } varargs = (flags & CO_VARARGS) != 0; varkwargs = (flags & CO_VARKEYWORDS) != 0; co_flags |= flags; @@ -76,8 +64,9 @@ co_consts = constants; co_names = names; co_code = codestring.toCharArray(); - co_lnotab = lnotab; + co_lnotab = null; // ignore } + private static final String[] __members__ = { "co_name", "co_argcount", "co_varnames", "co_filename", "co_firstlineno", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-26 03:36:33
|
Revision: 5983 http://jython.svn.sourceforge.net/jython/?rev=5983&view=rev Author: cgroves Date: 2009-01-26 03:36:25 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Fix javatests Modified Paths: -------------- trunk/jython/src/org/python/core/PyNewWrapper.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java Modified: trunk/jython/src/org/python/core/PyNewWrapper.java =================================================================== --- trunk/jython/src/org/python/core/PyNewWrapper.java 2009-01-26 03:10:36 UTC (rev 5982) +++ trunk/jython/src/org/python/core/PyNewWrapper.java 2009-01-26 03:36:25 UTC (rev 5983) @@ -28,15 +28,15 @@ PyType subtype, PyObject[] args, String[] keywords); - + public PyBuiltinCallable bind(PyObject self) { throw Py.SystemError("__new__ wrappers are already bound"); } - + public PyType getWrappedType() { return for_type; } - + public void setWrappedType(PyType type) { self = type; for_type = type; @@ -48,26 +48,22 @@ public PyObject __call__(PyObject[] args, String[] keywords) { int nargs = args.length; - if(nargs < 1 || nargs == keywords.length) { - throw Py.TypeError(for_type.fastGetName() - + ".__new__(): not enough arguments"); + if (nargs < 1 || nargs == keywords.length) { + throw Py.TypeError(for_type.fastGetName() + ".__new__(): not enough arguments"); } PyObject arg0 = args[0]; - if(!(arg0 instanceof PyType)) { - throw Py.TypeError(for_type.fastGetName() - + ".__new__(X): X is not a type object (" + if (!(arg0 instanceof PyType)) { + throw Py.TypeError(for_type.fastGetName() + ".__new__(X): X is not a type object (" + arg0.getType().fastGetName() + ")"); } PyType subtype = (PyType)arg0; - if(!subtype.isSubType(for_type)) { - throw Py.TypeError(for_type.fastGetName() + ".__new__(" - + subtype.fastGetName() + "): " + subtype.fastGetName() - + " is not a subtype of " + for_type.fastGetName()); + if (!subtype.isSubType(for_type)) { + throw Py.TypeError(for_type.fastGetName() + ".__new__(" + subtype.fastGetName() + "): " + + subtype.fastGetName() + " is not a subtype of " + for_type.fastGetName()); } - if(subtype.getStatic() != for_type) { - throw Py.TypeError(for_type.fastGetName() + ".__new__(" - + subtype.fastGetName() + ") is not safe, use " - + subtype.fastGetName() + ".__new__()"); + if (subtype.getStatic() != for_type) { + throw Py.TypeError(for_type.fastGetName() + ".__new__(" + subtype.fastGetName() + + ") is not safe, use " + subtype.fastGetName() + ".__new__()"); } PyObject[] rest = new PyObject[nargs - 1]; System.arraycopy(args, 1, rest, 0, nargs - 1); Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-01-26 03:10:36 UTC (rev 5982) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-01-26 03:36:25 UTC (rev 5983) @@ -502,8 +502,9 @@ if (jarIndex >= 0) { int start = classpath.lastIndexOf(File.pathSeparator, jarIndex) + 1; root = classpath.substring(start, jarIndex); - } else { - // in case JYTHON_JAR is referenced from a MANIFEST inside another jar on the classpath + } else if (jarFileName != null) { + // in case JYTHON_JAR is referenced from a MANIFEST inside another jar on the + // classpath root = new File(jarFileName).getParent(); } } Modified: trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java =================================================================== --- trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java 2009-01-26 03:10:36 UTC (rev 5982) +++ trunk/jython/tests/java/org/python/expose/generate/TypeExposerTest.java 2009-01-26 03:36:25 UTC (rev 5983) @@ -2,9 +2,6 @@ import java.io.IOException; -import junit.framework.TestCase; - -import org.objectweb.asm.Type; import org.python.core.Py; import org.python.core.PyNewWrapper; import org.python.core.PyObject; @@ -38,8 +35,9 @@ .getResourceAsStream("org/python/expose/generate/TypeExposerTest$SimplestNew.class")); TypeBuilder te = etp.getTypeExposer().makeBuilder(); assertEquals(true, te.getIsBaseType()); - PyObject new_ = te.getDict(PyType.fromClass(SimplestNew.class)).__finditem__("__new__"); - assertEquals(Py.One, new_.__call__(PyType.fromClass(SimplestNew.class))); + PyType simplestType = PyType.fromClass(SimplestNew.class); + PyNewWrapper new_ = (PyNewWrapper)te.getDict(simplestType).__finditem__("__new__"); + assertEquals(Py.One, new_.new_impl(false, null, null, null)); } public void testCatchingDupes() throws IOException { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-26 03:10:39
|
Revision: 5982 http://jython.svn.sourceforge.net/jython/?rev=5982&view=rev Author: cgroves Date: 2009-01-26 03:10:36 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Try to assign to a static field for a given name in __setattr__ on a Java type before filling something in on the dict. Fixes bug #1241 Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyObject.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/PyType.java trunk/jython/tests/java/org/python/tests/Visible.java Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2009-01-26 02:21:05 UTC (rev 5981) +++ trunk/jython/Lib/test/test_java_visibility.py 2009-01-26 03:10:36 UTC (rev 5982) @@ -68,6 +68,11 @@ v = Visible() self.assertEquals(Results.PUBLIC_FIELD, v.visibleField) self.assertEquals(Results.PUBLIC_STATIC_FIELD, Visible.visibleStaticField) + Visible.visibleStaticField = Results.PUBLIC_STATIC_FIELD + 1 + self.assertEquals(Results.PUBLIC_STATIC_FIELD + 1, Visible.visibleStaticField) + self.assertEquals(Results.PUBLIC_STATIC_FIELD + 1, Visible.getVisibleStaticField()) + Visible.setVisibleStaticField(Results.PUBLIC_STATIC_FIELD) + self.assertEquals(Results.PUBLIC_STATIC_FIELD, Visible.visibleStaticField) self.assertEquals(Results.PUBLIC_METHOD, v.visibleInstance(0)) self.assertEquals(Results.OVERLOADED_PUBLIC_METHOD, v.visibleInstance('a')) self.assertEquals(Results.EXTRA_ARG_PUBLIC_METHOD, v.visibleInstance(0, 'b')) Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-26 02:21:05 UTC (rev 5981) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-26 03:10:36 UTC (rev 5982) @@ -56,45 +56,51 @@ super(TYPE == null ? fromClass(PyType.class) : TYPE); } - // Java types are ok with things being added and removed from their dicts as long as there isn't - // something there, so let these checks through - @Override - protected void checkDelattr() {} - - @Override - protected void checkSetattr() {} - protected boolean useMetatypeFirst(PyObject attr) { return !(attr instanceof PyReflectedField || attr instanceof PyReflectedFunction); } + // Java types are ok with things being added and removed from their dicts as long as there isn't @Override - public void addMethod(PyBuiltinMethod meth) { + void type___setattr__(String name, PyObject value) { + PyObject field = lookup(name);// If we have a static field that takes this, go with that + if (field != null) { + if (field._doset(null, value)) { + return; + } + } if (modified == null) { modified = Generic.set(); } - if (modified.add(meth.info.getName())) { + if (modified.add(name)) { if (conflicted != null) { for (PyJavaType conflict : conflicted) { - if (conflict.modified != null - && conflict.modified.contains(meth.info.getName())) { + if (conflict.modified != null && conflict.modified.contains(name)) { throw Py.TypeError(getName() - + " does not have a consistent method resolution" + " order with " - + conflict.getName() + ", and it already has " - + meth.info.getName() + " added for Python"); + + " does not have a consistent method resolution order with " + + conflict.getName() + ", and it already has " + name + + " added for Python"); } } } } - super.addMethod(meth); + object___setattr__(name, value); + postSetattr(name); } @Override - public void removeMethod(PyBuiltinMethod meth) { - super.removeMethod(meth); + void type___delattr__(String name) { + PyObject field = lookup(name); + if (field == null) { + throw Py.NameError("attribute not found: "+name); + } + if (!field.jdontdel()) { + object___delattr__(name); + } if (modified != null) { - modified.remove(meth.info.getName()); + modified.remove(name); } + postDelattr(name); } @Override @@ -136,8 +142,8 @@ types.add(othertype); } } - throw Py.TypeError(String.format("Supertypes that share a method " - + " have an MRO conflict[method=%s, types=%s]", method, types)); + throw Py.TypeError(String.format("Supertypes that share a modified attribute " + + " have an MRO conflict[attribute=%s, types=%s]", method, types)); } } } Modified: trunk/jython/src/org/python/core/PyObject.java =================================================================== --- trunk/jython/src/org/python/core/PyObject.java 2009-01-26 02:21:05 UTC (rev 5981) +++ trunk/jython/src/org/python/core/PyObject.java 2009-01-26 03:10:36 UTC (rev 5982) @@ -1033,10 +1033,6 @@ return false; } - boolean jtryset(PyObject container, PyObject value) { - return _doset(container, value); - } - boolean jdontdel() { return false; } @@ -3682,7 +3678,7 @@ object___setattr__(asName(name), value); } - private final void object___setattr__(String name, PyObject value) { + final void object___setattr__(String name, PyObject value) { PyObject descr = objtype.lookup(name); boolean set = false; Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2009-01-26 02:21:05 UTC (rev 5981) +++ trunk/jython/src/org/python/core/PySystemState.java 2009-01-26 03:10:36 UTC (rev 5982) @@ -327,7 +327,7 @@ setWarnoptions(value); } else { PyObject ret = getType().lookup(name); // xxx fix fix fix - if (ret != null && ret.jtryset(this, value)) { + if (ret != null && ret._doset(this, value)) { return; } __dict__.__setitem__(name, value); @@ -338,7 +338,7 @@ checkMustExist(name); PyObject ret = getType().lookup(name); // xxx fix fix fix if (ret != null) { - ret.jtryset(this, PyAttributeDeleted.INSTANCE); + ret._doset(this, PyAttributeDeleted.INSTANCE); } try { __dict__.__delitem__(name); Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-26 02:21:05 UTC (rev 5981) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-26 03:10:36 UTC (rev 5982) @@ -1092,26 +1092,26 @@ */ public void addMethod(PyBuiltinMethod meth) { PyMethodDescr pmd = meth.makeDescriptor(this); - dict.__setitem__(pmd.getName(), pmd); + __setattr__(pmd.getName(), pmd); } /** * Removes the given method from this type's dict or raises a KeyError. */ public void removeMethod(PyBuiltinMethod meth) { - dict.__delitem__(meth.info.getName()); + __delattr__(meth.info.getName()); } - protected void checkSetattr() { + void type___setattr__(String name, PyObject value) { if (builtin) { throw Py.TypeError(String.format("can't set attributes of built-in/extension type " + "'%s'", this.name)); } + super.__setattr__(name, value); + postSetattr(name); } - final void type___setattr__(String name, PyObject value) { - checkSetattr(); - super.__setattr__(name, value); + void postSetattr(String name) { if (name == "__set__") { if (!has_set && lookup("__set__") != null) { traverse_hierarchy(false, new OnType() { @@ -1145,15 +1145,19 @@ } protected void checkDelattr() { + } + + void type___delattr__(String name) { if (builtin) { throw Py.TypeError(String.format("can't set attributes of built-in/extension type " + "'%s'", this.name)); } + super.__delattr__(name); + postDelattr(name); } - final void type___delattr__(String name) { - checkDelattr(); - super.__delattr__(name); + + void postDelattr(String name) { if (name == "__set__") { if (has_set && lookup("__set__") == null) { traverse_hierarchy(false, new OnType() { @@ -1168,7 +1172,7 @@ }); } } else if (name == "__delete__") { - if (has_set && lookup("__delete__") == null) { + if (has_delete && lookup("__delete__") == null) { traverse_hierarchy(false, new OnType() { public boolean onType(PyType type) { boolean absent = type.getDict().__finditem__("__delete__") == null; Modified: trunk/jython/tests/java/org/python/tests/Visible.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Visible.java 2009-01-26 02:21:05 UTC (rev 5981) +++ trunk/jython/tests/java/org/python/tests/Visible.java 2009-01-26 03:10:36 UTC (rev 5982) @@ -58,4 +58,12 @@ public static int visibleStatic(int iinput, String input) { return EXTRA_ARG_PUBLIC_STATIC_METHOD; } + + public static int getVisibleStaticField() { + return visibleStaticField; + } + + public static void setVisibleStaticField(int newValue) { + visibleStaticField = newValue; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-26 02:21:09
|
Revision: 5981 http://jython.svn.sourceforge.net/jython/?rev=5981&view=rev Author: cgroves Date: 2009-01-26 02:21:05 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Defer resolving inner classes till the containing class is fully resolved. Fixes issue #1234. Modified Paths: -------------- trunk/jython/Lib/test/test_import_jy.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/inbred/ trunk/jython/tests/java/org/python/tests/inbred/Metis.java trunk/jython/tests/java/org/python/tests/inbred/Zeus.java Modified: trunk/jython/Lib/test/test_import_jy.py =================================================================== --- trunk/jython/Lib/test/test_import_jy.py 2009-01-26 01:19:12 UTC (rev 5980) +++ trunk/jython/Lib/test/test_import_jy.py 2009-01-26 02:21:05 UTC (rev 5981) @@ -153,6 +153,11 @@ self.assertEquals(subprocess.call([sys.executable, test_support.findfile("import_star_from_java.py")]), 0) + def test_selfreferential_classes(self): + from org.python.tests.inbred import Metis + from org.python.tests.inbred import Zeus + self.assertEquals(Metis, Zeus.Athena.__bases__[0]) + self.assertEquals(Zeus, Metis.__bases__[0]) def test_main(): test_support.run_unittest(MislabeledImportTestCase, Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-26 01:19:12 UTC (rev 5980) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-26 02:21:05 UTC (rev 5981) @@ -15,8 +15,6 @@ import java.util.Set; import org.python.core.util.StringUtil; -import org.python.expose.ExposeAsSuperclass; -import org.python.expose.ExposedType; import org.python.util.Generic; public class PyJavaType extends PyType { @@ -164,8 +162,9 @@ } computeMro(toMerge, mro); } + @Override - protected void init(Class<?> forClass) { + protected void init(Class<?> forClass, Set<PyJavaType> needsInners) { name = forClass.getName(); // Strip the java fully qualified class name from Py classes in core if (name.startsWith("org.python.core.Py")) { @@ -179,8 +178,9 @@ underlying_class = forClass; computeLinearMro(baseClass); } else { + needsInners.add(this); javaProxy = forClass; - objtype = PyType.fromClass(Class.class); + objtype = PyType.fromClassSkippingInners(Class.class, needsInners); // Wrapped Java types fill in their mro first using all of their interfaces then their // super class. List<PyObject> visibleBases = Generic.list(); @@ -191,16 +191,16 @@ // mro continue; } - visibleBases.add(PyType.fromClass(iface)); + visibleBases.add(PyType.fromClassSkippingInners(iface, needsInners)); } if (javaProxy == Object.class) { - base = PyType.fromClass(PyObject.class); + base = PyType.fromClassSkippingInners(PyObject.class, needsInners); } else if(baseClass == null) { - base = PyType.fromClass(Object.class); + base = PyType.fromClassSkippingInners(Object.class, needsInners); }else if (javaProxy == Class.class) { - base = PyType.fromClass(PyType.class); + base = PyType.fromClassSkippingInners(PyType.class, needsInners); } else { - base = PyType.fromClass(baseClass); + base = PyType.fromClassSkippingInners(baseClass, needsInners); } visibleBases.add(base); this.bases = visibleBases.toArray(new PyObject[visibleBases.size()]); @@ -449,21 +449,6 @@ } else { dict.__setitem__("__init__", reflctr); } - for (Class<?> inner : forClass.getClasses()) { - // Only add the class if there isn't something else with that name and it came from this - // class - if (inner.getDeclaringClass() == forClass && - dict.__finditem__(inner.getSimpleName()) == null) { - // If this class is currently being loaded, any exposed types it contains won't have - // set their builder in PyType yet, so add them to BOOTSTRAP_TYPES so they're - // created as PyType instead of PyJavaType - if (inner.getAnnotation(ExposedType.class) != null - || ExposeAsSuperclass.class.isAssignableFrom(inner)) { - Py.BOOTSTRAP_TYPES.add(inner); - } - dict.__setitem__(inner.getSimpleName(), PyType.fromClass(inner)); - } - } for (Map.Entry<Class<?>, PyBuiltinMethod[]> entry : getCollectionProxies().entrySet()) { if (entry.getKey() == forClass) { for (PyBuiltinMethod meth : entry.getValue()) { Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-26 01:19:12 UTC (rev 5980) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-26 02:21:05 UTC (rev 5981) @@ -357,7 +357,7 @@ * Called on builtin types for a particular class. Should fill in dict, name, mro, base and * bases from the class. */ - protected void init(Class<?> forClass) { + protected void init(Class<?> forClass, Set<PyJavaType> needsInners) { underlying_class = forClass; if (underlying_class == PyObject.class) { mro = new PyType[] {this}; @@ -939,24 +939,24 @@ } // The types in Py.BOOTSTRAP_TYPES are initialized before their builders are assigned, // so do the work of addFromClass & fillFromClass after the fact - fromClass(builder.getTypeClass()).init(builder.getTypeClass()); + fromClass(builder.getTypeClass()).init(builder.getTypeClass(), null); } } - private static PyType addFromClass(Class<?> c) { + private static PyType addFromClass(Class<?> c, Set<PyJavaType> needsInners) { if (ExposeAsSuperclass.class.isAssignableFrom(c)) { PyType exposedAs = fromClass(c.getSuperclass()); class_to_type.put(c, exposedAs); return exposedAs; } - return createType(c); + return createType(c, needsInners); } private static TypeBuilder getBuilder(Class<?> c) { return classToBuilder == null ? null : classToBuilder.get(c); } - private static PyType createType(Class<?> c) { + private static PyType createType(Class<?> c, Set<PyJavaType> needsInners) { PyType newtype; if (c == PyType.class) { newtype = new PyType(false); @@ -975,22 +975,56 @@ class_to_type.put(c, newtype); newtype.builtin = true; - newtype.init(c); + newtype.init(c,needsInners); return newtype; } public static synchronized PyType fromClass(Class<?> c) { if (class_to_type == null) { class_to_type = Generic.map(); - addFromClass(PyType.class); + addFromClass(PyType.class, null); } PyType type = class_to_type.get(c); if (type != null) { return type; } - return addFromClass(c); + // We haven't seen this class before, so it's type needs to be created. If it's being + // exposed as a Java class, defer processing its inner types until it's completely + // created in case the inner class references a class that references this class. + Set<PyJavaType> needsInners = Generic.set(); + PyType result = addFromClass(c, needsInners); + for (PyJavaType javaType : needsInners) { + Class<?> forClass = javaType.getProxyType(); + if (forClass == null) { + continue; + } + for (Class<?> inner : forClass.getClasses()) { + // Only add the class if there isn't something else with that name and it came from this + // class + if (inner.getDeclaringClass() == forClass && + javaType.dict.__finditem__(inner.getSimpleName()) == null) { + // If this class is currently being loaded, any exposed types it contains won't have + // set their builder in PyType yet, so add them to BOOTSTRAP_TYPES so they're + // created as PyType instead of PyJavaType + if (inner.getAnnotation(ExposedType.class) != null + || ExposeAsSuperclass.class.isAssignableFrom(inner)) { + Py.BOOTSTRAP_TYPES.add(inner); + } + javaType.dict.__setitem__(inner.getSimpleName(), PyType.fromClass(inner)); + } + } + } + return result; } + static PyType fromClassSkippingInners(Class<?> c, Set<PyJavaType> needsInners) { + PyType type = class_to_type.get(c); + if (type != null) { + return type; + } + return addFromClass(c, needsInners); + } + @ExposedMethod(doc = BuiltinDocs.type___getattribute___doc) final PyObject type___getattribute__(PyObject name) { String n = asName(name); Added: trunk/jython/tests/java/org/python/tests/inbred/Metis.java =================================================================== --- trunk/jython/tests/java/org/python/tests/inbred/Metis.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/inbred/Metis.java 2009-01-26 02:21:05 UTC (rev 5981) @@ -0,0 +1,3 @@ +package org.python.tests.inbred; + +public interface Metis extends Zeus {} Added: trunk/jython/tests/java/org/python/tests/inbred/Zeus.java =================================================================== --- trunk/jython/tests/java/org/python/tests/inbred/Zeus.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/inbred/Zeus.java 2009-01-26 02:21:05 UTC (rev 5981) @@ -0,0 +1,11 @@ +package org.python.tests.inbred; + +/** + * Zeus ate Metis to prevent her from giving birth, but Athena was born inside Zeus' head anyway. By + * the mythology Metis should extend from Oceanus and Tethys, but we need Metis to extend Zeus to + * get the kind of inheritance that caused http://bugs.jython.org/issue1234 + */ +public interface Zeus { + + public interface Athena extends Metis {} +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-01-26 01:19:16
|
Revision: 5980 http://jython.svn.sourceforge.net/jython/?rev=5980&view=rev Author: zyasoft Date: 2009-01-26 01:19:12 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Properly handles *args, **kwargs for the receiver function. func_code can now be set to a PyBytecode (or other extender of PyBaseCode). Turned off debugging by default for PyBytecode objects. Modified Paths: -------------- branches/pbcvm/src/org/python/core/PyBytecode.java branches/pbcvm/src/org/python/core/PyFunction.java Modified: branches/pbcvm/src/org/python/core/PyBytecode.java =================================================================== --- branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 00:33:21 UTC (rev 5979) +++ branches/pbcvm/src/org/python/core/PyBytecode.java 2009-01-26 01:19:12 UTC (rev 5980) @@ -18,7 +18,9 @@ return opname; } + private boolean debug = false; public PyObject _debug(int maxCount) { + debug = maxCount > 0; this.maxCount = maxCount; return Py.None; } @@ -66,6 +68,8 @@ // co_argcount -= 1; // co_flags |= CO_VARKEYWORDS; // } + varargs = (flags & CO_VARARGS) != 0; + varkwargs = (flags & CO_VARKEYWORDS) != 0; co_flags |= flags; co_stacksize = stacksize; @@ -206,12 +210,14 @@ } private void print_debug(int count, int next_instr, int opcode, int oparg, PyStack stack, PyFrame f) { - System.err.println(co_name + ":" + - count + "," + f.f_lasti + "> opcode: " + - getOpname().__getitem__(Py.newInteger(opcode)) + - (opcode > Opcode.HAVE_ARGUMENT ? ", oparg: " + oparg : "") + - ", stack: " + stack.toString() + - ", blocks: " + stringify_blocks(f)); + if (debug) { + System.err.println(co_name + ":" + + count + "," + f.f_lasti + "> opcode: " + + getOpname().__getitem__(Py.newInteger(opcode)) + + (opcode > Opcode.HAVE_ARGUMENT ? ", oparg: " + oparg : "") + + ", stack: " + stack.toString() + + ", blocks: " + stringify_blocks(f)); + } } private static PyTryBlock popBlock(PyFrame f) { @@ -248,7 +254,9 @@ // 1. consider detaching the setting/getting of frame fields to improve performance, instead do this // in a shadow version of the frame that we copy back to on entry/exit and downcalls - System.err.println("Entry with " + f.f_lasti + " into " + co_code.length); + if (debug) { + System.err.println("Entry with " + f.f_lasti + " into " + co_code.length); + } if (f.f_lasti >= co_code.length) { throw Py.SystemError(""); } @@ -266,7 +274,7 @@ f.f_savedlocals = null; } - while (count < maxCount) { // XXX - replace with while(true) + while (!debug || (count < maxCount)) { // XXX - replace with while(true) try { @@ -290,7 +298,6 @@ next_instr += 1; f.f_lasti = next_instr; // should have no worries about needing co_lnotab, just keep this current - switch (opcode) { case Opcode.NOP: break; @@ -910,7 +917,7 @@ break; case Opcode.JUMP_ABSOLUTE: - next_instr = oparg; // XXX - continue to a label is probably much better + next_instr = oparg; break; case Opcode.GET_ITER: { @@ -1048,7 +1055,7 @@ case Opcode.EXTENDED_ARG: opcode = co_code[next_instr++]; next_instr += 2; - oparg = oparg << 16 | ((co_code[next_instr - 1] << 8) + (co_code[next_instr - 2])); + oparg = oparg << 16 | ((co_code[next_instr] << 8) + co_code[next_instr - 1]); break; default: @@ -1058,7 +1065,6 @@ f.f_lasti, opcode))); throw Py.SystemError("unknown opcode"); - } // end switch } // end try catch (Throwable t) { @@ -1133,9 +1139,11 @@ f.f_lasti = next_instr; // need to update on function entry, etc - System.err.println(count + "," + f.f_lasti + "> Returning from " + why + ": " + retval + - ", stack: " + stack.toString() + - ", blocks: " + stringify_blocks(f)); + if (debug) { + System.err.println(count + "," + f.f_lasti + "> Returning from " + why + ": " + retval + + ", stack: " + stack.toString() + + ", blocks: " + stringify_blocks(f)); + } if (why == why.EXCEPTION) { throw ts.exception; Modified: branches/pbcvm/src/org/python/core/PyFunction.java =================================================================== --- branches/pbcvm/src/org/python/core/PyFunction.java 2009-01-26 00:33:21 UTC (rev 5979) +++ branches/pbcvm/src/org/python/core/PyFunction.java 2009-01-26 01:19:12 UTC (rev 5980) @@ -195,10 +195,10 @@ @ExposedSet(name = "func_code") public void setFuncCode(PyCode code) { - if (func_code == null || !(code instanceof PyTableCode)) { + if (func_code == null || !(code instanceof PyBaseCode)) { throw Py.TypeError("func_code must be set to a code object"); } - PyTableCode tcode = (PyTableCode)code; + PyBaseCode tcode = (PyBaseCode)code; int nfree = tcode.co_freevars == null ? 0 : tcode.co_freevars.length; int nclosure = func_closure != null ? func_closure.__len__() : 0; if (nclosure != nfree) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-26 00:33:27
|
Revision: 5979 http://jython.svn.sourceforge.net/jython/?rev=5979&view=rev Author: cgroves Date: 2009-01-26 00:33:21 +0000 (Mon, 26 Jan 2009) Log Message: ----------- Include Python Java subclasses as bases as well as the Java proxy type, as it may have additional methods in its Python. Return the proxyClass directly from getProxyType as we're setting that on Python subclasses now. Modified Paths: -------------- trunk/jython/Lib/test/test_java_subclasses.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java trunk/jython/tests/java/org/python/tests/Coercions.java Modified: trunk/jython/Lib/test/test_java_subclasses.py =================================================================== --- trunk/jython/Lib/test/test_java_subclasses.py 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/Lib/test/test_java_subclasses.py 2009-01-26 00:33:21 UTC (rev 5979) @@ -12,7 +12,7 @@ from java.awt import Color, Component, Dimension, Rectangle from javax.swing.table import AbstractTableModel -from org.python.tests import BeanInterface, Callbacker +from org.python.tests import BeanInterface, Callbacker, Coercions class InterfaceTest(unittest.TestCase): def test_java_calling_python_interface_implementation(self): @@ -117,16 +117,27 @@ pass def test_multilevel_override(self): - class SubDate(Date): - def toString(self): - s = Date.toString(self) - return 'SubDate -> Date' + runs = [] + class SubDate(Date): + def run(self): + runs.append("SubDate") - class SubSubDate(SubDate): + def method(self): + return "SubDateMethod" + + def toString(self): + s = Date.toString(self) + return 'SubDate -> Date' + + class SubSubDate(SubDate, Runnable): def toString(self): return 'SubSubDate -> ' + SubDate.toString(self) + self.assertEquals("SubDate -> Date", SubDate().toString()) self.assertEquals("SubSubDate -> SubDate -> Date", SubSubDate().toString()) + self.assertEquals("SubDateMethod", SubSubDate().method()) + Coercions.runRunnable(SubSubDate()) + self.assertEquals(["SubDate"], runs) def test_passthrough(self): class CallbackPassthrough(Callbacker.Callback): Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-26 00:33:21 UTC (rev 5979) @@ -58,11 +58,6 @@ super(TYPE == null ? fromClass(PyType.class) : TYPE); } - @Override - public Class<?> getProxyType() { - return (Class<?>)javaProxy; - } - // Java types are ok with things being added and removed from their dicts as long as there isn't // something there, so let these checks through @Override Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-26 00:33:21 UTC (rev 5979) @@ -191,13 +191,24 @@ List<PyObject> cleanedBases = Generic.list(); boolean addedProxyType = false; for (PyObject base : bases_list) { - if (base instanceof PyJavaType) { - if (!addedProxyType) { + if (!(base instanceof PyType)) { + cleanedBases.add(base); + continue; + } + Class<?> proxy = ((PyType)base).getProxyType(); + if (proxy == null) { + cleanedBases.add(base);// non-proxy types go straight into our lookup + } else { + if (!(base instanceof PyJavaType)) { + // python subclasses of proxy types need to be added as a base so their + // version of methods will show up + cleanedBases.add(base); + } else if (!addedProxyType) { + // Only add a single Java type, since everything's going to go through the + // proxy type cleanedBases.add(proxyType); addedProxyType = true; } - } else { - cleanedBases.add(base); } } bases_list = cleanedBases.toArray(new PyObject[cleanedBases.size()]); @@ -593,15 +604,7 @@ * Returns the Java Class that this type inherits from, or null if this type is Python-only. */ public Class<?> getProxyType() { - for (PyObject base : bases) { - if (base instanceof PyType) { - Class<?> javaType = ((PyType)base).getProxyType(); - if (javaType != null) { - return javaType; - } - } - } - return null; + return (Class<?>)javaProxy; } private synchronized void attachSubclass(PyType subtype) { @@ -1206,6 +1209,10 @@ throw Py.TypeError(String.format("can't delete %s.__name__", name)); } + /** + * Returns the actual dict underlying this type instance. Changes to Java types should go + * through {@link #addMethod} and {@link #removeMethod}, or unexpected mro errors can occur. + */ public PyObject fastGetDict() { return dict; } Modified: trunk/jython/tests/java/org/python/tests/Coercions.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-25 21:06:04 UTC (rev 5978) +++ trunk/jython/tests/java/org/python/tests/Coercions.java 2009-01-26 00:33:21 UTC (rev 5979) @@ -100,4 +100,8 @@ } return true; } + + public static void runRunnable(Runnable r){ + r.run(); + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2009-01-25 21:06:09
|
Revision: 5978 http://jython.svn.sourceforge.net/jython/?rev=5978&view=rev Author: nriley Date: 2009-01-25 21:06:04 +0000 (Sun, 25 Jan 2009) Log Message: ----------- Typo fix. Modified Paths: -------------- trunk/jython/registry Modified: trunk/jython/registry =================================================================== --- trunk/jython/registry 2009-01-25 20:13:29 UTC (rev 5977) +++ trunk/jython/registry 2009-01-25 21:06:04 UTC (rev 5978) @@ -1,4 +1,4 @@ -# Python Registry -*- ksh -*- +# Python Registry -*- sh -*- # This default registry sets many common options to their default values # All of these settings could be erased with no change in behavior @@ -17,7 +17,7 @@ python.cachedir = cachedir # Setting this property to true disables the package scan for the cachedir. -# Please be aware that disabling this will break imporing * from java packages +# Please be aware that disabling this will break importing * from java packages #python.cachedir.skip = false # Properties to check for initializing and updating the package cache This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-01-25 20:13:33
|
Revision: 5977 http://jython.svn.sourceforge.net/jython/?rev=5977&view=rev Author: fwierzbicki Date: 2009-01-25 20:13:29 +0000 (Sun, 25 Jan 2009) Log Message: ----------- Extract a general purpose "python free" interface for PackagManager and add the python specific methods to PyPackageManager (which extends PackageManager). Modified Paths: -------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/SyspathJavaLoader.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java Added Paths: ----------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java Removed Paths: ------------- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java 2009-01-25 12:19:58 UTC (rev 5976) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PyJavaPackage.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -3,7 +3,7 @@ package org.python.core; -import org.python.core.packagecache.PackageManager; +import org.python.core.packagecache.PyPackageManager; import java.util.StringTokenizer; @@ -26,7 +26,7 @@ /** (Control) package manager whose hierarchy contains this java pkg. */ - public PackageManager __mgr__; + public PyPackageManager __mgr__; public PyJavaPackage(String name) { this(name, null, null); @@ -36,12 +36,12 @@ this(name, null, jarfile); } - public PyJavaPackage(String name,PackageManager mgr) { + public PyJavaPackage(String name,PyPackageManager mgr) { this(name, mgr, null); } - public PyJavaPackage(String name,PackageManager mgr,String jarfile) { + public PyJavaPackage(String name,PyPackageManager mgr,String jarfile) { __file__ = jarfile; __name__ = name; @@ -113,7 +113,7 @@ /** * Used for 'from xyz import *', dynamically dir pkg filling up __dict__. It uses - * {@link PackageManager#doDir} implementation furnished by the control package manager with + * {@link PyPackageManager#doDir} implementation furnished by the control package manager with * instantiate true. The package manager should load classes with {@link #addClass} in the * package. * @@ -151,8 +151,8 @@ public void __setattr__(String attr, PyObject value) { if (attr == "__mgr__") { - PackageManager newMgr = Py.tojava(value, - PackageManager.class); + PyPackageManager newMgr = Py.tojava(value, + PyPackageManager.class); if (newMgr == null) { throw Py.TypeError("cannot set java package __mgr__ to None"); } Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java 2009-01-25 12:19:58 UTC (rev 5976) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/PySystemState.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -21,7 +21,7 @@ import org.python.Version; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; -import org.python.core.packagecache.PackageManager; +import org.python.core.packagecache.PyPackageManager; import org.python.core.packagecache.SysPackageManager; import org.python.modules.Setup; import org.python.modules.zipimport.zipimporter; @@ -80,7 +80,7 @@ private static Map<String,String> builtinNames; public static PyTuple builtin_module_names = null; - public static PackageManager packageManager; + public static PyPackageManager packageManager; private static File cachedir; private static PyList defaultPath; Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/SyspathJavaLoader.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/SyspathJavaLoader.java 2009-01-25 12:19:58 UTC (rev 5976) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/SyspathJavaLoader.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -82,7 +82,7 @@ } try { - // this has the side affect of adding the jar to the PackageManager during the + // this has the side affect of adding the jar to the PyPackageManager during the // initialization of the SyspathArchive path = new SyspathArchive(sys.getPath(path.toString())); } catch (Exception e) { Deleted: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-25 12:19:58 UTC (rev 5976) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -1,72 +0,0 @@ -// Copyright (c) Corporation for National Research Initiatives -// Copyright 2000 Samuele Pedroni - -package org.python.core.packagecache; - -import org.python.core.Py; -import org.python.core.PyJavaPackage; -import org.python.core.PyList; -import org.python.core.PyObject; -import org.python.core.PyStringMap; - -import java.io.EOFException; - -public interface PackageManager { - - Class findClass(String pkg, String name, String reason); - - Class findClass(String pkg, String name); - - void notifyPackageImport(String pkg, String name); - - boolean packageExists(String pkg, String name); - - /** - * Reports the specified package content names. Should be overriden. Used by - * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. - * - * @return resulting list of names (PyList of PyString) - * @param jpkg queried package - * @param instantiate if true then instatiate reported names in package dict - * @param exclpkgs exclude packages (just when instantiate is false) - */ - PyList doDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs); - - /** - * Append a directory to the list of directories searched for java packages - * and java classes. - * - * @param dir A directory. - */ - void addDirectory(java.io.File dir); - - /** - * Append a directory to the list of directories searched for java packages - * and java classes. - * - * @param dir A directory name. - */ - void addJarDir(String dir, boolean cache); - - /** - * Append a jar file to the list of locations searched for java packages and - * java classes. - * - * @param jarfile A directory name. - */ - void addJar(String jarfile, boolean cache); - - PyObject lookupName(String name); - - /** - * Creates package/updates statically known classes info. Uses - * {@link PyJavaPackage#addPackage(java.lang.String, java.lang.String) }, - * {@link PyJavaPackage#addPlaceholders}. - * - * @param name package name - * @param classes comma-separated string - * @param jarfile involved jarfile; can be null - * @return created/updated package - */ - PyJavaPackage makeJavaPackage(String name, String classes, String jarfile); -} Added: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java (rev 0) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -0,0 +1,37 @@ +package org.python.core.packagecache; + +public interface PackageManager { + + Class findClass(String pkg, String name, String reason); + + Class findClass(String pkg, String name); + + void notifyPackageImport(String pkg, String name); + + boolean packageExists(String pkg, String name); + + /** + * Append a directory to the list of directories searched for java packages + * and java classes. + * + * @param dir A directory. + */ + void addDirectory(java.io.File dir); + + /** + * Append a directory to the list of directories searched for java packages + * and java classes. + * + * @param dir A directory name. + */ + void addJarDir(String dir, boolean cache); + + /** + * Append a jar file to the list of locations searched for java packages and + * java classes. + * + * @param jarfile A directory name. + */ + void addJar(String jarfile, boolean cache); + +} Copied: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java (from rev 5960, trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PackageManager.java) =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java (rev 0) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/PyPackageManager.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -0,0 +1,37 @@ +// Copyright (c) Corporation for National Research Initiatives +// Copyright 2000 Samuele Pedroni + +package org.python.core.packagecache; + +import org.python.core.PyJavaPackage; +import org.python.core.PyList; +import org.python.core.PyObject; + +public interface PyPackageManager extends PackageManager { + + /** + * Reports the specified package content names. Should be overriden. Used by + * {@link PyJavaPackage#__dir__} and {@link PyJavaPackage#fillDir}. + * + * @return resulting list of names (PyList of PyString) + * @param jpkg queried package + * @param instantiate if true then instatiate reported names in package dict + * @param exclpkgs exclude packages (just when instantiate is false) + */ + PyList doDir(PyJavaPackage jpkg, boolean instantiate, boolean exclpkgs); + + //XXX + PyObject lookupName(String name); + + /** + * Creates package/updates statically known classes info. Uses + * {@link PyJavaPackage#addPackage(java.lang.String, java.lang.String) }, + * {@link PyJavaPackage#addPlaceholders}. + * + * @param name package name + * @param classes comma-separated string + * @param jarfile involved jarfile; can be null + * @return created/updated package + */ + PyJavaPackage makeJavaPackage(String name, String classes, String jarfile); +} Modified: trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java =================================================================== --- trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-25 12:19:58 UTC (rev 5976) +++ trunk/sandbox/wierzbicki/jlr_experiment/src/org/python/core/packagecache/SysPackageManager.java 2009-01-25 20:13:29 UTC (rev 5977) @@ -41,7 +41,7 @@ /** * System package manager. Used by org.python.core.PySystemState. */ -public class SysPackageManager implements PackageManager { +public class SysPackageManager implements PyPackageManager { /* from old PackageManager */ private PyList searchPath; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-25 12:20:00
|
Revision: 5976 http://jython.svn.sourceforge.net/jython/?rev=5976&view=rev Author: cgroves Date: 2009-01-25 12:19:58 +0000 (Sun, 25 Jan 2009) Log Message: ----------- Test support classes for the last commit Added Paths: ----------- trunk/jython/tests/java/org/python/tests/mro/ trunk/jython/tests/java/org/python/tests/mro/ConfusedOnGetitemAdd.java trunk/jython/tests/java/org/python/tests/mro/ConfusedOnImport.java trunk/jython/tests/java/org/python/tests/mro/FirstAndPost.java trunk/jython/tests/java/org/python/tests/mro/FirstAndSecond.java trunk/jython/tests/java/org/python/tests/mro/FirstPredefinedGetitem.java trunk/jython/tests/java/org/python/tests/mro/GetitemAdder.java trunk/jython/tests/java/org/python/tests/mro/PostAndFirst.java trunk/jython/tests/java/org/python/tests/mro/PostdefinedGetitem.java trunk/jython/tests/java/org/python/tests/mro/SecondAndFirst.java trunk/jython/tests/java/org/python/tests/mro/SecondPredefinedGetitem.java Added: trunk/jython/tests/java/org/python/tests/mro/ConfusedOnGetitemAdd.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/ConfusedOnGetitemAdd.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/ConfusedOnGetitemAdd.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,9 @@ +package org.python.tests.mro; + +/** + * If {@link GetitemAdder#addPredefined} is called, this class is imported, then + * {@link GetitemAdder#addPostdefined} is called, the call to postdefined should raise a TypeError + * as this class produces a MRO conflict between {@link FirstPredefinedGetitem} and + * {@link PostdefinedGetitem}. + */ +public interface ConfusedOnGetitemAdd extends FirstAndPost, PostAndFirst {} Added: trunk/jython/tests/java/org/python/tests/mro/ConfusedOnImport.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/ConfusedOnImport.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/ConfusedOnImport.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,8 @@ +package org.python.tests.mro; + +/** + * {@link GetitemAdder#addPredefined} is expected to be called before this class is imported. If + * that's happened, there's a MRO conflict between {@link FirstPredefinedGetitem} and + * {@link SecondPredefinedGetitem}, so importing this should cause a TypeError. + */ +public class ConfusedOnImport implements FirstAndSecond, SecondAndFirst {} Added: trunk/jython/tests/java/org/python/tests/mro/FirstAndPost.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/FirstAndPost.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/FirstAndPost.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,3 @@ +package org.python.tests.mro; + +public interface FirstAndPost extends FirstPredefinedGetitem, PostdefinedGetitem {} Added: trunk/jython/tests/java/org/python/tests/mro/FirstAndSecond.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/FirstAndSecond.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/FirstAndSecond.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,3 @@ +package org.python.tests.mro; + +public interface FirstAndSecond extends FirstPredefinedGetitem, SecondPredefinedGetitem {} Added: trunk/jython/tests/java/org/python/tests/mro/FirstPredefinedGetitem.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/FirstPredefinedGetitem.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/FirstPredefinedGetitem.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,3 @@ +package org.python.tests.mro; + +public interface FirstPredefinedGetitem {} Added: trunk/jython/tests/java/org/python/tests/mro/GetitemAdder.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/GetitemAdder.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/GetitemAdder.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,32 @@ +package org.python.tests.mro; + +import org.python.core.PyBuiltinMethod; +import org.python.core.PyBuiltinMethodNarrow; +import org.python.core.PyObject; +import org.python.core.PyType; + +public class GetitemAdder { + + public static void addPostdefined() { + PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getitem__", 1) { + + @Override + public PyObject __call__(PyObject arg) { + return arg; + } + }; + PyType.fromClass(PostdefinedGetitem.class).addMethod(meth); + } + + public static void addPredefined() { + PyBuiltinMethod meth = new PyBuiltinMethodNarrow("__getitem__", 1) { + + @Override + public PyObject __call__(PyObject arg) { + return arg; + } + }; + PyType.fromClass(FirstPredefinedGetitem.class).addMethod(meth); + PyType.fromClass(SecondPredefinedGetitem.class).addMethod(meth); + } +} \ No newline at end of file Added: trunk/jython/tests/java/org/python/tests/mro/PostAndFirst.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/PostAndFirst.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/PostAndFirst.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,3 @@ +package org.python.tests.mro; + +public interface PostAndFirst extends PostdefinedGetitem, FirstPredefinedGetitem {} Added: trunk/jython/tests/java/org/python/tests/mro/PostdefinedGetitem.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/PostdefinedGetitem.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/PostdefinedGetitem.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,3 @@ +package org.python.tests.mro; + +public interface PostdefinedGetitem {} Added: trunk/jython/tests/java/org/python/tests/mro/SecondAndFirst.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/SecondAndFirst.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/SecondAndFirst.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,4 @@ +package org.python.tests.mro; + + +public interface SecondAndFirst extends SecondPredefinedGetitem, FirstPredefinedGetitem {} Added: trunk/jython/tests/java/org/python/tests/mro/SecondPredefinedGetitem.java =================================================================== --- trunk/jython/tests/java/org/python/tests/mro/SecondPredefinedGetitem.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/mro/SecondPredefinedGetitem.java 2009-01-25 12:19:58 UTC (rev 5976) @@ -0,0 +1,4 @@ +package org.python.tests.mro; + + +public interface SecondPredefinedGetitem {} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-25 12:19:33
|
Revision: 5975 http://jython.svn.sourceforge.net/jython/?rev=5975&view=rev Author: cgroves Date: 2009-01-25 12:19:27 +0000 (Sun, 25 Jan 2009) Log Message: ----------- Use Python's mro to determine an mro for Java classes and interfaces. If the Java class has an mro conflict, resolve it by arbitrarily choosing an interface or class. If an interface or class involved in an mro conflict has had its dict modified, or has its dict modified, raise a TypeError. Modified Paths: -------------- trunk/jython/Lib/test/test_import_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyType.java Modified: trunk/jython/Lib/test/test_import_jy.py =================================================================== --- trunk/jython/Lib/test/test_import_jy.py 2009-01-25 12:15:25 UTC (rev 5974) +++ trunk/jython/Lib/test/test_import_jy.py 2009-01-25 12:19:27 UTC (rev 5975) @@ -8,6 +8,7 @@ import sys import tempfile import unittest +import subprocess from test import test_support from test_chdir import read, safe_mktemp, COMPILED_SUFFIX @@ -148,7 +149,11 @@ # causes a stack overflow if the bug occurs self.assertRaises(Exception, getattr, anygui, 'abc') + def test_import_star(self): + self.assertEquals(subprocess.call([sys.executable, + test_support.findfile("import_star_from_java.py")]), 0) + def test_main(): test_support.run_unittest(MislabeledImportTestCase, OverrideBuiltinsImportTestCase, Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2009-01-25 12:15:25 UTC (rev 5974) +++ trunk/jython/Lib/test/test_java_integration.py 2009-01-25 12:19:27 UTC (rev 5975) @@ -20,6 +20,7 @@ from org.python.core.util import FileUtil from org.python.tests import BeanImplementation, Child, Listenable, CustomizableMapHolder +from org.python.tests.mro import (ConfusedOnGetitemAdd, FirstPredefinedGetitem, GetitemAdder) class InstantiationTest(unittest.TestCase): def test_cant_instantiate_abstract(self): @@ -411,11 +412,19 @@ self.assertEquals(7, m.held["initial"], "Existing fields should still be accessible") self.assertEquals(7, m.initial) self.assertEquals(None, m.nonexistent, "Nonexistent fields should be passed on to the Map") + + def test_adding_on_interface(self): + GetitemAdder.addPredefined() + class UsesInterfaceMethod(FirstPredefinedGetitem): + pass + self.assertEquals("key", UsesInterfaceMethod()["key"]) + + def test_add_on_mro_conflict(self): + """Adding same-named methods to Java classes with MRO conflicts produces TypeError""" + GetitemAdder.addPredefined() + self.assertRaises(TypeError, __import__, "org.python.tests.mro.ConfusedOnImport") + self.assertRaises(TypeError, GetitemAdder.addPostdefined) - def test_import_star(self): - self.assertEquals(subprocess.call([sys.executable, - test_support.findfile("import_star_from_java.py")]), 0) - def test_main(): test_support.run_unittest(InstantiationTest, BeanTest, Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-01-25 12:15:25 UTC (rev 5974) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-01-25 12:19:27 UTC (rev 5975) @@ -35,6 +35,19 @@ private static Map<Class<?>, PyBuiltinMethod[]> collectionProxies; + /** + * Other Java classes this type has MRO conflicts with. This doesn't matter for Java method + * resolution, but if Python methods are added to the type, the added methods can't overlap with + * methods added to any of the types in this set. If this type doesn't have any known conflicts, + * this is null. + */ + private Set<PyJavaType> conflicted; + + /** + * The names of methods that have been added to this class. + */ + private Set<String> modified; + public static PyObject wrapJavaObject(Object o) { PyObject obj = new PyObjectDerived(PyType.fromClass(o.getClass())); obj.javaProxy = o; @@ -62,11 +75,101 @@ return !(attr instanceof PyReflectedField || attr instanceof PyReflectedFunction); } - PyObject[] compute_mro() { - return mro; + @Override + public void addMethod(PyBuiltinMethod meth) { + if (modified == null) { + modified = Generic.set(); + } + if (modified.add(meth.info.getName())) { + if (conflicted != null) { + for (PyJavaType conflict : conflicted) { + if (conflict.modified != null + && conflict.modified.contains(meth.info.getName())) { + throw Py.TypeError(getName() + + " does not have a consistent method resolution" + " order with " + + conflict.getName() + ", and it already has " + + meth.info.getName() + " added for Python"); + } + } + } + } + super.addMethod(meth); } @Override + public void removeMethod(PyBuiltinMethod meth) { + super.removeMethod(meth); + if (modified != null) { + modified.remove(meth.info.getName()); + } + } + + @Override + void handleMroError(MROMergeState[] toMerge, List<PyObject> mro) { + if (underlying_class != null) { + // If this descends from PyObject, don't do the Java mro cleanup + super.handleMroError(toMerge, mro); + } + Set<PyJavaType> inConflict = Generic.set(); + PyJavaType winner = null; + for (MROMergeState mergee : toMerge) { + for (int i = mergee.next; i < mergee.mro.length; i++) { + if (mergee.mro[i] == PyObject.TYPE + || mergee.mro[i] == PyType.fromClass(Object.class)) { + continue; + } + if (winner == null) { + // Pick an arbitrary class to be added to the mro next and break the conflict. + // If method name conflicts were allowed between methods added to Java types, + // it would go first, but that's prevented, so being a winner doesn't actually + // get it anything + winner = (PyJavaType)mergee.mro[i]; + } + inConflict.add((PyJavaType)mergee.mro[i]); + } + } + + Set<String> allModified = Generic.set(); + PyJavaType[] conflicted = inConflict.toArray(new PyJavaType[inConflict.size()]); + for (PyJavaType type : conflicted) { + if (type.modified == null) { + continue; + } + for (String method : type.modified) { + if (!allModified.add(method)) { // Another type in conflict has this method, fail + PyList types = new PyList(); + for (PyJavaType othertype : conflicted) { + if (othertype.modified != null && othertype.modified.contains(method)) { + types.add(othertype); + } + } + throw Py.TypeError(String.format("Supertypes that share a method " + + " have an MRO conflict[method=%s, types=%s]", method, types)); + } + } + } + + // We can keep trucking, there aren't any existing method name conflicts. Mark the + // conflicts in all the classes so further method additions can check for trouble + for (PyJavaType type : conflicted) { + for (PyJavaType otherType : inConflict) { + if (otherType != type) { + if (type.conflicted == null) { + type.conflicted = Generic.set(); + } + type.conflicted.add(otherType); + } + } + } + + // Add our winner to the mro, clear the clog, and try to finish the rest + mro.add(winner); + for (MROMergeState mergee : toMerge) { + mergee.removeFromUnmerged(winner); + } + computeMro(toMerge, mro); + } + @Override protected void init(Class<?> forClass) { name = forClass.getName(); // Strip the java fully qualified class name from Py classes in core @@ -83,31 +186,30 @@ } else { javaProxy = forClass; objtype = PyType.fromClass(Class.class); - // Wrapped Java types fill in their mro first using their base class and then all of - // their interfaces. - if (baseClass == null) { + // Wrapped Java types fill in their mro first using all of their interfaces then their + // super class. + List<PyObject> visibleBases = Generic.list(); + for (Class<?> iface : forClass.getInterfaces()) { + if (iface == PyProxy.class || iface == ClassDictInit.class) { + // Don't show the interfaces added by proxy type construction; otherwise Python + // subclasses of proxy types and another Java interface can't make a consistent + // mro + continue; + } + visibleBases.add(PyType.fromClass(iface)); + } + if (javaProxy == Object.class) { base = PyType.fromClass(PyObject.class); - } else if (javaProxy == Class.class) { + } else if(baseClass == null) { + base = PyType.fromClass(Object.class); + }else if (javaProxy == Class.class) { base = PyType.fromClass(PyType.class); } else { base = PyType.fromClass(baseClass); } - bases = new PyObject[1 + forClass.getInterfaces().length]; - bases[0] = base; - for (int i = 1; i < bases.length; i++) { - bases[i] = PyType.fromClass(forClass.getInterfaces()[i - 1]); - } - Set<PyObject> seen = Generic.set(); - List<PyObject> mros = Generic.list(); - mros.add(this); - for (PyObject obj : bases) { - for (PyObject mroObj : ((PyType)obj).mro) { - if (seen.add(mroObj)) { - mros.add(mroObj); - } - } - } - mro = mros.toArray(new PyObject[mros.size()]); + visibleBases.add(base); + this.bases = visibleBases.toArray(new PyObject[visibleBases.size()]); + mro = computeMro(); } // PyReflected* can't call or access anything from non-public classes that aren't in @@ -392,7 +494,8 @@ || getDescrMethod(forClass, "_doset", OO) != null; has_delete = getDescrMethod(forClass, "__delete__", PyObject.class) != null || getDescrMethod(forClass, "_dodel", PyObject.class) != null; - } else { + } + if (forClass == Object.class) { // Pass __eq__ and __repr__ through to subclasses of Object addMethod(new PyBuiltinMethodNarrow("__eq__", 1) { @Override @@ -468,42 +571,39 @@ */ private void handleSuperMethodArgCollisions(Class<?> forClass) { for (Class<?> iface : forClass.getInterfaces()) { - for (Method meth : iface.getMethods()) { - if (!Modifier.isPublic(meth.getDeclaringClass().getModifiers())) { - // Ignore methods from non-public interfaces as they're similarly bugged - continue; + mergeMethods(iface); + } + if (forClass.getSuperclass() != null) { + mergeMethods(forClass.getSuperclass()); + } + } + + private void mergeMethods(Class<?> parent) { + for (Method meth : parent.getMethods()) { + if (!Modifier.isPublic(meth.getDeclaringClass().getModifiers())) { + // Ignore methods from non-public interfaces as they're similarly bugged + continue; + } + String nmethname = normalize(meth.getName()); + PyObject[] where = new PyObject[1]; + PyObject obj = lookup_where(nmethname, where); + if (obj == null) { + // Nothing in our supertype hierarchy defines something with this name, so it + // must not be visible there. + continue; + } else if (where[0] == this) { + // This method is the only thing defining items in this class' dict, so it must + // be a PyReflectedFunction created here. See if it needs the current method + // added to it. + if (!((PyReflectedFunction)obj).handles(meth)) { + ((PyReflectedFunction)obj).addMethod(meth); } - String nmethname = normalize(meth.getName()); - PyObject[] where = new PyObject[1]; - PyObject obj = lookup_where(nmethname, where); - if (obj == null) { - // Nothing in our supertype hierarchy defines something with this name, so it - // must not be visible there. - continue; - } else if (where[0] == this) { - // This method is the only thing defining items in this class' dict, so it must - // be a PyReflectedFunction created here. See if it needs the current method - // added to it. - if (!((PyReflectedFunction)obj).handles(meth)) { - ((PyReflectedFunction)obj).addMethod(meth); - } - } else { - // There's something in a superclass with the same name. If this class extends a - // class and doesn't just implement something, the extended class is first in - // mro, so items defined on the extended class will show up here. Thanks to that - // and copying the base function, we can get away with just looping over - // interface methods. - PyReflectedFunction func; - if (obj instanceof PyReflectedFunction) { - func = ((PyReflectedFunction)obj).copy(); - if (!func.handles(meth)) { - func.addMethod(meth); - } - } else { - func = new PyReflectedFunction(meth); - } - dict.__setitem__(nmethname, func); - } + } else { + // There's something in a superclass with the same name. Add an item to this type's + // dict to hide it. If it's this method, nothing's changed. If it's a field, we + // want to make the method visible. If it's a different method, it'll be added to + // the reflected function created here in a later call. + dict.__setitem__(nmethname, new PyReflectedFunction(meth)); } } } Modified: trunk/jython/src/org/python/core/PyType.java =================================================================== --- trunk/jython/src/org/python/core/PyType.java 2009-01-25 12:15:25 UTC (rev 5974) +++ trunk/jython/src/org/python/core/PyType.java 2009-01-25 12:19:27 UTC (rev 5975) @@ -507,7 +507,7 @@ private void mro_internal() { if (getType() == TYPE) { - mro = compute_mro(); + mro = computeMro(); } else { PyObject mroDescr = getType().lookup("mro"); if (mroDescr == null) { @@ -652,55 +652,18 @@ return acc.toArray(new PyObject[acc.size()]); } - private static boolean tail_contains(PyObject[] lst, int whence, PyObject o) { - int n = lst.length; - for (int i = whence + 1; i < n; i++) { - if (lst[i] == o) { - return true; - } - } - return false; - } - - private static PyException mro_error(PyObject[][] to_merge, int[] remain) { - StringBuilder msg = new StringBuilder("Cannot create a consistent method resolution\n" - + "order (MRO) for bases "); - PyDictionary set = new PyDictionary(); - for (int i = 0; i < to_merge.length; i++) { - PyObject[] lst = to_merge[i]; - if (remain[i] < lst.length) { - set.__setitem__(lst[remain[i]], Py.None); - } - } - PyObject iter = set.__iter__(); - PyObject cur; - boolean subq = false; - while ((cur = iter.__iternext__()) != null) { - PyObject name = cur.__findattr__("__name__"); - if (!subq) { - subq = true; - } else { - msg.append(", "); - } - msg.append(name == null ? "?" : name.toString()); - } - return Py.TypeError(msg.toString()); - } - @ExposedMethod(defaults = "null", doc = BuiltinDocs.type_mro_doc) final PyList type_mro(PyObject o) { if (o == null) { - return new PyList(compute_mro()); + return new PyList(computeMro()); } - return new PyList(((PyType)o).compute_mro()); + return new PyList(((PyType)o).computeMro()); } - PyObject[] compute_mro() { - PyObject[] bases = this.bases; - int n = bases.length; - for (int i = 0; i < n; i++) { + PyObject[] computeMro() { + for (int i = 0; i < bases.length; i++) { PyObject cur = bases[i]; - for (int j = i + 1; j < n; j++) { + for (int j = i + 1; j < bases.length; j++) { if (bases[j] == cur) { PyObject name = cur.__findattr__("__name__"); throw Py.TypeError("duplicate base class " + @@ -709,58 +672,77 @@ } } - int nmerge = n + 1; - PyObject[][] to_merge = new PyObject[nmerge][]; - int[] remain = new int[nmerge]; - - for (int i = 0; i < n; i++) { - PyObject cur = bases[i]; - remain[i] = 0; - if (cur instanceof PyType) { - to_merge[i] = ((PyType)cur).mro; - } else if (cur instanceof PyClass) { - to_merge[i] = classic_mro((PyClass)cur); + MROMergeState[] toMerge = new MROMergeState[bases.length + 1]; + for (int i = 0; i < bases.length; i++) { + toMerge[i] = new MROMergeState(); + if (bases[i] instanceof PyType) { + toMerge[i].mro = ((PyType)bases[i]).mro; + } else if (bases[i] instanceof PyClass) { + toMerge[i].mro = classic_mro((PyClass)bases[i]); } } + toMerge[bases.length] = new MROMergeState(); + toMerge[bases.length].mro = bases; - to_merge[n] = bases; - remain[n] = 0; + List<PyObject> mro = Generic.list(); + mro.add(this); + return computeMro(toMerge, mro); + } - List<PyObject> acc = Generic.list(); - acc.add(this); - - int empty_cnt = 0; - - scan : for (int i = 0; i < nmerge; i++) { - PyObject candidate; - PyObject[] cur = to_merge[i]; - if (remain[i] >= cur.length) { - empty_cnt++; + PyObject[] computeMro(MROMergeState[] toMerge, List<PyObject> mro) { + scan : for (int i = 0; i < toMerge.length; i++) { + if (toMerge[i].isMerged()) { continue scan; } - candidate = cur[remain[i]]; - for (int j = 0; j < nmerge; j++) - if (tail_contains(to_merge[j], remain[j], candidate)) { + PyObject candidate = toMerge[i].getCandidate(); + for (MROMergeState mergee : toMerge) { + if(mergee.unmergedContains(candidate)) { continue scan; } - acc.add(candidate); - for (int j = 0; j < nmerge; j++) { - if (remain[j] < to_merge[j].length && to_merge[j][remain[j]] == candidate) { - remain[j]++; - } } - // restart scan - i = -1; - empty_cnt = 0; + mro.add(candidate); + for (MROMergeState element : toMerge) { + element.noteMerged(candidate); + } + i = -1;// restart scan } - if (empty_cnt == nmerge) { - return acc.toArray(bases); + for (MROMergeState mergee : toMerge) { + if (!mergee.isMerged()) { + handleMroError(toMerge, mro); + } } - throw mro_error(to_merge, remain); + return mro.toArray(new PyObject[mro.size()]); } + /** + * Must either throw an exception, or bring the merges in <code>toMerge</code> to completion by + * finishing filling in <code>mro</code>. + */ + void handleMroError(MROMergeState[] toMerge, List<PyObject> mro) { + StringBuilder msg = new StringBuilder("Cannot create a consistent method resolution\n" + + "order (MRO) for bases "); + Set<PyObject> set = Generic.set(); + for (MROMergeState mergee : toMerge) { + if(!mergee.isMerged()) { + set.add(mergee.mro[0]); + } + } + boolean first = true; + for (PyObject unmerged : set) { + PyObject name = unmerged.__findattr__("__name__"); + if (first) { + first = false; + } else { + msg.append(", "); + } + msg.append(name == null ? "?" : name.toString() + new PyList(((PyType)unmerged).bases)); + } + throw Py.TypeError(msg.toString()); + } + + /** * Finds the parent of type with an underlying_class or with slots sans a __dict__ * slot. */ @@ -1076,6 +1058,13 @@ dict.__setitem__(pmd.getName(), pmd); } + /** + * Removes the given method from this type's dict or raises a KeyError. + */ + public void removeMethod(PyBuiltinMethod meth) { + dict.__delitem__(meth.info.getName()); + } + protected void checkSetattr() { if (builtin) { throw Py.TypeError(String.format("can't set attributes of built-in/extension type " @@ -1380,4 +1369,64 @@ return pytyp; } } + + /** + * Tracks the status of merging a single base into a subclass' mro in computeMro. + */ + static class MROMergeState { + + /** The mro of the base type we're representing. */ + public PyObject[] mro; + + /** + * The index of the next item to be merged from mro, or mro.length if this base has been + * completely merged. + */ + public int next; + + public boolean isMerged() { + return mro.length == next; + } + + public PyObject getCandidate() { + return mro[next]; + } + + /** + * Marks candidate as merged for this base if it's the next item to be merged. + */ + public void noteMerged(PyObject candidate) { + if (!isMerged() && getCandidate() == candidate) { + next++; + } + } + + /** + * Returns true if candidate is in the items past this state's next item to be merged. + */ + public boolean unmergedContains(PyObject candidate) { + for (int i = next + 1; i < mro.length; i++) { + if (mro[i] == candidate) { + return true; + } + } + return false; + } + + /** + * Removes the given item from this state's mro if it isn't already finished. + */ + public void removeFromUnmerged(PyJavaType winner) { + if (isMerged()) { + return; + } + List<PyObject> newMro = Generic.list(); + for (PyObject mroEntry : mro) { + if (mroEntry != winner) { + newMro.add(mroEntry); + } + } + mro = newMro.toArray(new PyObject[newMro.size()]); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-25 12:18:55
|
Revision: 5974 http://jython.svn.sourceforge.net/jython/?rev=5974&view=rev Author: cgroves Date: 2009-01-25 12:15:25 +0000 (Sun, 25 Jan 2009) Log Message: ----------- Bring up to the current state of affairs Modified Paths: -------------- trunk/jython/registry trunk/jython/src/org/python/core/Options.java Modified: trunk/jython/registry =================================================================== --- trunk/jython/registry 2009-01-24 20:17:39 UTC (rev 5973) +++ trunk/jython/registry 2009-01-25 12:15:25 UTC (rev 5974) @@ -17,7 +17,7 @@ python.cachedir = cachedir # Setting this property to true disables the package scan for the cachedir. -# Please be aware that disabling this might break some java import statements +# Please be aware that disabling this will break imporing * from java packages #python.cachedir.skip = false # Properties to check for initializing and updating the package cache @@ -25,10 +25,6 @@ python.packages.paths = java.class.path, sun.boot.class.path python.packages.directories = java.ext.dirs -# To force JIT compilation of Jython code -- should be unnecessary -# Setting this to true will cause jdk1.2rc1 to core dump on Windows -python.options.compileClass = false - # Set verbosity to error, warning, message, comment, or debug # for varying levels of informative messages from Jython. Normally # this option is set from the command line. @@ -45,23 +41,12 @@ # Setting this to a valid codec name will cause the console to use a # different encoding when reading commands from the console. -# The default java encoding is still used when reading python sources -# from the filesystem. #python.console.encoding = cp850 # Setting this to false will allow Jython to provide access to # non-public fields, methods, and constructors of Java objects. python.security.respectJavaAccessibility = true -# List of choices for internal tables impl (PyJavaClasses canonical map etc.), -# these are separated through ':' and tryed from left to right. -# For long running applications under java2, needing classes unloading, -# in order to have jython runtime automatically discarding -# no longer needed info and avoding memory leakage, this can be set -# to weak or soft (=> an impl. using weak-refs or soft-refs will be used). -#python.options.internalTablesImpl = soft -#python.options.internalTablesImpl = weak - # Setting this to true will force Jython will use the first module # found on sys.path where java File.isFile() returns true. # Setting this to true has no effect on unix-type filesystems. @@ -90,15 +75,3 @@ # functionality by having an entry such as os:com.foo.jni.os #python.modules.builtin = whatever -# This specifies the command used by jythonc to compile Java source -# code, along with the complete classpath to use. -# python.jythonc.compiler = /depot/java/plat/bin/jikes -# python.jythonc.classpath = /usr/java1.2/jre/lib/rt.jar:/Jython/dist:. -# python.jythonc.compileropts = +E +D -g - -# python.os determines operating-specific features, similar to and overriding the -# Java property "os.name". -# Some generic values are also supported: 'nt', 'ce' and 'posix'. -# Uncomment the following line for the most generic OS behavior available. -#python.os=None - Modified: trunk/jython/src/org/python/core/Options.java =================================================================== --- trunk/jython/src/org/python/core/Options.java 2009-01-24 20:17:39 UTC (rev 5973) +++ trunk/jython/src/org/python/core/Options.java 2009-01-25 12:15:25 UTC (rev 5974) @@ -54,12 +54,6 @@ public static int verbose = Py.MESSAGE; /** - * Setting this to true will support old 1.0 style keyword+"_" names. This - * isn't needed any more due to improvements in the parser - */ - public static boolean deprecatedKeywordMangling = false; - - /** * A directory where the dynamically generated classes are written. Nothing is * ever read from here, it is only for debugging purposes. */ @@ -131,9 +125,6 @@ "options.showPythonProxyExceptions", Options.showPythonProxyExceptions); - Options.deprecatedKeywordMangling = getBooleanOption( - "deprecated.keywordMangling", Options.deprecatedKeywordMangling); - Options.respectJavaAccessibility = getBooleanOption( "security.respectJavaAccessibility", Options.respectJavaAccessibility); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-24 20:17:43
|
Revision: 5973 http://jython.svn.sourceforge.net/jython/?rev=5973&view=rev Author: cgroves Date: 2009-01-24 20:17:39 +0000 (Sat, 24 Jan 2009) Log Message: ----------- Exclude the xerces service declaration as our jarjar'd version doesn't match the names in the declaration Modified Paths: -------------- trunk/jython/build.xml Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2009-01-24 20:11:54 UTC (rev 5972) +++ trunk/jython/build.xml 2009-01-24 20:17:39 UTC (rev 5973) @@ -532,7 +532,7 @@ <rule pattern="org.jruby.ext.posix.**" result="org.python.posix.@1"/> <zipfileset src="extlibs/constantine-0.4.jar"/> <rule pattern="com.kenai.constantine.**" result="org.python.constantine.@1"/> - <zipfileset src="extlibs/xercesImpl-2.9.1.jar"/> + <zipfileset src="extlibs/xercesImpl-2.9.1.jar" excludes="META-INF/services/*"/> <rule pattern="org.apache.xml.**" result="org.python.apache.xml.@1"/> <rule pattern="org.apache.xerces.**" result="org.python.apache.xerces.@1"/> <rule pattern="org.apache.wml.**" result="org.python.apache.wml.@1"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2009-01-24 20:11:56
|
Revision: 5972 http://jython.svn.sourceforge.net/jython/?rev=5972&view=rev Author: cgroves Date: 2009-01-24 20:11:54 +0000 (Sat, 24 Jan 2009) Log Message: ----------- Try the current classloader for places where the context classloader isn't set Modified Paths: -------------- trunk/jython/src/org/python/core/ClasspathPyImporter.java Modified: trunk/jython/src/org/python/core/ClasspathPyImporter.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporter.java 2009-01-24 20:10:59 UTC (rev 5971) +++ trunk/jython/src/org/python/core/ClasspathPyImporter.java 2009-01-24 20:11:54 UTC (rev 5972) @@ -83,27 +83,32 @@ } @Override - protected String makeEntry(String fullFilename) { - if (entries.containsKey(fullFilename)) { - return fullFilename; + protected String makeEntry(String filename) { + if (entries.containsKey(filename)) { + return filename; } - InputStream is = null; - ClassLoader classLoader = Py.getSystemState().getClassLoader(); - if (classLoader != null) { - Py.writeDebug("import", "trying " + fullFilename + " in sys class loader"); - is = classLoader.getResourceAsStream(fullFilename); + InputStream is = tryClassLoader(filename, Py.getSystemState().getClassLoader(), "sys"); + if (is == null) { + is = tryClassLoader(filename, Thread.currentThread().getContextClassLoader(), "context"); } if (is == null) { - Py.writeDebug("import", "trying " + fullFilename + " in context class loader"); - is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fullFilename); + is = tryClassLoader(filename, ClasspathPyImporter.class.getClassLoader(), "current"); } if (is != null) { - entries.put(fullFilename, is); - return fullFilename; + entries.put(filename, is); + return filename; } return null; } + private InputStream tryClassLoader(String fullFilename, ClassLoader loader, String name) { + if (loader != null) { + Py.writeDebug("import", "trying " + fullFilename + " in " + name + " class loader"); + return loader.getResourceAsStream(fullFilename); + } + return null; + } + @Override protected String makeFilename(String fullname) { return path.replace(PYCLASSPATH_PREFIX, "") + fullname.replace('.', '/'); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |