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: <cg...@us...> - 2008-12-31 22:55:19
|
Revision: 5819 http://jython.svn.sourceforge.net/jython/?rev=5819&view=rev Author: cgroves Date: 2008-12-31 21:36:03 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Abbreviating package to pkg makes it sound like it's going in a field named pkg. Modified Paths: -------------- trunk/jython/src/org/python/core/ClasspathPyImporter.java trunk/jython/src/org/python/core/util/importer.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Modified: trunk/jython/src/org/python/core/ClasspathPyImporter.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporter.java 2008-12-30 21:09:17 UTC (rev 5818) +++ trunk/jython/src/org/python/core/ClasspathPyImporter.java 2008-12-31 21:36:03 UTC (rev 5819) @@ -110,7 +110,7 @@ } @Override - protected String makePkgPath(String fullname) { + protected String makePackagePath(String fullname) { return path; } Modified: trunk/jython/src/org/python/core/util/importer.java =================================================================== --- trunk/jython/src/org/python/core/util/importer.java 2008-12-30 21:09:17 UTC (rev 5818) +++ trunk/jython/src/org/python/core/util/importer.java 2008-12-31 21:36:03 UTC (rev 5819) @@ -46,7 +46,7 @@ * Returns the value to fill in __path__ on a module with the given full module name created by * this importer. */ - protected abstract String makePkgPath(String fullname); + protected abstract String makePackagePath(String fullname); /** * Given a full module name, return the potential file path in the archive (without extension). @@ -95,7 +95,7 @@ if (moduleCodeData.ispackage) { // add __path__ to the module *before* the code gets executed PyList pkgpath = new PyList(); - pkgpath.add(makePkgPath(fullname)); + pkgpath.add(makePackagePath(fullname)); mod.__dict__.__setitem__("__path__", pkgpath); } imp.createFromCode(fullname, moduleCodeData.code, moduleCodeData.path); @@ -155,7 +155,7 @@ */ protected final ModuleCodeData getModuleCode(String fullname) { String path = makeFilename(fullname); - String fullPath = makePkgPath(fullname); + String fullPath = makePackagePath(fullname); if (path.length() < 0) { return null; Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-12-30 21:09:17 UTC (rev 5818) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-12-31 21:36:03 UTC (rev 5819) @@ -418,7 +418,7 @@ } @Override - protected String makePkgPath(String fullname) { + protected String makePackagePath(String fullname) { return archive + File.separator + prefix + getSubname(fullname); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-31 21:57:40
|
Revision: 5823 http://jython.svn.sourceforge.net/jython/?rev=5823&view=rev Author: fwierzbicki Date: 2008-12-31 21:57:35 +0000 (Wed, 31 Dec 2008) Log Message: ----------- test259.py -> test_codeop_jy.py Modified Paths: -------------- trunk/jython/Lib/test/test_codeop_jy.py Removed Paths: ------------- trunk/jython/bugtests/test259.py trunk/jython/bugtests/test259s.py Modified: trunk/jython/Lib/test/test_codeop_jy.py =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:56:48 UTC (rev 5822) +++ trunk/jython/Lib/test/test_codeop_jy.py 2008-12-31 21:57:35 UTC (rev 5823) @@ -171,6 +171,7 @@ ai("del (1,)") ai("del [1]") ai("del '1'") + ai("if (a == 1 and b = 2): pass") def test_filename(self): self.assertEquals(compile_("a = 1\n", "abc").co_filename, Deleted: trunk/jython/bugtests/test259.py =================================================================== --- trunk/jython/bugtests/test259.py 2008-12-31 21:56:48 UTC (rev 5822) +++ trunk/jython/bugtests/test259.py 2008-12-31 21:57:35 UTC (rev 5823) @@ -1,11 +0,0 @@ - -import support - - -try: - import test259s -except SyntaxError: - pass -else: - raise support.TestError, "Should raise a syntax error" - Deleted: trunk/jython/bugtests/test259s.py =================================================================== --- trunk/jython/bugtests/test259s.py 2008-12-31 21:56:48 UTC (rev 5822) +++ trunk/jython/bugtests/test259s.py 2008-12-31 21:57:35 UTC (rev 5823) @@ -1,9 +0,0 @@ - -var_a = 'blah' -var_b = 'halb' - -if (var_a == 'blah' and var_b = 'halb') : - print 'IT IS TRUE' -else : - print 'IT IS FALSE' - This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-31 21:56:51
|
Revision: 5822 http://jython.svn.sourceforge.net/jython/?rev=5822&view=rev Author: cgroves Date: 2008-12-31 21:56:48 +0000 (Wed, 31 Dec 2008) Log Message: ----------- Patch from David Morley to rename set in PySequence to pyset such that PySequence can be subclassed by List without requiring a type on List. See http://www.nabble.com/PySequence-set-method-incompatible-with-List%3CPyObject%3E--to14964846.html Modified Paths: -------------- trunk/jython/src/org/python/core/AstList.java trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySequence.java trunk/jython/src/org/python/core/PySequenceList.java Modified: trunk/jython/src/org/python/core/AstList.java =================================================================== --- trunk/jython/src/org/python/core/AstList.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/AstList.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -454,10 +454,6 @@ return new AstList(newList); } - protected void set(int i, PyObject value) { - data.set(i, value); - } - protected void setslice(int start, int stop, int step, PyObject value) { if(stop < start) { stop = start; @@ -587,13 +583,12 @@ return adapter.ast2py(data.get(index)); } - public PyObject pyset(int index, PyObject element) { + public void pyset(int index, PyObject element) { if (adapter == null) { - return (PyObject)data.set(index, element); + data.set(index, element); } Object o = adapter.py2ast(element); data.set(index, o); - return element; } public Object remove(int index) { Modified: trunk/jython/src/org/python/core/PyArray.java =================================================================== --- trunk/jython/src/org/python/core/PyArray.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PyArray.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -1312,6 +1312,10 @@ * value to set the element to */ public void set(int i, PyObject value) { + pyset(i, value); + } + + protected void pyset(int i, PyObject value) { if ("u".equals(typecode)) { Array.setInt(data, i, getCodePoint(value)); return; Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PyList.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -116,10 +116,6 @@ remove(start, stop); } - protected void set(int i, PyObject value) { - list.pyset(i, value); - } - protected void setslice(int start, int stop, int step, PyObject value) { if(stop < start) { stop = start; Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PySequence.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -63,7 +63,7 @@ * @param value * the value to set this element to. */ - protected void set(int index, PyObject value) { + protected void pyset(int index, PyObject value) { throw Py.TypeError("can't assign to immutable object"); } @@ -399,7 +399,7 @@ @Override public void setItem(int idx, PyObject value) { - set(idx, value); + pyset(idx, value); } @Override Modified: trunk/jython/src/org/python/core/PySequenceList.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceList.java 2008-12-31 21:38:23 UTC (rev 5821) +++ trunk/jython/src/org/python/core/PySequenceList.java 2008-12-31 21:56:48 UTC (rev 5822) @@ -99,8 +99,8 @@ return list.pyget(index); } - public PyObject pyset(int index, PyObject element) { - return list.pyset(index, element); + public void pyset(int index, PyObject element) { + list.pyset(index, element); } public Object remove(int index) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-30 21:09:21
|
Revision: 5818 http://jython.svn.sourceforge.net/jython/?rev=5818&view=rev Author: cgroves Date: 2008-12-30 21:09:17 +0000 (Tue, 30 Dec 2008) Log Message: ----------- Looks like the regrtest run by the buildbot needs derived classes Modified Paths: -------------- trunk/jython/src/templates/mappings Added Paths: ----------- trunk/jython/src/org/python/core/ClasspathPyImporterDerived.java trunk/jython/src/templates/ClasspathPyImporter.derived Added: trunk/jython/src/org/python/core/ClasspathPyImporterDerived.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporterDerived.java (rev 0) +++ trunk/jython/src/org/python/core/ClasspathPyImporterDerived.java 2008-12-30 21:09:17 UTC (rev 5818) @@ -0,0 +1,1136 @@ +/* Generated file, do not modify. See jython/src/templates/gderived.py. */ +package org.python.core; + +public class ClasspathPyImporterDerived extends ClasspathPyImporter implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + + public ClasspathPyImporterDerived(PyType subtype) { + super(subtype); + slots=new PyObject[subtype.getNumSlots()]; + } + + public PyString __str__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__str__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__str__(); + } + + public PyString __repr__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__repr__(); + } + + public PyString __hex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__hex__(); + } + + public PyString __oct__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__oct__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__oct__(); + } + + public PyFloat __float__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__float__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyFloat) + return(PyFloat)res; + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); + } + return super.__float__(); + } + + public PyComplex __complex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__complex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyComplex) + return(PyComplex)res; + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); + } + return super.__complex__(); + } + + public PyObject __pos__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pos__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__pos__(); + } + + public PyObject __neg__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__neg__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__neg__(); + } + + public PyObject __abs__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__abs__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__abs__(); + } + + public PyObject __invert__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__invert__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__invert__(); + } + + public PyObject __reduce__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__reduce__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__reduce__(); + } + + public PyObject __add__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__add__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__add__(other); + } + + public PyObject __radd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__radd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__radd__(other); + } + + public PyObject __sub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__sub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__sub__(other); + } + + public PyObject __rsub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rsub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rsub__(other); + } + + public PyObject __mul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mul__(other); + } + + public PyObject __rmul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmul__(other); + } + + public PyObject __div__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__div__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__div__(other); + } + + public PyObject __rdiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdiv__(other); + } + + public PyObject __floordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__floordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__floordiv__(other); + } + + public PyObject __rfloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rfloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rfloordiv__(other); + } + + public PyObject __truediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__truediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__truediv__(other); + } + + public PyObject __rtruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rtruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rtruediv__(other); + } + + public PyObject __mod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mod__(other); + } + + public PyObject __rmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmod__(other); + } + + public PyObject __divmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__divmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__divmod__(other); + } + + public PyObject __rdivmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdivmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdivmod__(other); + } + + public PyObject __rpow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rpow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rpow__(other); + } + + public PyObject __lshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lshift__(other); + } + + public PyObject __rlshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rlshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rlshift__(other); + } + + public PyObject __rshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rshift__(other); + } + + public PyObject __rrshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rrshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rrshift__(other); + } + + public PyObject __and__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__and__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__and__(other); + } + + public PyObject __rand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rand__(other); + } + + public PyObject __or__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__or__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__or__(other); + } + + public PyObject __ror__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ror__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ror__(other); + } + + public PyObject __xor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__xor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__xor__(other); + } + + public PyObject __rxor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rxor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rxor__(other); + } + + public PyObject __lt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lt__(other); + } + + public PyObject __le__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__le__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__le__(other); + } + + public PyObject __gt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__gt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__gt__(other); + } + + public PyObject __ge__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ge__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ge__(other); + } + + public PyObject __eq__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__eq__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__eq__(other); + } + + public PyObject __ne__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ne__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ne__(other); + } + + public PyObject __iadd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iadd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iadd__(other); + } + + public PyObject __isub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__isub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__isub__(other); + } + + public PyObject __imul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imul__(other); + } + + public PyObject __idiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__idiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__idiv__(other); + } + + public PyObject __ifloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ifloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ifloordiv__(other); + } + + public PyObject __itruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__itruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__itruediv__(other); + } + + public PyObject __imod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imod__(other); + } + + public PyObject __ipow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ipow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ipow__(other); + } + + public PyObject __ilshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ilshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ilshift__(other); + } + + public PyObject __irshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__irshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__irshift__(other); + } + + public PyObject __iand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iand__(other); + } + + public PyObject __ior__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ior__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ior__(other); + } + + public PyObject __ixor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ixor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ixor__(other); + } + + public PyObject __int__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__int__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) + return(PyObject)res; + throw Py.TypeError("__int__"+" should return an integer"); + } + return super.__int__(); + } + + public PyObject __long__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__long__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyLong||res instanceof PyInteger) + return res; + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); + } + return super.__long__(); + } + + public int hashCode() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hash__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) { + return((PyInteger)res).getValue(); + } else + if (res instanceof PyLong) { + return((PyLong)res).getValue().intValue(); + } + throw Py.TypeError("__hash__ should return a int"); + } + if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { + throw Py.TypeError(String.format("unhashable type: '%.200s'",getType().fastGetName())); + } + return super.hashCode(); + } + + public PyUnicode __unicode__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__unicode__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyUnicode) + return(PyUnicode)res; + if (res instanceof PyString) + return new PyUnicode((PyString)res); + throw Py.TypeError("__unicode__"+" should return a "+"unicode"); + } + return super.__unicode__(); + } + + public int __cmp__(PyObject other) { + PyType self_type=getType(); + PyType[]where_type=new PyType[1]; + PyObject impl=self_type.lookup_where("__cmp__",where_type); + // Full Compatibility with CPython __cmp__: + // If the derived type don't override __cmp__, the + // *internal* super().__cmp__ should be called, not the + // exposed one. The difference is that the exposed __cmp__ + // throws a TypeError if the argument is an instance of the same type. + if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { + return super.__cmp__(other); + } + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) { + return-2; + } + int c=res.asInt(); + return c<0?-1:c>0?1:0; + } + + public boolean __nonzero__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__nonzero__"); + if (impl==null) { + impl=self_type.lookup("__len__"); + if (impl==null) + return super.__nonzero__(); + } + PyObject o=impl.__get__(this,self_type).__call__(); + Class c=o.getClass(); + if (c!=PyInteger.class&&c!=PyBoolean.class) { + throw Py.TypeError(String.format("__nonzero__ should return bool or int, returned %s",self_type.getName())); + } + return o.__nonzero__(); + } + + public boolean __contains__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__contains__"); + if (impl==null) + return super.__contains__(o); + return impl.__get__(this,self_type).__call__(o).__nonzero__(); + } + + public int __len__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__len__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) + return((PyInteger)res).getValue(); + throw Py.TypeError("__len__ should return a int"); + } + return super.__len__(); + } + + public PyObject __iter__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iter__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + impl=self_type.lookup("__getitem__"); + if (impl==null) + return super.__iter__(); + return new PySequenceIter(this); + } + + public PyObject __iternext__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("next"); + if (impl!=null) { + try { + return impl.__get__(this,self_type).__call__(); + } catch (PyException exc) { + if (Py.matchException(exc,Py.StopIteration)) + return null; + throw exc; + } + } + return super.__iternext__(); // ??? + } + + public PyObject __finditem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(key); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __getitem__(PyObject key) { + // Same as __finditem__, without swallowing LookupErrors. This allows + // __getitem__ implementations written in Python to raise custom + // exceptions (such as subclasses of KeyError). + // + // We are forced to duplicate the code, instead of defining __finditem__ + // in terms of __getitem__. That's because PyObject defines __getitem__ + // in terms of __finditem__. Therefore, we would end with an infinite + // loop when self_type.lookup("__getitem__") returns null: + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ + // + // By duplicating the (short) lookup and call code, we are safe, because + // the call chains will be: + // + // __finditem__ -> super.__finditem__ + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ + + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(key); + return super.__getitem__(key); + } + + public void __setitem__(PyObject key,PyObject value) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key,value); + return; + } + super.__setitem__(key,value); + } + + public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); + } + return super.__getslice__(start,stop,step); + } + + public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); + return; + } + super.__setslice__(start,stop,step,value); + } + + public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); + return; + } + super.__delslice__(start,stop,step); + } + + public void __delitem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key); + return; + } + super.__delitem__(key); + } + + public PyObject __call__(PyObject args[],String keywords[]) { + ThreadState ts=Py.getThreadState(); + if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); + try { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__call__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(args,keywords); + return super.__call__(args,keywords); + } finally { + --ts.recursion_depth; + } + } + + public PyObject __findattr_ex__(String name) { + PyType self_type=getType(); + // TODO: We should speed this up. As the __getattribute__ slot almost never + // changes, it is a good candidate for caching, as PyClass does with + // __getattr__. See #1102. + PyObject getattribute=self_type.lookup("__getattribute__"); + PyString py_name=null; + PyException firstAttributeError=null; + try { + if (getattribute!=null) { + py_name=PyString.fromInterned(name); + return getattribute.__get__(this,self_type).__call__(py_name); + } else { + Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); + PyObject ret=super.__findattr_ex__(name); + if (ret!=null) { + return ret; + } // else: pass through to __getitem__ invocation + } + } catch (PyException e) { + if (!Py.matchException(e,Py.AttributeError)) { + throw e; + } else { + firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors + // and pass through to __getattr__ invocation. + } + } + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) { + if (py_name==null) { + py_name=PyString.fromInterned(name); + } + return getattr.__get__(this,self_type).__call__(py_name); + } + if (firstAttributeError!=null) { + throw firstAttributeError; + } + return null; + } + + public void __setattr__(String name,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); + return; + } + super.__setattr__(name,value); + } + + public void __delattr__(String name) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); + return; + } + super.__delattr__(name); + } + + public PyObject __get__(PyObject obj,PyObject type) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__get__"); + if (impl!=null) { + if (obj==null) + obj=Py.None; + if (type==null) + type=Py.None; + return impl.__get__(this,self_type).__call__(obj,type); + } + return super.__get__(obj,type); + } + + public void __set__(PyObject obj,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__set__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj,value); + return; + } + super.__set__(obj,value); + } + + public void __delete__(PyObject obj) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delete__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj); + return; + } + super.__delete__(obj); + } + + public PyObject __pow__(PyObject other,PyObject modulo) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pow__"); + if (impl!=null) { + PyObject res; + if (modulo==null) { + res=impl.__get__(this,self_type).__call__(other); + } else { + res=impl.__get__(this,self_type).__call__(other,modulo); + } + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__pow__(other,modulo); + } + + public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { + PyType self_type=getType(); + if (self_type.isSubType(type)) { + PyObject impl=self_type.lookup("__init__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(args,keywords); + if (res!=Py.None) { + throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); + } + proxyInit(); + } + } + } + + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + + public Object __tojava__(Class c) { + // If we are not being asked by the "default" conversion to java, then + // we can provide this as the result, as long as it is a instance of the + // specified class. Without this, derived.__tojava__(PyObject.class) + // would broke. (And that's not pure speculation: PyReflectedFunction's + // ReflectedArgs asks for things like that). + if ((c!=Object.class)&&(c.isInstance(this))) { + return this; + } + // Otherwise, we call the derived __tojava__, if it exists: + PyType self_type=getType(); + PyObject impl=self_type.lookup("__tojava__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava__(Object.class); + return super.__tojava__(c); + } + + public Object __coerce_ex__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__coerce__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(o); + if (res==Py.NotImplemented) + return Py.None; + if (!(res instanceof PyTuple)) + throw Py.TypeError("__coerce__ didn't return a 2-tuple"); + return((PyTuple)res).getArray(); + } + return super.__coerce_ex__(o); + } + + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + +} Added: trunk/jython/src/templates/ClasspathPyImporter.derived =================================================================== --- trunk/jython/src/templates/ClasspathPyImporter.derived (rev 0) +++ trunk/jython/src/templates/ClasspathPyImporter.derived 2008-12-30 21:09:17 UTC (rev 5818) @@ -0,0 +1,4 @@ +base_class: ClasspathPyImporter +want_dict: false +ctr +incl: object Modified: trunk/jython/src/templates/mappings =================================================================== --- trunk/jython/src/templates/mappings 2008-12-30 17:17:26 UTC (rev 5817) +++ trunk/jython/src/templates/mappings 2008-12-30 21:09:17 UTC (rev 5818) @@ -7,6 +7,7 @@ # lines; one for their expose, and one for their derived class. BaseException.derived:org.python.core.PyBaseExceptionDerived +ClasspathPyImporter.derived:org.python.core.ClasspathPyImporterDerived array.derived:org.python.core.PyArrayDerived bool.derived:org.python.core.PyBooleanDerived classmethod.derived:org.python.core.PyClassMethodDerived This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-12-30 17:17:29
|
Revision: 5817 http://jython.svn.sourceforge.net/jython/?rev=5817&view=rev Author: otmarhumbel Date: 2008-12-30 17:17:26 +0000 (Tue, 30 Dec 2008) Log Message: ----------- provide default answers where possible in console mode (less typing for the user) Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/ConsoleInstaller.java trunk/installer/src/java/org/python/util/install/TextConstants.java trunk/installer/src/java/org/python/util/install/TextConstants_de.java trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java Modified: trunk/installer/src/java/org/python/util/install/ConsoleInstaller.java =================================================================== --- trunk/installer/src/java/org/python/util/install/ConsoleInstaller.java 2008-12-30 08:17:05 UTC (rev 5816) +++ trunk/installer/src/java/org/python/util/install/ConsoleInstaller.java 2008-12-30 17:17:26 UTC (rev 5817) @@ -15,6 +15,8 @@ public class ConsoleInstaller implements ProgressListener, TextKeys { + public static final String CURRENT_JRE = "="; + private static final String _CANCEL = "c"; private static final String _PROMPT = ">>>"; @@ -23,7 +25,6 @@ private static final String _END_ANSWERS = "]"; - private static final String _CURRENT = "=="; private InstallerCommandLine _commandLine; @@ -80,25 +81,33 @@ } private String question(String question) { - return question(question, null, false); + return question(question, null, false, null); } private String question(String question, boolean answerRequired) { - return question(question, null, answerRequired); + return question(question, null, answerRequired, null); } - private String question(String question, List<String> answers) { - return question(question, answers, true); + private String question(String question, List<String> answers, String defaultAnswer) { + return question(question, answers, true, defaultAnswer); } /** * question and answer * + * @param question * @param answers * Possible answers (may be null) + * @param answerRequired + * @param defaultAnswer + * (may be null) + * * @return (chosen) answer */ - private String question(String question, List<String> answers, boolean answerRequired) { + private String question(String question, + List<String> answers, + boolean answerRequired, + String defaultAnswer) { try { if (answers != null && answers.size() > 0) { question = question + " " + _BEGIN_ANSWERS; @@ -106,7 +115,16 @@ while (answersAsIterator.hasNext()) { if (!question.endsWith(_BEGIN_ANSWERS)) question = question + "/"; - question = question + answersAsIterator.next(); + String possibleAnswer = answersAsIterator.next(); + if (possibleAnswer.equalsIgnoreCase(defaultAnswer)) { + if (Character.isDigit(possibleAnswer.charAt(0))) { + question = question.concat(" ").concat(possibleAnswer).concat(" "); + } else { + question = question + possibleAnswer.toUpperCase(); + } + } else { + question = question + possibleAnswer; + } } question = question + _END_ANSWERS; } @@ -117,22 +135,27 @@ // output to normal System.out System.out.print(question); // intended print, not println (!) answer = readLine(); - if (answers != null && answers.size() > 0) { - Iterator<String> answersAsIterator = answers.iterator(); - while (answersAsIterator.hasNext()) { - if (answer.equalsIgnoreCase(answersAsIterator.next())) { - match = true; - } + if ("".equals(answer) && answerRequired) { + // check default answer + if (defaultAnswer != null) { + match = true; + answer = defaultAnswer; } } else { - match = true; - if (answerRequired && "".equals(answer)) { - match = false; + if (answers != null && answers.size() > 0) { + Iterator<String> answersAsIterator = answers.iterator(); + while (answersAsIterator.hasNext()) { + if (answer.equalsIgnoreCase(answersAsIterator.next())) { + match = true; + } + } + } else { + match = true; } + if (!match && !_CANCEL.equalsIgnoreCase(answer)) { + message(getText(C_INVALID_ANSWER, answer)); + } } - if (!match && !_CANCEL.equalsIgnoreCase(answer)) { - message(getText(C_INVALID_ANSWER, answer)); - } } if (_CANCEL.equalsIgnoreCase(answer)) { throw new InstallationCancelledException(); @@ -172,15 +195,20 @@ availableLanguages.add(getText(C_GERMAN)); // 1 == German List<String> answers = new ArrayList<String>(availableLanguages.size()); String languages = ""; + String defaultAnswer = null; for (Iterator<String> iterator = availableLanguages.iterator(); iterator.hasNext();) { String language = iterator.next(); + String possibleAnswer = language.substring(0, 1); + if (defaultAnswer == null) { + defaultAnswer = possibleAnswer; + } languages = languages + language + ", "; - answers.add(language.substring(0, 1).toLowerCase()); + answers.add(possibleAnswer.toLowerCase()); } languages = languages.substring(0, languages.length() - 2); message(getText(C_AVAILABLE_LANGUAGES, languages)); - String answer = question(getText(C_SELECT_LANGUAGE), answers); - if (answer.equalsIgnoreCase((String)answers.get(1))) { + String answer = question(getText(C_SELECT_LANGUAGE), answers, defaultAnswer); + if (answer.equalsIgnoreCase(answers.get(1))) { Installation.setLanguage(Locale.GERMAN); } else { Installation.setLanguage(Locale.ENGLISH); @@ -196,7 +224,7 @@ message(" " + Installation.STANDARD + ". " + getText(C_STANDARD)); message(" " + Installation.MINIMUM + ". " + getText(C_MINIMUM)); message(" " + Installation.STANDALONE + ". " + getText(C_STANDALONE)); - String answer = question(getText(C_SELECT_INSTALL_TYPE), getTypeAnswers()); + String answer = question(getText(C_SELECT_INSTALL_TYPE), getTypeAnswers(), Installation.ALL); if (Installation.ALL.equals(answer)) { installationType.setAll(); } else if (Installation.STANDARD.equals(answer)) { @@ -209,10 +237,10 @@ if (!installationType.isStandalone()) { // include parts ? if (!installationType.isAll()) { - answer = question(getText(C_INCLUDE), getYNAnswers()); + answer = question(getText(C_INCLUDE), getYNAnswers(), no); if (yes.equals(answer)) { do { - answer = question(getText(C_INEXCLUDE_PARTS, no), getInExcludeAnswers()); + answer = question(getText(C_INEXCLUDE_PARTS, no), getInExcludeAnswers(), no); if (InstallerCommandLine.INEXCLUDE_LIBRARY_MODULES.equals(answer)) { installationType.addLibraryModules(); } else if (InstallerCommandLine.INEXCLUDE_DEMOS_AND_EXAMPLES.equals(answer)) { @@ -230,10 +258,10 @@ } // exclude parts ? if (!installationType.isMinimum()) { - answer = question(getText(C_EXCLUDE), getYNAnswers()); + answer = question(getText(C_EXCLUDE), getYNAnswers(), no); if (yes.equals(answer)) { do { - answer = question(getText(C_INEXCLUDE_PARTS, no), getInExcludeAnswers()); + answer = question(getText(C_INEXCLUDE_PARTS, no), getInExcludeAnswers(), no); if (InstallerCommandLine.INEXCLUDE_LIBRARY_MODULES.equals(answer)) { installationType.removeLibraryModules(); } else if (InstallerCommandLine.INEXCLUDE_DEMOS_AND_EXAMPLES.equals(answer)) { @@ -259,9 +287,7 @@ message(getText(C_JAVA_VERSION, javaInfo.getJavaVersionInfo().getVendor(), javaInfo.getJavaVersionInfo().getVersion())); - if (Installation.isValidJava(javaInfo.getJavaVersionInfo())) { - question(getText(C_PROCEED)); - } else { + if (!Installation.isValidJava(javaInfo.getJavaVersionInfo())) { message(getText(C_UNSUPPORTED_JAVA)); question(getText(C_PROCEED_ANYWAY)); } @@ -269,9 +295,7 @@ String osName = System.getProperty(Installation.OS_NAME); String osVersion = System.getProperty(Installation.OS_VERSION); message(getText(C_OS_VERSION, osName, osVersion)); - if (Installation.isValidOs()) { - question(getText(C_PROCEED)); - } else { + if (!Installation.isValidOs()) { message(getText(C_UNSUPPORTED_OS)); question(getText(C_PROCEED_ANYWAY)); } @@ -309,7 +333,9 @@ } private void acceptLicense() { - String read = question(getText(C_READ_LICENSE), getYNAnswers()); + String no = getText(C_NO); + String yes = getText(C_YES); + String read = question(getText(C_READ_LICENSE), getYNAnswers(), no); if (read.equalsIgnoreCase(getText(C_YES))) { String licenseText = "n/a"; try { @@ -319,13 +345,15 @@ throw new InstallerException(ioe); } } - String accept = question(getText(C_ACCEPT), getYNAnswers()); + String accept = question(getText(C_ACCEPT), getYNAnswers(), yes); if (!accept.equalsIgnoreCase(getText(C_YES))) { throw new InstallationCancelledException(); } } private File determineTargetDirectory() { + String no = getText(C_NO); + String yes = getText(C_YES); File targetDirectory = null; try { do { @@ -337,11 +365,13 @@ if (targetDirectory.list().length > 0) { String overwrite = question(getText(C_OVERWRITE_DIRECTORY, targetDirectory.getCanonicalPath()), - getYNAnswers()); + getYNAnswers(), + no); if (overwrite.equalsIgnoreCase(getText(C_YES))) { String clear = question(getText(C_CLEAR_DIRECTORY, targetDirectory.getCanonicalPath()), - getYNAnswers()); + getYNAnswers(), + yes); if (clear.equalsIgnoreCase(getText(C_YES))) { clearDirectory(targetDirectory); } @@ -351,7 +381,8 @@ } else { String create = question(getText(C_CREATE_DIRECTORY, targetDirectory.getCanonicalPath()), - getYNAnswers()); + getYNAnswers(), + yes); if (create.equalsIgnoreCase(getText(C_YES))) { if (!targetDirectory.mkdirs()) { throw new InstallerException(getText(C_UNABLE_CREATE_DIRECTORY, @@ -371,9 +402,9 @@ JavaHomeHandler javaHomeHandler = null; boolean javaFound = false; while (!javaFound) { - String javaHomeName = question(getText(C_ENTER_JAVA_HOME, _CURRENT), true); + String javaHomeName = question(getText(C_ENTER_JAVA_HOME), null, true, CURRENT_JRE); // only validate deviations - if (_CURRENT.equals(javaHomeName)) { + if (CURRENT_JRE.equals(javaHomeName)) { javaHomeHandler = new JavaHomeHandler(); javaFound = true; } else { @@ -419,7 +450,8 @@ } private void showReadme(final File targetDirectory) { - String read = question(getText(C_READ_README), getYNAnswers()); + String no = getText(C_NO); + String read = question(getText(C_READ_README), getYNAnswers(), no); if (read.equalsIgnoreCase(getText(C_YES))) { try { message(_jarInfo.getReadmeText()); @@ -465,7 +497,7 @@ } } String proceed = question(getText(C_CONFIRM_TARGET, targetDirectory.getCanonicalPath()), - getYNAnswers()); + getYNAnswers(), getText(C_YES)); if (!proceed.equalsIgnoreCase(getText(C_YES))) { throw new InstallationCancelledException(); } Modified: trunk/installer/src/java/org/python/util/install/TextConstants.java =================================================================== --- trunk/installer/src/java/org/python/util/install/TextConstants.java 2008-12-30 08:17:05 UTC (rev 5816) +++ trunk/installer/src/java/org/python/util/install/TextConstants.java 2008-12-30 17:17:26 UTC (rev 5817) @@ -93,7 +93,7 @@ { C_CONGRATULATIONS, "Congratulations!" }, // congratulations { C_CREATE_DIRECTORY, "Unable to find directory {0}, create it ?" }, // console { C_ENTER_TARGET_DIRECTORY, "Please enter the target directory" }, // console - { C_ENTER_JAVA_HOME, "Please enter the target java home directory ({0} for current)" }, // console + { C_ENTER_JAVA_HOME, "Please enter the java home directory (empty for using the current java runtime)" }, // console { C_ENGLISH, "English" }, // language { C_EXCLUDE, "Do you want to exclude parts from the installation ?" }, // installation type { C_GENERATING_START_SCRIPTS, "Generating start scripts ..." }, // progress @@ -111,7 +111,7 @@ { C_NON_EMPTY_TARGET_DIRECTORY, "Target directory {0} is not empty" }, // error { C_NOT_A_DIRECTORY, "{0} is not a directory. " }, // error { C_NOT_FOUND, "{0} not found. " }, // error - { C_OS_VERSION, "Your operation system version is: {0} / {1}" }, // version + { C_OS_VERSION, "Your operating system version is: {0} / {1}" }, // version { C_OVERWRITE_DIRECTORY, "Directory {0} is not empty - ok to overwrite contents ?" }, // console { C_PACKING_STANDALONE_JAR, "Packing standalone " + JarInstaller.JYTHON_JAR + " ..." }, // progress { C_PROCEED, "Please press Enter to proceed" }, // console Modified: trunk/installer/src/java/org/python/util/install/TextConstants_de.java =================================================================== --- trunk/installer/src/java/org/python/util/install/TextConstants_de.java 2008-12-30 08:17:05 UTC (rev 5816) +++ trunk/installer/src/java/org/python/util/install/TextConstants_de.java 2008-12-30 17:17:26 UTC (rev 5817) @@ -94,7 +94,7 @@ { C_CONGRATULATIONS, "Gratulation!" }, // congratulations { C_CREATE_DIRECTORY, "Das Verzeichnis {0} gibt es nicht - soll es erstellt werden ?" }, // console { C_ENTER_TARGET_DIRECTORY, "Bitte geben Sie das Zielverzeichnis ein" }, // console - { C_ENTER_JAVA_HOME, "Bitte geben Sie das gewuenschte Java Home Verzeichnis ein ({0} fuer das aktuelle)" }, // console + { C_ENTER_JAVA_HOME, "Bitte geben Sie das gewuenschte Java Home Verzeichnis ein (Enter fuer das aktuelle)" }, // console { C_ENGLISH, "Englisch" }, // language { C_EXCLUDE, "Moechten Sie Teile von der Installation ausschliessen ?" }, // installation type { C_GENERATING_START_SCRIPTS, "Start Scripts werden generiert ..." }, // progress Modified: trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java 2008-12-30 08:17:05 UTC (rev 5816) +++ trunk/installer/src/java/org/python/util/install/driver/InstallationDriver.java 2008-12-30 17:17:26 UTC (rev 5817) @@ -6,6 +6,7 @@ import java.util.Iterator; import java.util.List; +import org.python.util.install.ConsoleInstaller; import org.python.util.install.Installation; import org.python.util.install.InstallerCommandLine; import org.python.util.install.JavaHomeHandler; @@ -191,10 +192,8 @@ if (javaHomeHandler.isDeviation() && javaHomeHandler.isValidHome()) { test1.addAnswer(javaHomeHandler.getHome().getAbsolutePath()); // different jre } else { - test1.addAnswer("=="); // current jre + test1.addAnswer(ConsoleInstaller.CURRENT_JRE); } - test1.addAnswer(""); // simple enter for java version - test1.addAnswer(""); // simple enter for os version test1.addAnswer("y"); // confirm copying test1.addAnswer("n"); // no readme test1.setVerifier(new NormalVerifier()); @@ -220,10 +219,8 @@ if (javaHomeHandler.isDeviation() && javaHomeHandler.isValidHome()) { test2.addAnswer(javaHomeHandler.getHome().getAbsolutePath()); // different jre } else { - test2.addAnswer("=="); // current jre + test2.addAnswer(ConsoleInstaller.CURRENT_JRE); } - test2.addAnswer(""); // simple enter for java version - test2.addAnswer(""); // simple enter for os version test2.addAnswer("y"); // confirm copying test2.addAnswer("n"); // no readme test2.setVerifier(new NormalVerifier()); @@ -240,10 +237,8 @@ if (javaHomeHandler.isDeviation() && javaHomeHandler.isValidHome()) { test3.addAnswer(javaHomeHandler.getHome().getAbsolutePath()); // different jre } else { - test3.addAnswer("=="); // current jre + test3.addAnswer(ConsoleInstaller.CURRENT_JRE); } - test3.addAnswer(""); // simple enter for java version - test3.addAnswer(""); // simple enter for os version test3.addAnswer("y"); // confirm copying test3.addAnswer("n"); // no readme test3.setVerifier(new StandaloneVerifier()); @@ -264,10 +259,8 @@ if (javaHomeHandler.isDeviation() && javaHomeHandler.isValidHome()) { test4.addAnswer(javaHomeHandler.getHome().getAbsolutePath()); // different jre } else { - test4.addAnswer("=="); // current jre + test4.addAnswer(ConsoleInstaller.CURRENT_JRE); } - test4.addAnswer(""); // simple enter for java version - test4.addAnswer(""); // simple enter for os version test4.addAnswer("y"); // confirm copying test4.addAnswer("n"); // no readme test4.setVerifier(new NormalVerifier()); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-30 08:17:09
|
Revision: 5816 http://jython.svn.sourceforge.net/jython/?rev=5816&view=rev Author: cgroves Date: 2008-12-30 08:17:05 +0000 (Tue, 30 Dec 2008) Log Message: ----------- Break the suffix ordering and module creation parts out of zipimporter into a new class, importer, and use that as the base class of a PEP-302 hook to import py and $py.class files off the classpath, ClasspathPyImporter. Like the JavaImporter, it triggers off a special entry in sys.path -- __pyclasspath__ in this case. Anything past __pyclasspath__/ in the sys.path entry is treated as a prefix, and modules are loaded below that. Add a default __pyclasspath__/ entry to sys.path to get py files directly on the classpath. This fixes issue1181, issue1747126 and possibly issue1108. Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/Lib/site.py trunk/jython/src/org/python/core/JavaImporter.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/modules/imp.java trunk/jython/src/org/python/modules/zipimport/zipimport.java trunk/jython/src/org/python/modules/zipimport/zipimporter.java Added Paths: ----------- trunk/jython/Lib/test/classimport.jar trunk/jython/Lib/test/classimport_Lib.jar trunk/jython/Lib/test/test_classpathimporter.py trunk/jython/src/org/python/core/ClasspathPyImporter.java trunk/jython/src/org/python/core/util/importer.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/CoreExposed.includes 2008-12-30 08:17:05 UTC (rev 5816) @@ -1,4 +1,5 @@ org/python/core/AstList.class +org/python/core/ClasspathPyImporter.class org/python/core/PyArray.class org/python/core/PyBaseString.class org/python/core/PyBaseException.class Modified: trunk/jython/Lib/site.py =================================================================== --- trunk/jython/Lib/site.py 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/Lib/site.py 2008-12-30 08:17:05 UTC (rev 5816) @@ -65,7 +65,7 @@ def makepath(*paths): dir = os.path.join(*paths) - if dir == '__classpath__': + if dir == '__classpath__' or dir.startswith('__pyclasspath__'): return dir, dir dir = os.path.abspath(dir) return dir, os.path.normcase(dir) Added: trunk/jython/Lib/test/classimport.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/classimport.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/Lib/test/classimport_Lib.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/Lib/test/classimport_Lib.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/Lib/test/test_classpathimporter.py =================================================================== --- trunk/jython/Lib/test/test_classpathimporter.py (rev 0) +++ trunk/jython/Lib/test/test_classpathimporter.py 2008-12-30 08:17:05 UTC (rev 5816) @@ -0,0 +1,45 @@ +import unittest +import sys +from test import test_support +from java.io import File +from java.lang import Thread +from java.net import URLClassLoader + +class ClasspathImporterTestCase(unittest.TestCase): + def setUp(self): + self.orig_context = Thread.currentThread().contextClassLoader + self.orig_path = sys.path + + def tearDown(self): + Thread.currentThread().contextClassLoader = self.orig_context + sys.path = self.orig_path + try: + del sys.modules['flat_in_jar'] + del sys.modules['jar_pkg'] + del sys.modules['jar_pkg.prefer_compiled'] + except KeyError: + pass + + def setClassLoaderAndCheck(self, jar): + url = File(test_support.findfile(jar)).toURL() + Thread.currentThread().contextClassLoader = URLClassLoader([url]) + import flat_in_jar + self.assertEquals(flat_in_jar.value, 7) + import jar_pkg + from jar_pkg import prefer_compiled + self.assert_(prefer_compiled.compiled) + self.assertRaises(NameError, __import__, 'flat_bad') + self.assertRaises(NameError, __import__, 'jar_pkg.bad') + + def test_default_pyclasspath(self): + self.setClassLoaderAndCheck("classimport.jar") + + def test_path_in_pyclasspath(self): + sys.path = ['__pyclasspath__/Lib'] + self.setClassLoaderAndCheck("classimport_Lib.jar") + +def test_main(): + test_support.run_unittest(ClasspathImporterTestCase) + +if __name__ == '__main__': + test_main() Added: trunk/jython/src/org/python/core/ClasspathPyImporter.java =================================================================== --- trunk/jython/src/org/python/core/ClasspathPyImporter.java (rev 0) +++ trunk/jython/src/org/python/core/ClasspathPyImporter.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -0,0 +1,125 @@ +package org.python.core; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Map; + +import org.python.core.util.importer; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedType; +import org.python.util.Generic; + +@ExposedType(name="ClasspathPyImporter") +public class ClasspathPyImporter extends importer<String> { + + public static final String PYCLASSPATH_PREFIX = "__pyclasspath__/"; + public static final PyType TYPE = PyType.fromClass(ClasspathPyImporter.class); + + public ClasspathPyImporter(PyType subType) { + super(subType); + } + + public ClasspathPyImporter() { + super(); + } + + @ExposedNew + @ExposedMethod + final void ClasspathPyImporter___init__(PyObject[] args, String[] kwds) { + ArgParser ap = new ArgParser("__init__", args, kwds, new String[] {"path"}); + String path = ap.getString(0); + if (path == null || !path.startsWith(PYCLASSPATH_PREFIX)) { + throw Py.ImportError("path isn't for classpath importer"); + } + if (!path.endsWith("/")) { + path += "/"; + } + this.path = path; + } + + /** + * Find the module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @param path if not installed on the meta-path None or a module path + * @return a loader instance if this importer can load the module, None + * otherwise + */ + @ExposedMethod(defaults = "null") + final PyObject ClasspathPyImporter_find_module(String fullname, String path) { + return importer_find_module(fullname, path); + } + + /** + * Load a module for the fully qualified name. + * + * @param fullname the fully qualified name of the module + * @return a loaded PyModule + */ + @ExposedMethod + final PyObject ClasspathPyImporter_load_module(String fullname) { + return importer_load_module(fullname); + } + + @Override + protected boolean isAcceptableBytecode(String searchPath, String entry) { + return true; + } + + @Override + protected Bundle makeBundle(String fullFilename, String entry) { + InputStream is = entries.remove(entry); + return new Bundle(is) { + @Override + public void close() { + try { + inputStream.close(); + } catch (IOException e) { + throw Py.JavaError(e); + } + } + }; + } + + @Override + protected String makeEntry(String fullFilename) { + if (entries.containsKey(fullFilename)) { + return fullFilename; + } + InputStream is = null; + ClassLoader classLoader = Py.getSystemState().getClassLoader(); + if (classLoader != null) { + Py.writeDebug("import", "trying " + fullFilename + " in sys class loader"); + is = classLoader.getResourceAsStream(fullFilename); + } + if (is == null) { + Py.writeDebug("import", "trying " + fullFilename + " in context class loader"); + is = Thread.currentThread().getContextClassLoader().getResourceAsStream(fullFilename); + } + if (is != null) { + entries.put(fullFilename, is); + return fullFilename; + } + return null; + } + + @Override + protected String makeFilename(String fullname) { + return path.replace(PYCLASSPATH_PREFIX, "") + fullname.replace('.', '/'); + } + + @Override + protected String makePkgPath(String fullname) { + return path; + } + + @Override + protected String getSeparator() { + return "/"; + } + + private Map<String, InputStream> entries = Generic.map(); + + private String path; +} Modified: trunk/jython/src/org/python/core/JavaImporter.java =================================================================== --- trunk/jython/src/org/python/core/JavaImporter.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/core/JavaImporter.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -5,12 +5,10 @@ */ public class JavaImporter extends PyObject { - public JavaImporter() { - super(); - } - + public static final String JAVA_IMPORT_PATH_ENTRY = "__classpath__"; + public PyObject __call__(PyObject args[], String keywords[]) { - if(args[0].toString().endsWith("__classpath__")){ + if(args[0].toString().endsWith(JAVA_IMPORT_PATH_ENTRY)){ return this; } throw Py.ImportError("unable to handle"); @@ -18,7 +16,7 @@ /** * Find the module for the fully qualified name. - * + * * @param name the fully qualified name of the module * @return a loader instance if this importer can load the module, None * otherwise @@ -29,7 +27,7 @@ /** * Find the module for the fully qualified name. - * + * * @param name the fully qualified name of the module * @param path if installed on the meta-path None or a module path * @return a loader instance if this importer can load the module, None @@ -52,7 +50,7 @@ /** * Returns a string representation of the object. - * + * * @return a string representation of the object. */ public String toString() { Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -93,7 +93,7 @@ public static final PyString byteorder = new PyString("big"); public static final int maxint = Integer.MAX_VALUE; public static final int minint = Integer.MIN_VALUE; - + private static boolean initialized = false; /** The arguments passed to this program on the command line. */ @@ -101,7 +101,7 @@ public PyObject modules; public PyList path; - + // shadowed statics - don't use directly public static PyList warnoptions = new PyList(); public static PyObject builtins; @@ -112,7 +112,7 @@ public PyObject ps1 = new PyString(">>> "); public PyObject ps2 = new PyString("... "); - + public PyObject executable; private String currentWorkingDir; @@ -142,13 +142,15 @@ argv = (PyList)defaultArgv.repeat(1); path = (PyList)defaultPath.repeat(1); - path.append(Py.newString("__classpath__")); + path.append(Py.newString(JavaImporter.JAVA_IMPORT_PATH_ENTRY)); + path.append(Py.newString(ClasspathPyImporter.PYCLASSPATH_PREFIX)); executable = defaultExecutable; meta_path = new PyList(); path_hooks = new PyList(); path_hooks.append(new JavaImporter()); path_hooks.append(zipimporter.TYPE); + path_hooks.append(ClasspathPyImporter.TYPE); path_importer_cache = new PyDictionary(); currentWorkingDir = new File("").getAbsolutePath(); @@ -240,7 +242,7 @@ return shadowing.builtins; } } - + public synchronized void setBuiltins(PyObject value) { if (shadowing == null) { builtins = value; Added: trunk/jython/src/org/python/core/util/importer.java =================================================================== --- trunk/jython/src/org/python/core/util/importer.java (rev 0) +++ trunk/jython/src/org/python/core/util/importer.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -0,0 +1,230 @@ +package org.python.core.util; + +import java.io.InputStream; +import java.util.EnumSet; +import org.python.core.BytecodeLoader; +import org.python.core.Py; +import org.python.core.PyCode; +import org.python.core.PyList; +import org.python.core.PyModule; +import org.python.core.PyObject; +import org.python.core.PyType; +import org.python.core.imp; + +/** + * A base class for PEP-302 path hooks. Handles looking through source, compiled, package and module + * items in the right order, and creating and filling in modules. + */ +public abstract class importer<T> extends PyObject { + + static enum EntryType { + IS_SOURCE, IS_BYTECODE, IS_PACKAGE + }; + /** SearchOrder defines how we search for a module. */ + final SearchOrderEntry[] searchOrder; + + /** Module information */ + protected static enum ModuleInfo { + ERROR, NOT_FOUND, MODULE, PACKAGE + }; + + public importer(PyType subType) { + super(subType); + searchOrder = makeSearchOrder(); + } + + public importer() { + searchOrder = makeSearchOrder(); + } + + /** + * Returns the separator between directories and files used by this type of importer. + */ + protected abstract String getSeparator(); + + /** + * Returns the value to fill in __path__ on a module with the given full module name created by + * this importer. + */ + protected abstract String makePkgPath(String fullname); + + /** + * Given a full module name, return the potential file path in the archive (without extension). + */ + protected abstract String makeFilename(String fullname); + + /** + * Returns an entry for a filename from makeFilename with a potential suffix such that this + * importer can make a bundle with it, or null if fullFilename doesn't exist in this importer. + */ + protected abstract T makeEntry(String filenameAndSuffix); + + /** + * Returns a Bundle for fullFilename and entry, the result from a makeEntry call for + * fullFilename. + */ + protected abstract Bundle makeBundle(String filenameAndSuffix, T entry); + + private SearchOrderEntry[] makeSearchOrder(){ + return new SearchOrderEntry[] { + new SearchOrderEntry(getSeparator() + "__init__$py.class", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_BYTECODE)), + new SearchOrderEntry(getSeparator() + "__init__.py", + EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_SOURCE)), + new SearchOrderEntry("$py.class", EnumSet.of(EntryType.IS_BYTECODE)), + new SearchOrderEntry(".py", EnumSet.of(EntryType.IS_SOURCE)),}; + } + + protected final PyObject importer_find_module(String fullname, String path) { + ModuleInfo moduleInfo = getModuleInfo(fullname); + if (moduleInfo == ModuleInfo.ERROR || moduleInfo == ModuleInfo.NOT_FOUND) { + return Py.None; + } + return this; + } + + protected final PyObject importer_load_module(String fullname) { + ModuleCodeData moduleCodeData = getModuleCode(fullname); + if (moduleCodeData == null) { + return Py.None; + } + // the module *must* be in sys.modules before the loader executes the module code; the + // module code may (directly or indirectly) import itself + PyModule mod = imp.addModule(fullname); + mod.__dict__.__setitem__("__loader__", this); + if (moduleCodeData.ispackage) { + // add __path__ to the module *before* the code gets executed + PyList pkgpath = new PyList(); + pkgpath.add(makePkgPath(fullname)); + mod.__dict__.__setitem__("__path__", pkgpath); + } + imp.createFromCode(fullname, moduleCodeData.code, moduleCodeData.path); + Py.writeDebug("import", "import " + fullname + " # loaded from " + moduleCodeData.path); + return mod; + } + + /** + * Bundle is an InputStream, bundled together with a method that can close the input stream and + * whatever resources are associated with it when the resource is imported. + */ + protected abstract static class Bundle { + public InputStream inputStream; + + public Bundle(InputStream inputStream) { + this.inputStream = inputStream; + } + + /** + * Close the underlying resource if necessary. Raises an IOError if a problem occurs. + */ + public abstract void close(); + } + + protected abstract boolean isAcceptableBytecode(String searchPath, T entry); + + /** + * Return module information for the module with the fully qualified name. + * + * @param fullname + * the fully qualified name of the module + * @return the module's information + */ + protected final ModuleInfo getModuleInfo(String fullname) { + String path = makeFilename(fullname); + + for (SearchOrderEntry entry : searchOrder) { + T importEntry = makeEntry(path + entry.suffix); + if (importEntry == null) { + continue; + } + + if (entry.type.contains(EntryType.IS_PACKAGE)) { + return ModuleInfo.PACKAGE; + } + return ModuleInfo.MODULE; + } + return ModuleInfo.NOT_FOUND; + } + + /** + * Return the code object and its associated data for the module with the fully qualified name. + * + * @param fullname + * the fully qualified name of the module + * @return the module's ModuleCodeData object + */ + protected final ModuleCodeData getModuleCode(String fullname) { + String path = makeFilename(fullname); + String fullPath = makePkgPath(fullname); + + if (path.length() < 0) { + return null; + } + + for (SearchOrderEntry entry : searchOrder) { + String suffix = entry.suffix; + String searchPath = path + suffix; + String fullSearchPath = fullPath + suffix; + + Py.writeDebug("import", "# trying " + searchPath); + T tocEntry = makeEntry(searchPath); + if (tocEntry == null) { + continue; + } + + boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); + boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); + + if (isbytecode && !isAcceptableBytecode(searchPath, tocEntry)) { + continue; + } + + Bundle bundle = makeBundle(searchPath, tocEntry); + byte[] codeBytes; + if (isbytecode) { + codeBytes = imp.readCode(fullname, bundle.inputStream, true); + } else { + codeBytes = imp.compileSource(fullname, bundle.inputStream, fullSearchPath); + } + bundle.close(); + + if (codeBytes == null) { + // bad magic number or non-matching mtime in byte code, try next + continue; + } + + PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, fullSearchPath); + return new ModuleCodeData(code, ispackage, fullSearchPath); + } + return null; + } + + /** + * Container for PyModule code - whether or not it's a package - and its path. + */ + protected class ModuleCodeData { + public PyCode code; + public boolean ispackage; + public String path; + + public ModuleCodeData(PyCode code, boolean ispackage, String path) { + this.code = code; + this.ispackage = ispackage; + this.path = path; + } + } + + /** + * A step in the module search order: the file suffix and its entry type. + */ + protected static class SearchOrderEntry { + public String suffix; + public EnumSet<EntryType> type; + + public SearchOrderEntry(String suffix, EnumSet<EntryType> type) { + this.suffix = suffix; + this.type = type; + } + } + +} Modified: trunk/jython/src/org/python/modules/imp.java =================================================================== --- trunk/jython/src/org/python/modules/imp.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/modules/imp.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -9,8 +9,6 @@ import org.python.core.PyString; import org.python.core.PySystemState; import org.python.core.PyTuple; -import org.python.core.PyInteger; - import java.io.File; import java.io.FileInputStream; import java.io.IOException; @@ -144,8 +142,7 @@ public static PyObject load_source(String modname, String filename, PyObject file) { PyObject mod = Py.None; if (file == null) { - // XXX: This should load the accompanying byte code file - // instead, if it exists + // XXX: This should load the accompanying byte code file instead, if it exists file = new PyFile(filename, "r", 1024); } Object o = file.__tojava__(InputStream.class); @@ -202,8 +199,7 @@ String compiledName; switch (type) { case PY_SOURCE: - // XXX: This should load the accompanying byte - // code file instead, if it exists + // XXX: This should load the accompanying byte code file instead, if it exists String resolvedFilename = sys.getPath(filename.toString()); compiledName = org.python.core.imp.makeCompiledFilename(resolvedFilename); if (name.endsWith(".__init__")) { @@ -229,8 +225,7 @@ break; case PKG_DIRECTORY: PyModule m = org.python.core.imp.addModule(name); - m.__dict__.__setitem__("__path__", - new PyList(new PyObject[] { filename })); + m.__dict__.__setitem__("__path__", new PyList(new PyObject[] {filename})); m.__dict__.__setitem__("__file__", filename); ModuleInfo mi = findFromSource(name, filename.toString(), true, true); type = mi.type; Modified: trunk/jython/src/org/python/modules/zipimport/zipimport.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimport.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/modules/zipimport/zipimport.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -8,8 +8,6 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyStringMap; -import org.python.core.PyType; -import org.python.core.exceptions; /** * This module adds the ability to import Python modules (*.py, Modified: trunk/jython/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-12-30 07:11:59 UTC (rev 5815) +++ trunk/jython/src/org/python/modules/zipimport/zipimporter.java 2008-12-30 08:17:05 UTC (rev 5816) @@ -6,27 +6,22 @@ import java.io.InputStream; import java.util.Date; import java.util.Enumeration; -import java.util.EnumSet; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; import org.python.core.ArgParser; -import org.python.core.BytecodeLoader; import org.python.core.Py; -import org.python.core.PyCode; import org.python.core.PyDictionary; import org.python.core.PyInteger; -import org.python.core.PyList; import org.python.core.PyLong; -import org.python.core.PyModule; import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PySystemState; import org.python.core.PyTuple; import org.python.core.PyType; -import org.python.core.imp; import org.python.core.util.FileUtil; import org.python.core.util.StringUtil; +import org.python.core.util.importer; import org.python.expose.ExposedGet; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; @@ -37,11 +32,11 @@ * * @author Philip Jenvey */ -@ExposedType(name = "zipimport.zipimporter") -public class zipimporter extends PyObject { - +@ExposedType(name = "zipimport.zipimporter", base = PyObject.class) +public class zipimporter extends importer<PyObject> { + public static final PyType TYPE = PyType.fromClass(zipimporter.class); - + @ExposedGet public static final PyString __doc__ = new PyString( "zipimporter(archivepath) -> zipimporter object\n" + @@ -50,25 +45,6 @@ "a zipfile. ZipImportError is raised if 'archivepath' doesn't point to\n" + "a valid Zip archive."); - /** zipSearchOrder defines how we search for a module in the Zip - * archive */ - static enum EntryType { - IS_SOURCE, IS_BYTECODE, IS_PACKAGE - }; - static final SearchOrderEntry[] zipSearchOrder = new SearchOrderEntry[] { - new SearchOrderEntry(File.separator + "__init__$py.class", - EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_BYTECODE)), - new SearchOrderEntry(File.separator + "__init__.py", - EnumSet.of(EntryType.IS_PACKAGE, EntryType.IS_SOURCE)), - new SearchOrderEntry("$py.class", EnumSet.of(EntryType.IS_BYTECODE)), - new SearchOrderEntry(".py", EnumSet.of(EntryType.IS_SOURCE)), - }; - - /** Module information */ - static enum ModuleInfo { - ERROR, NOT_FOUND, MODULE, PACKAGE - }; - /** Pathname of the Zip archive */ @ExposedGet public String archive; @@ -131,15 +107,13 @@ prefix = pathFile.getName() + File.separator + prefix; pathFile = parentFile; } - if (archive != null) { files = zipimport._zip_directory_cache.__finditem__(archive); if (files == null) { files = readDirectory(archive); zipimport._zip_directory_cache.__setitem__(archive, files); } - } - else { + } else { throw zipimport.ZipImportError("not a Zip file"); } @@ -166,11 +140,7 @@ */ @ExposedMethod(defaults = "null") final PyObject zipimporter_find_module(String fullname, String path) { - ModuleInfo moduleInfo = getModuleInfo(fullname); - if (moduleInfo == ModuleInfo.ERROR || moduleInfo == ModuleInfo.NOT_FOUND) { - return Py.None; - } - return this; + return importer_find_module(fullname, path); } public PyObject load_module(String fullname) { @@ -185,30 +155,7 @@ */ @ExposedMethod final PyObject zipimporter_load_module(String fullname) { - ModuleCodeData moduleCodeData = getModuleCode(fullname); - if (moduleCodeData == null) { - return Py.None; - } - - // the module *must* be in sys.modules before the loader - // executes the module code; the module code may (directly or - // indirectly) import itself - PyModule mod = imp.addModule(fullname); - - mod.__dict__.__setitem__("__loader__", this); - if (moduleCodeData.ispackage) { - // add __path__ to the module *before* the code gets - // executed - String fullpath = archive + File.separator + prefix + getSubname(fullname); - PyList pkgpath = new PyList(); - pkgpath.add(fullpath); - mod.__dict__.__setitem__("__path__", pkgpath); - } - - imp.createFromCode(fullname, moduleCodeData.code, moduleCodeData.path); - Py.writeDebug("import", "import " + fullname + " # loaded from Zip " + - moduleCodeData.path); - return mod; + return importer_load_module(fullname); } public String get_data(String path) { @@ -234,7 +181,7 @@ throw Py.IOError(path); } - ZipBundle zipBundle = getDataStream(path); + Bundle zipBundle = makeBundle(path, tocEntry); byte[] data; try { data = FileUtil.readBytes(zipBundle.inputStream); @@ -309,7 +256,7 @@ throw zipimport.ZipImportError("can't find module '" + fullname + "'"); } - String path = makeFilename(prefix, getSubname(fullname)); + String path = makeFilename(fullname); if (moduleInfo == ModuleInfo.PACKAGE) { path += File.separator + "__init__.py"; } @@ -334,7 +281,7 @@ * @return a ZipBundle with an InputStream to the file's * uncompressed data */ - public ZipBundle getDataStream(String datapath) { + public ZipBundle makeBundle(String datapath, PyObject entry) { datapath = datapath.replace(File.separatorChar, '/'); ZipFile zipArchive; try { @@ -355,91 +302,16 @@ } /** - * Return module information for the module with the fully - * qualified name. + * Determine if the byte code at path with the specified toc entry has a modification time + * greater than its accompanying source code's. * - * @param fullname the fully qualified name of the module - * @return the module's information - */ - private ModuleInfo getModuleInfo(String fullname) { - String path = makeFilename(prefix, getSubname(fullname)); - - for (SearchOrderEntry entry : zipSearchOrder) { - PyObject tocEntry = files.__finditem__(path + entry.suffix); - if (tocEntry == null) - continue; - - if (entry.type.contains(EntryType.IS_PACKAGE)) { - return ModuleInfo.PACKAGE; - } - return ModuleInfo.MODULE; - } - return ModuleInfo.NOT_FOUND; - } - - /** - * Return the code object and its associated data for the module - * with the fully qualified name. - * - * @param fullname the fully qualified name of the module - * @return the module's ModuleCodeData object - */ - private ModuleCodeData getModuleCode(String fullname) { - String path = makeFilename(prefix, getSubname(fullname)); - - if (path.length() < 0) { - return null; - } - - for (SearchOrderEntry entry : zipSearchOrder) { - String suffix = entry.suffix; - String searchPath = path + suffix; - - Py.writeDebug("import", "# trying " + archive + File.separator + path); - PyObject tocEntry = files.__finditem__(searchPath); - if (tocEntry == null) { - continue; - } - - boolean ispackage = entry.type.contains(EntryType.IS_PACKAGE); - boolean isbytecode = entry.type.contains(EntryType.IS_BYTECODE); - - if (isbytecode && isOutdatedBytecode(searchPath, tocEntry)) { - continue; - } - - String pathToEntry = archive + File.separator + searchPath; - ZipBundle zipBundle = getDataStream(searchPath); - byte[] codeBytes; - if (isbytecode) { - codeBytes = imp.readCode(fullname, zipBundle.inputStream, true); - } - else { - codeBytes = imp.compileSource(fullname, zipBundle.inputStream, pathToEntry); - } - zipBundle.close(); - - if (codeBytes == null) { - // bad magic number or non-matching mtime in byte code, try next - continue; - } - - PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, pathToEntry); - return new ModuleCodeData(code, ispackage, pathToEntry); - } - return null; - } - - /** - * Determine if the byte code at path with the specified toc entry - * has a modification time greater than its accompanying source - * code's. - * - * @param path a String path to the byte code - * @param tocEntry the byte code's PyObject toc entry + * @param path + * a String path to the byte code + * @param tocEntry + * the byte code's PyObject toc entry * @return boolean whether or not the byte code is older */ - private boolean isOutdatedBytecode(String path, PyObject tocEntry) { + protected boolean isAcceptableBytecode(String path, PyObject tocEntry) { String sourcePath = path.substring(0, path.length() - 9) + ".py"; PyObject sourceTocEntry = files.__finditem__(sourcePath); if (sourceTocEntry == null) { @@ -528,13 +400,41 @@ return files; } + protected String getSeparator() { + return File.separator; + } + /** + * Given a full module name, return the potential file path in the archive (without extension). + * + * @param prefix + * a String value + * @param name + * a String modulename value + * @return the file path String value + */ + protected String makeFilename(String fullname) { + return prefix + getSubname(fullname).replace('.', File.separatorChar); + } + + @Override + protected String makePkgPath(String fullname) { + return archive + File.separator + prefix + getSubname(fullname); + } + + @Override + protected PyObject makeEntry(String fullFilename) { + return files.__finditem__(fullFilename); + } + + /** * Return fullname.split(".")[-1]. * - * @param fullname a String value + * @param fullname + * a String value * @return a split(".")[-1] String value */ - private String getSubname(String fullname) { + protected String getSubname(String fullname) { int i = fullname.lastIndexOf("."); if (i >= 0) { return fullname.substring(i + 1); @@ -543,18 +443,6 @@ } /** - * Given a (sub)modulename, return the potential file path in the - * archive (without extension). - * - * @param prefix a String value - * @param name a String modulename value - * @return the file path String value - */ - private String makeFilename(String prefix, String name) { - return prefix + name.replace('.', File.separatorChar); - } - - /** * Convert a time in milliseconds since epoch to DOS date format * * @param time in milliseconds, a long value @@ -613,43 +501,21 @@ } /** - * Container for PyModule code, whether or not it's a package and - * its path. - * + * ZipBundle is a ZipFile and one of its InputStreams, bundled together so the ZipFile can be + * closed when finished with its InputStream. */ - private class ModuleCodeData { - PyCode code; - boolean ispackage; - String path; - - public ModuleCodeData(PyCode code, boolean ispackage, String path) { - this.code = code; - this.ispackage = ispackage; - this.path = path; - } - } - - /** - * ZipBundle is a ZipFile and one of its InputStreams, bundled - * together so the ZipFile can be closed when finished with its - * InputStream. - * - */ - private class ZipBundle { + private class ZipBundle extends Bundle { ZipFile zipFile; - InputStream inputStream; public ZipBundle(ZipFile zipFile, InputStream inputStream) { + super(inputStream); this.zipFile = zipFile; - this.inputStream = inputStream; } /** - * Close the ZipFile; implicitly closes all of its - * InputStreams. + * Close the ZipFile; implicitly closes all of its InputStreams. * * Raises an IOError if a problem occurred. - * */ public void close() { try { @@ -660,19 +526,4 @@ } } } - - /** - * A step in the module search order: the file suffix and its file - * type. - * - */ - protected static class SearchOrderEntry { - public String suffix; - public EnumSet<EntryType> type; - - public SearchOrderEntry(String suffix, EnumSet<EntryType> type) { - this.suffix = suffix; - this.type = type; - } - } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-30 07:12:03
|
Revision: 5815 http://jython.svn.sourceforge.net/jython/?rev=5815&view=rev Author: pjenvey Date: 2008-12-30 07:11:59 +0000 (Tue, 30 Dec 2008) Log Message: ----------- o fix mishandling of tracebacks during re-raises. they're now special cased when PyException.isReRaise (analogous to CPython's why == WHY_RERAISE) is true o expose PyTraceback Modified Paths: -------------- trunk/jython/CoreExposed.includes trunk/jython/Lib/test/test_traceback_jy.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyException.java trunk/jython/src/org/python/core/PyTableCode.java trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/CoreExposed.includes =================================================================== --- trunk/jython/CoreExposed.includes 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/CoreExposed.includes 2008-12-30 07:11:59 UTC (rev 5815) @@ -34,6 +34,7 @@ org/python/core/PyStaticMethod.class org/python/core/PyString.class org/python/core/PySuper.class +org/python/core/PyTraceback.class org/python/core/PyTuple.class org/python/core/PyType.class org/python/core/PyUnicode.class Modified: trunk/jython/Lib/test/test_traceback_jy.py =================================================================== --- trunk/jython/Lib/test/test_traceback_jy.py 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/Lib/test/test_traceback_jy.py 2008-12-30 07:11:59 UTC (rev 5815) @@ -24,18 +24,15 @@ try: EventQueue.invokeAndWait(PyRunnable()) except TypeError: - # XXX: - """ self.assertEqual(tb_info(), [('test_tb_across_threads', 'EventQueue.invokeAndWait(PyRunnable())'), ('run', "raise TypeError('this is only a test')")]) - """ else: self.fail('Expected TypeError') - def _test_reraise(self): + def test_reraise(self): def raiser(): raise Exception(), None, tb try: Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/Py.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -1113,28 +1113,15 @@ /* Helpers to implement finally clauses */ public static void addTraceback(Throwable t, PyFrame frame) { - PyException e = Py.JavaError(t); - - //Add another traceback object to the exception if needed - if (e.traceback.tb_frame != frame && e.traceback.tb_frame.f_back != null) { - e.traceback = new PyTraceback(e.traceback); - } + Py.JavaError(t).tracebackHere(frame, true); } /* Helpers to implement except clauses */ public static PyException setException(Throwable t, PyFrame frame) { PyException pye = Py.JavaError(t); pye.normalize(); - - // attach catching frame - if (frame != null && pye.traceback.tb_frame != frame && pye.traceback.tb_frame.f_back != null) { - pye.traceback = new PyTraceback(pye.traceback); - } - - ThreadState ts = getThreadState(); - - ts.exception = pye; - + pye.tracebackHere(frame); + getThreadState().exception = pye; return pye; } Modified: trunk/jython/src/org/python/core/PyException.java =================================================================== --- trunk/jython/src/org/python/core/PyException.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/PyException.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -20,8 +20,15 @@ */ public PyObject value = Py.None; + /** The exception traceback object. */ public PyTraceback traceback; + /** + * Whether the exception was re-raised, such as when a traceback is specified to + * 'raise', or via a 'finally' block. + */ + private boolean isReRaise = false; + private boolean normalized = false; public PyException() { @@ -39,17 +46,9 @@ public PyException(PyObject type, PyObject value, PyTraceback traceback) { this.type = type; this.value = value; - if (traceback != null) { this.traceback = traceback; - } else { - PyFrame frame = Py.getFrame(); - if (frame != null) { - this.traceback = new PyTraceback(frame); - if (frame.tracefunc != null) { - frame.tracefunc = frame.tracefunc.traceException(frame, this); - } - } + isReRaise = true; } } @@ -133,6 +132,32 @@ } /** + * Register frame as having been visited in the traceback. + * + * @param here the current PyFrame + */ + public void tracebackHere(PyFrame here) { + tracebackHere(here, false); + } + + /** + * Register frame as having been visited in the traceback. + * + * @param here the current PyFrame + * @param isFinally whether caller is a Python finally block + */ + public void tracebackHere(PyFrame here, boolean isFinally) { + if (!isReRaise && here != null) { + // the frame is either inapplicable or already registered (from a finally) + // during a re-raise + traceback = new PyTraceback(traceback, here); + } + // finally blocks immediately tracebackHere: so they toggle isReRaise to skip the + // next tracebackHere hook + isReRaise = isFinally; + } + + /** * Logic for the raise statement * * @param type the first arg to raise, a type or an instance @@ -185,6 +210,7 @@ throw Py.TypeError("exceptions must be classes, instances, or strings (deprecated), " + "not " + type.getType().fastGetName()); } + return new PyException(type, value, (PyTraceback)traceback); } @@ -202,7 +228,7 @@ return false; } PyType type = ((PyType)obj); - if(type.isSubType((PyType)Py.BaseException)){ + if (type.isSubType(PyBaseException.TYPE)) { return true; } return type.getProxyType() != null && Throwable.class.isAssignableFrom(type.getProxyType()); Modified: trunk/jython/src/org/python/core/PyTableCode.java =================================================================== --- trunk/jython/src/org/python/core/PyTableCode.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/PyTableCode.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -198,37 +198,23 @@ try { ret = funcs.call_function(func_id, frame); } catch (Throwable t) { - //t.printStackTrace(); - //Convert exceptions that occured in Java code to PyExceptions - PyException e = Py.JavaError(t); + // Convert exceptions that occured in Java code to PyExceptions + PyException pye = Py.JavaError(t); + pye.tracebackHere(frame); - //Add another traceback object to the exception if needed - if (e.traceback.tb_frame != frame) { - PyTraceback tb; - // If f_back is null, we've jumped threads so use the current - // threadstate's frame. Bug #1533624 - if(e.traceback.tb_frame.f_back == null) { - tb = new PyTraceback(ts.frame); - } else { - tb = new PyTraceback(e.traceback.tb_frame.f_back); - } - tb.tb_next = e.traceback; - e.traceback = tb; - } - frame.f_lasti = -1; if (frame.tracefunc != null) { - frame.tracefunc.traceException(frame, e); + frame.tracefunc.traceException(frame, pye); } if (ts.profilefunc != null) { - ts.profilefunc.traceException(frame, e); + ts.profilefunc.traceException(frame, pye); } - //Rethrow the exception to the next stack frame + // Rethrow the exception to the next stack frame ts.exception = previous_exception; ts.frame = ts.frame.f_back; - throw e; + throw pye; } if (frame.tracefunc != null) { Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2008-12-30 03:53:59 UTC (rev 5814) +++ trunk/jython/src/org/python/core/PyTraceback.java 2008-12-30 07:11:59 UTC (rev 5815) @@ -2,33 +2,32 @@ package org.python.core; import org.python.core.util.RelativeFile; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedType; /** * A python traceback object. */ -// XXX: isBaseType = false -public class PyTraceback extends PyObject -{ +@ExposedType(name = "traceback", isBaseType = false) +public class PyTraceback extends PyObject { + + public static final PyType TYPE = PyType.fromClass(PyTraceback.class); + + @ExposedGet public PyObject tb_next; + + @ExposedGet public PyFrame tb_frame; + + @ExposedGet public int tb_lineno; - public PyTraceback(PyFrame frame) { + public PyTraceback(PyTraceback next, PyFrame frame) { + tb_next = next; tb_frame = frame; - if (tb_frame != null) { - tb_lineno = tb_frame.getline(); - } - tb_next = Py.None; + tb_lineno = frame.getline(); } - public PyTraceback(PyTraceback next) { - tb_next = next; - if (next != null) { - tb_frame = next.tb_frame.f_back; - tb_lineno = tb_frame.getline(); - } - } - private String tracebackInfo() { if (tb_frame == null || tb_frame.f_code == null) { return String.format(" (no code object) at line %s\n", tb_lineno); @@ -103,7 +102,7 @@ public void dumpStack(StringBuilder buf) { buf.append(tracebackInfo()); - if (tb_next != Py.None && tb_next != this) { + if (tb_next != null && tb_next != this) { ((PyTraceback)tb_next).dumpStack(buf); } else if (tb_next == this) { buf.append("circularity detected!"+this+tb_next); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-30 03:54:09
|
Revision: 5814 http://jython.svn.sourceforge.net/jython/?rev=5814&view=rev Author: zyasoft Date: 2008-12-30 03:53:59 +0000 (Tue, 30 Dec 2008) Log Message: ----------- Added a shim for xml.etree.cElementTree such that it just pulls in the entire namespace of ElementTree. This is for code that expects cElementTree is available if ET is part of a Python's stdlib. This enables soaplib's unit tests to all pass (assuming a patch for #1191). Added Paths: ----------- trunk/jython/Lib/xml/etree/ trunk/jython/Lib/xml/etree/cElementTree.py Added: trunk/jython/Lib/xml/etree/cElementTree.py =================================================================== --- trunk/jython/Lib/xml/etree/cElementTree.py (rev 0) +++ trunk/jython/Lib/xml/etree/cElementTree.py 2008-12-30 03:53:59 UTC (rev 5814) @@ -0,0 +1,10 @@ +# make an exact copy of ElementTree's namespace here to support even +# private API usage +from xml.etree.ElementTree import ( + Comment, Element, ElementPath, ElementTree, PI, ProcessingInstruction, + QName, SubElement, TreeBuilder, VERSION, XML, XMLID, XMLParser, + XMLTreeBuilder, _Element, _ElementInterface, _SimpleElementPath, + __all__, __doc__, __file__, __name__, _encode, _encode_entity, + _escape, _escape_attrib, _escape_cdata, _escape_map, _namespace_map, + _raise_serialization_error, dump, fixtag, fromstring, iselement, + iterparse, parse, re, string, sys, tostring) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-30 00:19:23
|
Revision: 5813 http://jython.svn.sourceforge.net/jython/?rev=5813&view=rev Author: cgroves Date: 2008-12-30 00:19:19 +0000 (Tue, 30 Dec 2008) Log Message: ----------- Vestigial Modified Paths: -------------- trunk/jython/src/org/python/compiler/ProxyMaker.java Modified: trunk/jython/src/org/python/compiler/ProxyMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-29 23:59:02 UTC (rev 5812) +++ trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-30 00:19:19 UTC (rev 5813) @@ -670,8 +670,6 @@ } public void addClassDictInit() throws Exception { - supernames.size(); - // classDictInit method classfile.addInterface(mapClass(org.python.core.ClassDictInit.class)); Code code = classfile.addMethod("classDictInit", This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-29 23:59:05
|
Revision: 5812 http://jython.svn.sourceforge.net/jython/?rev=5812&view=rev Author: cgroves Date: 2008-12-29 23:59:02 +0000 (Mon, 29 Dec 2008) Log Message: ----------- Try the current thread's context class loader instead of using Class.forName. Fixes issue1216. The implementation differs from the patch in that it tries SyspathJavaLoader before going to the context class loader so java classes can still be found on sys.path. Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/src/org/python/compiler/ProxyMaker.java trunk/jython/src/org/python/compiler/ScopeInfo.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/SyspathJavaLoader.java Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-29 23:59:02 UTC (rev 5812) @@ -8,8 +8,8 @@ from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import (Boolean, ExceptionInInitializerError, Integer, Object, String, Runnable, - Thread, ThreadGroup, System, Runtime, Math, Byte) +from java.lang import (Boolean, ClassLoader, ExceptionInInitializerError, Integer, Object, String, + Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath from java.math import BigDecimal @@ -55,6 +55,49 @@ pass A() +""" +public abstract class ContextAbstract { + public ContextAbstract() { + method(); + } + + public abstract void method(); +} +""" +# The following is the correspoding bytecode for ContextAbstract compiled with javac 1.5 +# Needs to be named differently than Abstract above so the class loader won't just use it +CONTEXT_ABSTRACT = '''\ +eJxdjr1uwjAUhc8lbgIh/AVegA0YQJ1BlRBSp6gdWrE7wQKjEEvBVH0tFip14AF4KMQ17YSHc3yu +vuPry/X3DOAZ3RACrRAe2gE6AWKCP9OFti8EbzBcEsTCrBShlehCvR12qSo/ZZrzJE5MJvOlLLXL +/0NhN3pP6CQLU1j1befp3pYys1N+d6fsxqwI4Yc5lJl61a7QewDHW/klIzzBjxDB58UPAKHtkEku +i/XkPd2qzIo+/1/AnQrIdVkDTlN2Yq+NfkCjEyrHO1JlbXLF3QV7lbXGKfqDEaIOCHL7ORMad7J5 +A7yvPDQ= +'''.decode('base64').decode('zlib') +class ContextClassloaderTest(unittest.TestCase): + '''Classes on the context classloader should be importable and subclassable. + + http://bugs.jython.org/issue1216''' + def setUp(self): + self.orig_context = Thread.currentThread().contextClassLoader + class AbstractLoader(ClassLoader): + def __init__(self): + ClassLoader.__init__(self) + c = self.super__defineClass("ContextAbstract", CONTEXT_ABSTRACT, 0, + len(CONTEXT_ABSTRACT), ClassLoader.protectionDomain) + self.super__resolveClass(c) + Thread.currentThread().contextClassLoader = AbstractLoader() + + def tearDown(self): + Thread.currentThread().contextClassLoader = self.orig_context + + def test_can_subclass_abstract(self): + import ContextAbstract + + class A(ContextAbstract): + def method(self): + pass + A() + class InstantiationTest(unittest.TestCase): def test_can_subclass_abstract(self): class A(Component): @@ -470,6 +513,7 @@ def test_main(): test_support.run_unittest(AbstractOnSyspathTest, + ContextClassloaderTest, InstantiationTest, BeanTest, ExtendJavaTest, Modified: trunk/jython/src/org/python/compiler/ProxyMaker.java =================================================================== --- trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/compiler/ProxyMaker.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -670,7 +670,7 @@ } public void addClassDictInit() throws Exception { - int n = supernames.size(); + supernames.size(); // classDictInit method classfile.addInterface(mapClass(org.python.core.ClassDictInit.class)); Modified: trunk/jython/src/org/python/compiler/ScopeInfo.java =================================================================== --- trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/compiler/ScopeInfo.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -125,7 +125,7 @@ public int jy_npurecell; public int cell, distance; - + public ScopeInfo up; //Resolve the names used in the given scope, and mark any freevars used in the up scope @@ -188,7 +188,7 @@ names.addElement(purecells.elementAt(i)); } } - + if (some_free && nested) { up.contains_ns_free_vars = true; } @@ -202,23 +202,25 @@ } - private void dynastuff_trouble(boolean inner_free, - CompilationContext ctxt) throws Exception { - String illegal; - if (unqual_exec && from_import_star) - illegal = "function '"+scope_name+ - "' uses import * and bare exec, which are illegal"; - else if (unqual_exec) - illegal = "unqualified exec is not allowed in function '"+ - scope_name+"'"; - else - illegal = "import * is not allowed in function '"+scope_name+"'"; - String why; - if (inner_free) - why = " because it contains a function with free variables"; - else - why = " because it contains free variables"; - ctxt.error(illegal + why, true, scope_node); + private void dynastuff_trouble(boolean inner_free, CompilationContext ctxt) throws Exception { + StringBuilder illegal = new StringBuilder(); + if (unqual_exec && from_import_star) { + illegal.append("function '") + .append(scope_name) + .append("' uses import * and bare exec, which are illegal"); + } else if (unqual_exec) { + illegal.append("unqualified exec is not allowed in function '") + .append(scope_name) + .append("'"); + } else { + illegal.append("import * is not allowed in function '").append(scope_name).append("'"); + } + if (inner_free) { + illegal.append(" because it contains a function with free variables"); + } else { + illegal.append(" because it contains free variables"); + } + ctxt.error(illegal.toString(), true, scope_node); } public Vector freevars = new Vector(); @@ -230,7 +232,7 @@ public void setup_closure() { setup_closure(up); } - + /** * setup the closure on this scope using the passed in scope. This is used * by jythonc to setup its closures. Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/core/Py.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -761,11 +761,15 @@ secEnv = true; } if (classLoader != null) { - return classLoader.loadClass(name); + try { + return classLoader.loadClass(name); + } catch (ClassNotFoundException cnfe) { + // let the context classloader try + } } } - return Class.forName(name); + return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (ClassNotFoundException e) { // e.printStackTrace(); @@ -797,13 +801,17 @@ if (classLoader != null) { writeDebug("import", "trying " + name + " as " + reason + " in syspath loader"); - return classLoader.loadClass(name); + try { + return classLoader.loadClass(name); + } catch (ClassNotFoundException cnfe) { + // let the context classloader try + } } } writeDebug("import", "trying " + name + " as " + reason + " in Class.forName"); - return Class.forName(name); + return Thread.currentThread().getContextClassLoader().loadClass(name); } catch (ClassNotFoundException e) { return null; } catch (IllegalArgumentException e) { Modified: trunk/jython/src/org/python/core/SyspathJavaLoader.java =================================================================== --- trunk/jython/src/org/python/core/SyspathJavaLoader.java 2008-12-29 23:56:48 UTC (rev 5811) +++ trunk/jython/src/org/python/core/SyspathJavaLoader.java 2008-12-29 23:59:02 UTC (rev 5812) @@ -17,7 +17,7 @@ public class SyspathJavaLoader extends ClassLoader { private static final char SLASH_CHAR = '/'; - + public InputStream getResourceAsStream(String res) { Py.writeDebug("resource", "trying resource: " + res); PySystemState sys = Py.getSystemState(); @@ -26,7 +26,7 @@ return classLoader.getResourceAsStream(res); } - classLoader = this.getClass().getClassLoader(); + classLoader = Thread.currentThread().getContextClassLoader(); InputStream ret; @@ -47,7 +47,7 @@ res = res.replace(SLASH_CHAR, File.separatorChar); entryRes = entryRes.replace(File.separatorChar, SLASH_CHAR); } - + PyList path = sys.path; for (int i = 0; i < path.__len__(); i++) { PyObject entry = path.__getitem__(i); @@ -85,23 +85,23 @@ if (classLoader != null) { return classLoader.loadClass(name); } - + // Search the sys.path for a .class file matching the named class. try { return Class.forName(name); } catch(ClassNotFoundException e) {} - + // The current class loader may be null (e.g., when Jython is loaded // from the boot classpath); try the system class loader. try { return Class.forName(name, true, ClassLoader.getSystemClassLoader()); } catch(ClassNotFoundException e) {} - + Class c = findLoadedClass(name); if(c != null) { return c; } - + PyList path = sys.path; for(int i = 0; i < path.__len__(); i++) { InputStream fis = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-29 23:56:50
|
Revision: 5811 http://jython.svn.sourceforge.net/jython/?rev=5811&view=rev Author: cgroves Date: 2008-12-29 23:56:48 +0000 (Mon, 29 Dec 2008) Log Message: ----------- Switch to the proxy constructor before checking if there are no visible constructors as the proxy class may be subclassing a class with only protected constructors. Modified Paths: -------------- trunk/jython/src/org/python/core/PyReflectedConstructor.java Modified: trunk/jython/src/org/python/core/PyReflectedConstructor.java =================================================================== --- trunk/jython/src/org/python/core/PyReflectedConstructor.java 2008-12-29 22:38:59 UTC (rev 5810) +++ trunk/jython/src/org/python/core/PyReflectedConstructor.java 2008-12-29 23:56:48 UTC (rev 5811) @@ -82,19 +82,19 @@ throw Py.TypeError("invalid self argument to constructor"); } Class<?> javaClass = self.getType().getProxyType(); + Class<?> declaringClass = argslist[0] == null ? null : argslist[0].declaringClass; + // If the declaring class is a pure Java type but we're instantiating a Python proxy, + // grab the proxy version of the constructor to instantiate the proper type + if ((declaringClass == null || !PyProxy.class.isAssignableFrom(declaringClass)) + && !(self.getType() instanceof PyJavaType)) { + return PyType.fromClass(javaClass).lookup("__init__").__call__(self, args, keywords); + } if (nargs == 0) { throw Py.TypeError("No visible constructors for class (" + javaClass.getName() + ")"); } - Class<?> declaringClass = argslist[0].declaringClass; if (!declaringClass.isAssignableFrom(javaClass)) { throw Py.TypeError("self invalid - must implement: " + declaringClass.getName()); } - // If the declaring class is a pure Java type but we're instantiating a Python proxy, - // grab the proxy version of the constructor to instantiate the proper type - if (!PyProxy.class.isAssignableFrom(declaringClass) - && !(self.getType() instanceof PyJavaType)) { - return PyType.fromClass(javaClass).lookup("__init__").__call__(self, args, keywords); - } int mods = declaringClass.getModifiers(); if (Modifier.isInterface(mods)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-29 22:39:05
|
Revision: 5810 http://jython.svn.sourceforge.net/jython/?rev=5810&view=rev Author: pjenvey Date: 2008-12-29 22:38:59 +0000 (Mon, 29 Dec 2008) Log Message: ----------- move test389 to test_traceback_jy, add a new currently failing traceback test Added Paths: ----------- trunk/jython/Lib/test/test_traceback_jy.py Removed Paths: ------------- trunk/jython/bugtests/test389.py Added: trunk/jython/Lib/test/test_traceback_jy.py =================================================================== --- trunk/jython/Lib/test/test_traceback_jy.py (rev 0) +++ trunk/jython/Lib/test/test_traceback_jy.py 2008-12-29 22:38:59 UTC (rev 5810) @@ -0,0 +1,69 @@ +"""Misc traceback tests + +Made for Jython. +""" +import sys +import traceback +import unittest +from test import test_support + +if test_support.is_jython: + from java.awt import EventQueue + from java.lang import Runnable + +class TracebackTestCase(unittest.TestCase): + + def test_tb_across_threads(self): + if not test_support.is_jython: + return + + # http://bugs.jython.org/issue1533624 + class PyRunnable(Runnable): + def run(self): + raise TypeError('this is only a test') + try: + EventQueue.invokeAndWait(PyRunnable()) + except TypeError: + # XXX: + """ + self.assertEqual(tb_info(), + [('test_tb_across_threads', + 'EventQueue.invokeAndWait(PyRunnable())'), + ('run', + "raise TypeError('this is only a test')")]) + """ + else: + self.fail('Expected TypeError') + + def _test_reraise(self): + def raiser(): + raise Exception(), None, tb + try: + # Jython previously added raiser's frame to the traceback + raiser() + except Exception: + self.assertEqual(tb_info(), + [('test_reraise', 'raiser()'), + ('<module>', "raise Exception('foo')")]) + + else: + self.fail('Expected Exception') + + +try: + raise Exception('foo') +except Exception: + tb = sys.exc_info()[2] + + +def tb_info(): + # [2:] ignores filename/lineno + return [info[2:] for info in traceback.extract_tb(sys.exc_info()[2])] + + +def test_main(): + test_support.run_unittest(TracebackTestCase) + + +if __name__ == '__main__': + test_main() Deleted: trunk/jython/bugtests/test389.py =================================================================== --- trunk/jython/bugtests/test389.py 2008-12-29 17:26:45 UTC (rev 5809) +++ trunk/jython/bugtests/test389.py 2008-12-29 22:38:59 UTC (rev 5810) @@ -1,20 +0,0 @@ -''' -Test for Bug #1533624. A call that crosses threads causes a null pointer -exception when building a traceback. If it reappears instead of the -TypeError showing up a null pointer exception will be thrown. -''' - -from java.awt import EventQueue -from java.lang import Runnable - -class PyRunnable(Runnable): - def run(self): - raise TypeError, 'this is only a test' - -def g(): - EventQueue.invokeAndWait(PyRunnable()) - -try: - g() -except TypeError: - pass This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-29 17:26:50
|
Revision: 5809 http://jython.svn.sourceforge.net/jython/?rev=5809&view=rev Author: fwierzbicki Date: 2008-12-29 17:26:45 +0000 (Mon, 29 Dec 2008) Log Message: ----------- rename test to fit convention of _jy at the end and to match the CPython Lib test on which it is based. Added Paths: ----------- trunk/jython/Lib/test/test_codeop_jy.py Removed Paths: ------------- trunk/jython/Lib/test/test_jy_compile.py Copied: trunk/jython/Lib/test/test_codeop_jy.py (from rev 5808, trunk/jython/Lib/test/test_jy_compile.py) =================================================================== --- trunk/jython/Lib/test/test_codeop_jy.py (rev 0) +++ trunk/jython/Lib/test/test_codeop_jy.py 2008-12-29 17:26:45 UTC (rev 5809) @@ -0,0 +1,176 @@ +""" + test compile. derived from test_codeop +""" +import unittest +from test import test_support +from test.test_support import run_unittest + + +def compile_(source,name="<input>",symbol="single"): + return compile(source,name,symbol) + +class CompileTests(unittest.TestCase): + + def assertValid(self, str, symbol='single',values=None,value=None): + '''succeed iff str is a valid piece of code''' + code = compile_(str, "<input>", symbol) + if values: + d = {} + exec code in d + self.assertEquals(d,values) + elif value is not None: + self.assertEquals(eval(code,self.eval_d),value) + else: + self.assert_(code) + + + def assertInvalid(self, str, symbol='single', is_syntax=1): + '''succeed iff str is the start of an invalid piece of code''' + try: + compile_(str,symbol=symbol) + self.fail("No exception thrown for invalid code") + except SyntaxError: + self.assert_(is_syntax) + except OverflowError: + self.assert_(not is_syntax) + + assertIncomplete = assertInvalid + + def test_valid(self): + av = self.assertValid + + av("") + av("\n") + av("\n\n") + av("# a\n") + + av("a = 1") + av("\na = 1") + av("a = 1\n") + av("a = 1\n\n") + av("\n\na = 1\n\n",values={'a':1}) + + av("def x():\n pass\n") + av("if 1:\n pass\n") + + av("\n\nif 1: pass\n") + av("\n\nif 1: a=1\n\n",values={'a':1}) + + av("def x():\n pass") + av("def x():\n pass\n ") + av("def x():\n pass\n ") + av("\n\ndef x():\n pass") + + av("def x():\n\n pass\n") # failed under 2.1 + av("def x():\n pass\n \n") + av("def x():\n pass\n \n") + + av("pass\n") + av("3**3\n") + + av("if 9==3:\n pass\nelse:\n pass") + av("if 9==3:\n pass\nelse:\n pass\n") + av("if 1:\n pass\n if 1:\n pass\n else:\n pass") + av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") + + av("#a\n#b\na = 3\n") + av("#a\n\n \na=3\n",values={'a':3}) + av("a=3\n\n") + av("a = 9+ \\\n3") + + av("3**3","eval") + av("(lambda z: \n z**3)","eval") + + av("9+ \\\n3","eval") + av("9+ \\\n3\n","eval") + + # these failed under 2.1 + self.eval_d = {'a': 2} + av("\n\na**3","eval",value=8) + av("\n \na**3","eval",value=8) + av("#a\n#b\na**3","eval",value=8) + + # this failed under 2.2.1 + av("def f():\n try: pass\n finally: [x for x in (1,2)]") + + # Failed for Jython 2.5a2. See http://bugs.jython.org/issue1116. + av("@a.b.c\ndef f():\n pass") + + def test_incomplete(self): + ai = self.assertIncomplete + + ai("(a **") + ai("(a,b,") + ai("(a,b,(") + ai("(a,b,(") + ai("a = (") + ai("a = {") + ai("b + {") + + ai("if 9==3:\n pass\nelse:") + ai("if 9==3:\n pass\nelse:\n") + + ai("if 1:") + ai("if 1:\n") + ai("if 1:\n pass\n if 1:\n pass\n else:") + ai("if 1:\n pass\n if 1:\n pass\n else:\n") + + ai("def x():") + ai("def x():\n") + ai("def x():\n\n") + + ai("a = 9+ \\") + ai("a = 'a\\") + ai("a = '''xy") + + ai("","eval") + ai("\n","eval") + ai("(","eval") + ai("(\n\n\n","eval") + ai("(9+","eval") + ai("9+ \\","eval") + ai("lambda z: \\","eval") + + def test_invalid(self): + ai = self.assertInvalid + + ai("a b") + + ai("a @") + ai("a b @") + ai("a ** @") + + ai("a = ") + ai("a = 9 +") + + ai("def x():\n\npass\n") + + ai("\n\n if 1: pass\n\npass") # valid for 2.1 ?! + + ai("a = 9+ \\\n") + ai("a = 'a\\ ") + ai("a = 'a\\\n") + + ai("a = 1","eval") + ai("a = (","eval") + ai("]","eval") + ai("())","eval") + ai("[}","eval") + ai("9+","eval") + ai("lambda z:","eval") + ai("a b","eval") + ai("return 2.3") + + def test_filename(self): + self.assertEquals(compile_("a = 1\n", "abc").co_filename, + compile("a = 1\n", "abc", 'single').co_filename) + self.assertNotEquals(compile_("a = 1\n", "abc").co_filename, + compile("a = 1\n", "def", 'single').co_filename) + + +def test_main(): + run_unittest(CompileTests) + + +if __name__ == "__main__": + test_main() Deleted: trunk/jython/Lib/test/test_jy_compile.py =================================================================== --- trunk/jython/Lib/test/test_jy_compile.py 2008-12-29 09:00:09 UTC (rev 5808) +++ trunk/jython/Lib/test/test_jy_compile.py 2008-12-29 17:26:45 UTC (rev 5809) @@ -1,176 +0,0 @@ -""" - test compile. derived from test_codeop -""" -import unittest -from test import test_support -from test.test_support import run_unittest - - -def compile_(source,name="<input>",symbol="single"): - return compile(source,name,symbol) - -class CompileTests(unittest.TestCase): - - def assertValid(self, str, symbol='single',values=None,value=None): - '''succeed iff str is a valid piece of code''' - code = compile_(str, "<input>", symbol) - if values: - d = {} - exec code in d - self.assertEquals(d,values) - elif value is not None: - self.assertEquals(eval(code,self.eval_d),value) - else: - self.assert_(code) - - - def assertInvalid(self, str, symbol='single', is_syntax=1): - '''succeed iff str is the start of an invalid piece of code''' - try: - compile_(str,symbol=symbol) - self.fail("No exception thrown for invalid code") - except SyntaxError: - self.assert_(is_syntax) - except OverflowError: - self.assert_(not is_syntax) - - assertIncomplete = assertInvalid - - def test_valid(self): - av = self.assertValid - - av("") - av("\n") - av("\n\n") - av("# a\n") - - av("a = 1") - av("\na = 1") - av("a = 1\n") - av("a = 1\n\n") - av("\n\na = 1\n\n",values={'a':1}) - - av("def x():\n pass\n") - av("if 1:\n pass\n") - - av("\n\nif 1: pass\n") - av("\n\nif 1: a=1\n\n",values={'a':1}) - - av("def x():\n pass") - av("def x():\n pass\n ") - av("def x():\n pass\n ") - av("\n\ndef x():\n pass") - - av("def x():\n\n pass\n") # failed under 2.1 - av("def x():\n pass\n \n") - av("def x():\n pass\n \n") - - av("pass\n") - av("3**3\n") - - av("if 9==3:\n pass\nelse:\n pass") - av("if 9==3:\n pass\nelse:\n pass\n") - av("if 1:\n pass\n if 1:\n pass\n else:\n pass") - av("if 1:\n pass\n if 1:\n pass\n else:\n pass\n") - - av("#a\n#b\na = 3\n") - av("#a\n\n \na=3\n",values={'a':3}) - av("a=3\n\n") - av("a = 9+ \\\n3") - - av("3**3","eval") - av("(lambda z: \n z**3)","eval") - - av("9+ \\\n3","eval") - av("9+ \\\n3\n","eval") - - # these failed under 2.1 - self.eval_d = {'a': 2} - av("\n\na**3","eval",value=8) - av("\n \na**3","eval",value=8) - av("#a\n#b\na**3","eval",value=8) - - # this failed under 2.2.1 - av("def f():\n try: pass\n finally: [x for x in (1,2)]") - - # Failed for Jython 2.5a2. See http://bugs.jython.org/issue1116. - av("@a.b.c\ndef f():\n pass") - - def test_incomplete(self): - ai = self.assertIncomplete - - ai("(a **") - ai("(a,b,") - ai("(a,b,(") - ai("(a,b,(") - ai("a = (") - ai("a = {") - ai("b + {") - - ai("if 9==3:\n pass\nelse:") - ai("if 9==3:\n pass\nelse:\n") - - ai("if 1:") - ai("if 1:\n") - ai("if 1:\n pass\n if 1:\n pass\n else:") - ai("if 1:\n pass\n if 1:\n pass\n else:\n") - - ai("def x():") - ai("def x():\n") - ai("def x():\n\n") - - ai("a = 9+ \\") - ai("a = 'a\\") - ai("a = '''xy") - - ai("","eval") - ai("\n","eval") - ai("(","eval") - ai("(\n\n\n","eval") - ai("(9+","eval") - ai("9+ \\","eval") - ai("lambda z: \\","eval") - - def test_invalid(self): - ai = self.assertInvalid - - ai("a b") - - ai("a @") - ai("a b @") - ai("a ** @") - - ai("a = ") - ai("a = 9 +") - - ai("def x():\n\npass\n") - - ai("\n\n if 1: pass\n\npass") # valid for 2.1 ?! - - ai("a = 9+ \\\n") - ai("a = 'a\\ ") - ai("a = 'a\\\n") - - ai("a = 1","eval") - ai("a = (","eval") - ai("]","eval") - ai("())","eval") - ai("[}","eval") - ai("9+","eval") - ai("lambda z:","eval") - ai("a b","eval") - ai("return 2.3") - - def test_filename(self): - self.assertEquals(compile_("a = 1\n", "abc").co_filename, - compile("a = 1\n", "abc", 'single').co_filename) - self.assertNotEquals(compile_("a = 1\n", "abc").co_filename, - compile("a = 1\n", "def", 'single').co_filename) - - -def test_main(): - run_unittest(CompileTests) - - -if __name__ == "__main__": - test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-29 09:00:11
|
Revision: 5808 http://jython.svn.sourceforge.net/jython/?rev=5808&view=rev Author: zyasoft Date: 2008-12-29 09:00:09 +0000 (Mon, 29 Dec 2008) Log Message: ----------- Used Oti Humbel's golden rule of explicit imports to ensure compatibility of signal.py with Jython's standalone mode. Modified Paths: -------------- trunk/jython/Lib/signal.py Modified: trunk/jython/Lib/signal.py =================================================================== --- trunk/jython/Lib/signal.py 2008-12-29 08:42:35 UTC (rev 5807) +++ trunk/jython/Lib/signal.py 2008-12-29 09:00:09 UTC (rev 5808) @@ -35,13 +35,13 @@ except ImportError: raise ImportError("signal module requires sun.misc.Signal, which is not available on this platform") -import java.util.concurrent import os import sun.misc.SignalHandler import sys import threading import time from java.lang import IllegalArgumentException +from java.util.concurrent.atomic import AtomicReference debug = 0 @@ -182,7 +182,7 @@ def pause(): raise NotImplementedError -_alarm_timer_holder = java.util.concurrent.atomic.AtomicReference() +_alarm_timer_holder = AtomicReference() def _alarm_handler(sig, frame): print "Alarm clock" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-29 08:42:38
|
Revision: 5807 http://jython.svn.sourceforge.net/jython/?rev=5807&view=rev Author: zyasoft Date: 2008-12-29 08:42:35 +0000 (Mon, 29 Dec 2008) Log Message: ----------- test_signal formerly used output comparison testing. There's no good way of excluding this file from the distribution, so instead we include a null one (just 'test_signal') Added Paths: ----------- trunk/jython/Lib/test/output/test_signal Added: trunk/jython/Lib/test/output/test_signal =================================================================== --- trunk/jython/Lib/test/output/test_signal (rev 0) +++ trunk/jython/Lib/test/output/test_signal 2008-12-29 08:42:35 UTC (rev 5807) @@ -0,0 +1 @@ +test_signal This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-29 08:33:26
|
Revision: 5806 http://jython.svn.sourceforge.net/jython/?rev=5806&view=rev Author: zyasoft Date: 2008-12-29 08:33:23 +0000 (Mon, 29 Dec 2008) Log Message: ----------- PySystemState (aka 'sys') now supports shadowing on builtins and warnoptions. Other non-final statics are now immutable from Jython (but shadowing could be readily extended to them). PyFile also supports an encoding, a 2.5 feature, that is used by ipython. Modified Paths: -------------- trunk/jython/Lib/test/test_sys_jy.py trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyFile.java trunk/jython/src/org/python/core/PySystemState.java trunk/jython/src/org/python/core/exceptions.java trunk/jython/src/org/python/util/InteractiveConsole.java trunk/jython/src/org/python/util/jython.java Added Paths: ----------- trunk/jython/Lib/test/sys_jy_test_module.py Added: trunk/jython/Lib/test/sys_jy_test_module.py =================================================================== --- trunk/jython/Lib/test/sys_jy_test_module.py (rev 0) +++ trunk/jython/Lib/test/sys_jy_test_module.py 2008-12-29 08:33:23 UTC (rev 5806) @@ -0,0 +1,2 @@ +class Foobar(object): + pass Modified: trunk/jython/Lib/test/test_sys_jy.py =================================================================== --- trunk/jython/Lib/test/test_sys_jy.py 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/Lib/test/test_sys_jy.py 2008-12-29 08:33:23 UTC (rev 5806) @@ -62,8 +62,75 @@ reload(sys) self.assert_(type(sys.getdefaultencoding) == type(gde)) + +def exec_code_separately(function, sharing=False): + """Runs code in a separate context: (thread, PySystemState, PythonInterpreter) + + A PySystemState is used in conjunction with its thread + context. This is not so desirable - at the very least it means + that a thread pool cannot be shared. But this is not the place to + revisit ancient design decisions.""" + + def function_context(): + from org.python.core import Py + from org.python.util import PythonInterpreter + from org.python.core import PySystemState + + ps = PySystemState() + pi = PythonInterpreter({}, ps) + if not sharing: + ps.shadow() + ps.builtins = ps.builtins.copy() + pi.exec(function.func_code) + + import threading + context = threading.Thread(target=function_context) + context.start() + context.join() + + +def set_globally(): + import sys + import test.sys_jy_test_module # used as a probe + + # can't use 'foo', test_with wants to have that undefined + sys.builtins['test_sys_jy_foo'] = 42 + + +def set_shadow(): + import sys + sys.builtins['fum'] = 24 + +class ShadowingTest(unittest.TestCase): + + def setUp(self): + exec_code_separately(set_globally, sharing=True) + exec_code_separately(set_shadow) + + def test_super_globals(self): + import sys, __builtin__ + + def get_sym(sym): + return sys.builtins.get(sym) + def get_sym_attr(sym): + return hasattr(__builtin__, sym) + + self.assertEqual(test_sys_jy_foo, 42, "should be able to install a new builtin ('super global')") + self.assertEqual(get_sym('test_sys_jy_foo'), 42) + self.assertTrue(get_sym_attr('test_sys_jy_foo')) + + def is_fum_there(): fum + self.assertRaises(NameError, is_fum_there) # shadowed global ('fum') should not be visible + self.assertEqual(get_sym('fum'), None) + self.assertTrue(not(get_sym_attr('fum'))) + + def test_sys_modules_per_instance(self): + import sys + self.assertTrue('sys_jy_test_module' not in sys.modules, "sys.modules should be per PySystemState instance") + + def test_main(): - test.test_support.run_unittest(SysTest) + test.test_support.run_unittest(SysTest, ShadowingTest) if __name__ == "__main__": test_main() Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/Py.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -1207,7 +1207,7 @@ } f = new PyFrame(tc, locals, globals, - PySystemState.builtins); + Py.getSystemState().getBuiltins()); return code.call(f); } Modified: trunk/jython/src/org/python/core/PyFile.java =================================================================== --- trunk/jython/src/org/python/core/PyFile.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/PyFile.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -42,6 +42,9 @@ @ExposedGet public String mode; + @ExposedGet + public String encoding; + /** Indicator dictating whether a space should be written to this * file on the next print statement (not currently implemented in * print ) */ Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -25,7 +25,8 @@ /** * The "sys" module. */ -// xxx this should really be a module! +// xxx Many have lamented, this should really be a module! +// but it will require some refactoring to see this wish come true. public class PySystemState extends PyObject { public static final String PYTHON_CACHEDIR = "python.cachedir"; @@ -38,8 +39,8 @@ private static final String JAR_URL_PREFIX = "jar:file:"; private static final String JAR_SEPARATOR = "!"; - public static PyString version = new PyString(Version.getVersion()); - public static int hexversion = ((Version.PY_MAJOR_VERSION << 24) | + public static final PyString version = new PyString(Version.getVersion()); + public static final int hexversion = ((Version.PY_MAJOR_VERSION << 24) | (Version.PY_MINOR_VERSION << 16) | (Version.PY_MICRO_VERSION << 8) | (Version.PY_RELEASE_LEVEL << 4) | @@ -52,8 +53,8 @@ /** * The copyright notice for this release. */ - // TBD: should we use \u00a9 Unicode c-inside-circle? - public static PyObject copyright = Py.newString( + + public static final PyObject copyright = Py.newString( "Copyright (c) 2000-2008, Jython Developers\n" + "All rights reserved.\n\n" + @@ -75,16 +76,24 @@ public static PyTuple builtin_module_names = null; public static PackageManager packageManager; - public static File cachedir; + private static File cachedir; private static PyList defaultPath; private static PyList defaultArgv; private static PyObject defaultExecutable; + // XXX - from Jython code, these statics are immutable; we may wish to consider + // using the shadowing mechanism for them as well if in practice it makes + // sense for them to be changed public static Properties registry; // = init_registry(); public static PyObject prefix; public static PyObject exec_prefix = Py.EmptyString; + public static PyString platform = new PyString("java"); + public static final PyString byteorder = new PyString("big"); + public static final int maxint = Integer.MAX_VALUE; + public static final int minint = Integer.MIN_VALUE; + private static boolean initialized = false; /** The arguments passed to this program on the command line. */ @@ -92,25 +101,20 @@ public PyObject modules; public PyList path; + + // shadowed statics - don't use directly + public static PyList warnoptions = new PyList(); public static PyObject builtins; public PyList meta_path; public PyList path_hooks; public PyObject path_importer_cache; - public static PyString platform = new PyString("java"); - public static PyString byteorder = new PyString("big"); - public PyObject ps1 = new PyString(">>> "); public PyObject ps2 = new PyString("... "); - - public static int maxint = Integer.MAX_VALUE; - public static int minint = Integer.MIN_VALUE; - + public PyObject executable; - public static PyList warnoptions; - private String currentWorkingDir; private PyObject environ; @@ -153,18 +157,24 @@ // Set up the initial standard ins and outs String mode = Options.unbuffered ? "b" : ""; int buffering = Options.unbuffered ? 0 : 1; - __stdout__ = stdout = new PyFile(System.out, "<stdout>", "w" + mode, buffering, false); - __stderr__ = stderr = new PyFile(System.err, "<stderr>", "w" + mode, 0, false); - __stdin__ = stdin = new PyFile(System.in, "<stdin>", "r" + mode, buffering, false); + stdout = new PyFile(System.out, "<stdout>", "w" + mode, buffering, false); + stderr = new PyFile(System.err, "<stderr>", "w" + mode, 0, false); + stdin = new PyFile(System.in, "<stdin>", "r" + mode, buffering, false); __displayhook__ = new PySystemStateFunctions("displayhook", 10, 1, 1); __excepthook__ = new PySystemStateFunctions("excepthook", 30, 3, 3); - if(builtins == null){ - builtins = new PyStringMap(); - __builtin__.fillWithBuiltins(builtins); + String encoding = registry.getProperty("python.console.encoding", "US-ASCII"); + ((PyFile)stdout).encoding = encoding; + ((PyFile)stderr).encoding = encoding; + ((PyFile)stdin).encoding = encoding; + __stdout__ = stdout; + __stderr__ = stderr; + __stdin__ = stdin; + + if (builtins == null) { + builtins = getDefaultBuiltins(); } - PyModule __builtin__ = new PyModule("__builtin__", builtins); - modules.__setitem__("__builtin__", __builtin__); + modules.__setitem__("__builtin__", new PyModule("__builtin__", getDefaultBuiltins())); __dict__ = new PyStringMap(); __dict__.invoke("update", getType().fastGetDict()); __dict__.__setitem__("displayhook", __displayhook__); @@ -175,56 +185,150 @@ __dict__.invoke("update", getType().fastGetDict()); } + private static void checkReadOnly(String name) { + if (name == "__dict__" || + name == "__class__" || + name == "registry" || + name == "exec_prefix" || + name == "platform" || + name == "packageManager") { + throw Py.TypeError("readonly attribute"); + } + } + + private static void checkMustExist(String name) { + if (name == "__dict__" || + name == "__class__" || + name == "registry" || + name == "exec_prefix" || + name == "platform" || + name == "packageManager" || + name == "builtins" || + name == "warnoptions") { + throw Py.TypeError("readonly attribute"); + } + } + + // might be nice to have something general here, but for now these + // seem to be the only values that need to be explicitly shadowed + private Shadow shadowing; + public synchronized void shadow() { + if (shadowing == null) { + shadowing = new Shadow(); + } + } + + private static class DefaultBuiltinsHolder { + static final PyObject builtins = fillin(); + + static PyObject fillin() { + PyObject temp = new PyStringMap(); + __builtin__.fillWithBuiltins(temp); + return temp; + } + } + + public static PyObject getDefaultBuiltins() { + return DefaultBuiltinsHolder.builtins; + } + + public synchronized PyObject getBuiltins() { + if (shadowing == null) { + return getDefaultBuiltins(); + } + else { + return shadowing.builtins; + } + } + + public synchronized void setBuiltins(PyObject value) { + if (shadowing == null) { + builtins = value; + } else { + shadowing.builtins = value; + } + modules.__setitem__("__builtin__", new PyModule("__builtin__", value)); + } + + public synchronized PyObject getWarnoptions() { + if (shadowing == null) { + return warnoptions; + } + else { + return shadowing.warnoptions; + } + } + + public synchronized void setWarnoptions(PyObject value) { + if (shadowing == null) { + warnoptions = new PyList(value); + } else { + shadowing.warnoptions = new PyList(value); + } + } + // xxx fix this accessors public PyObject __findattr_ex__(String name) { if (name == "exc_value") { PyException exc = Py.getThreadState().exception; - if (exc == null) return null; + if (exc == null) { + return null; + } return exc.value; - } - if (name == "exc_type") { + } else if (name == "exc_type") { PyException exc = Py.getThreadState().exception; - if (exc == null) return null; + if (exc == null) { + return null; + } return exc.type; - } - if (name == "exc_traceback") { + } else if (name == "exc_traceback") { PyException exc = Py.getThreadState().exception; - if (exc == null) return null; + if (exc == null) { + return null; + } return exc.traceback; - } - if (name == "warnoptions") { - if (warnoptions == null) - warnoptions = new PyList(); - return warnoptions; - } + } else if (name == "warnoptions") { + return getWarnoptions(); + } else if (name == "builtins") { + return getBuiltins(); + } else { + PyObject ret = super.__findattr_ex__(name); + if (ret != null) { + if (ret instanceof PyMethod) { + if (__dict__.__finditem__(name) instanceof PyReflectedFunction) { + return ret; // xxx depends on nonstandard __dict__ + } + } else if (ret == PyAttributeDeleted.INSTANCE) { + return null; + } else { + return ret; + } + } - PyObject ret = super.__findattr_ex__(name); - if (ret != null) { - if (ret instanceof PyMethod) { - if (__dict__.__finditem__(name) instanceof PyReflectedFunction) - return ret; // xxx depends on nonstandard __dict__ - } else if (ret == PyAttributeDeleted.INSTANCE) { - return null; - } - else return ret; + return __dict__.__finditem__(name); } - - return __dict__.__finditem__(name); } public void __setattr__(String name, PyObject value) { - if (name == "__dict__" || name == "__class__") - throw Py.TypeError("readonly attribute"); - PyObject ret = getType().lookup(name); // xxx fix fix fix - if (ret != null && ret.jtryset(this, value)) { - return; + checkReadOnly(name); + if (name == "builtins") { + shadow(); + setBuiltins(value); } - __dict__.__setitem__(name, value); + else if (name == "warnoptions") { + shadow(); + setWarnoptions(value); + } else { + PyObject ret = getType().lookup(name); // xxx fix fix fix + if (ret != null && ret.jtryset(this, value)) { + return; + } + __dict__.__setitem__(name, value); + } } public void __delattr__(String name) { - if (name == "__dict__" || name == "__class__") - throw Py.TypeError("readonly attribute"); + checkMustExist(name); PyObject ret = getType().lookup(name); // xxx fix fix fix if (ret != null) { ret.jtryset(this, PyAttributeDeleted.INSTANCE); @@ -233,7 +337,7 @@ __dict__.__delitem__(name); } catch (PyException pye) { // KeyError if (ret == null) { - throw Py.AttributeError(name); + throw Py.AttributeError(name); } } } @@ -558,7 +662,7 @@ Py.setSystemState(Py.defaultSystemState); if (classLoader != null) Py.defaultSystemState.setClassLoader(classLoader); - Py.initClassExceptions(PySystemState.builtins); + Py.initClassExceptions(getDefaultBuiltins()); // Make sure that Exception classes have been loaded new PySyntaxError("", 1, 1, "", ""); } @@ -888,9 +992,10 @@ if (o == Py.None) return; - PySystemState.builtins.__setitem__("_", Py.None); + PyObject currentBuiltins = Py.getSystemState().getBuiltins(); + currentBuiltins.__setitem__("_", Py.None); Py.stdout.println(o.__repr__()); - PySystemState.builtins.__setitem__("_", o); + currentBuiltins.__setitem__("_", o); } static void excepthook(PyObject type, PyObject val, PyObject tb) { @@ -987,3 +1092,13 @@ return null; } } + +class Shadow { + PyObject builtins; + PyList warnoptions; + + Shadow() { + builtins = PySystemState.getDefaultBuiltins(); + warnoptions = PySystemState.warnoptions; + } +} \ No newline at end of file Modified: trunk/jython/src/org/python/core/exceptions.java =================================================================== --- trunk/jython/src/org/python/core/exceptions.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/core/exceptions.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -36,7 +36,7 @@ if (frame.f_back != null) { frame.f_builtins = frame.f_back.f_builtins; } else { - frame.f_builtins = PySystemState.builtins; + frame.f_builtins = PySystemState.getDefaultBuiltins(); } } ts.frame = frame; Modified: trunk/jython/src/org/python/util/InteractiveConsole.java =================================================================== --- trunk/jython/src/org/python/util/InteractiveConsole.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/util/InteractiveConsole.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -46,7 +46,7 @@ return Py.newString(raw_input(prompt)); } }; - PySystemState.builtins.__setitem__("raw_input", newRawInput); + Py.getSystemState().getBuiltins().__setitem__("raw_input", newRawInput); } } Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-12-29 06:59:00 UTC (rev 5805) +++ trunk/jython/src/org/python/util/jython.java 2008-12-29 08:33:23 UTC (rev 5806) @@ -137,10 +137,11 @@ // Now create an interpreter InteractiveConsole interp = newInterpreter(); - PySystemState.warnoptions = new PyList(); + PyList warnoptions = new PyList(); for (String wopt : opts.warnoptions) { - PySystemState.warnoptions.append(new PyString(wopt)); + warnoptions.append(new PyString(wopt)); } + Py.getSystemState().setWarnoptions(warnoptions); // Decide if stdin is interactive if (!opts.fixInteractive && opts.interactive) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-29 06:59:02
|
Revision: 5805 http://jython.svn.sourceforge.net/jython/?rev=5805&view=rev Author: zyasoft Date: 2008-12-29 06:59:00 +0000 (Mon, 29 Dec 2008) Log Message: ----------- Added signal support per http://bugs.jython.org/issue1074, with signal.py based on the patch submitted by Glyph Lefkowitz. One significant difference is that it introspects the signal constants through the API provided by sun.misc.Signals - no support for Constantine actually needed here. Also added os.kill, os.wait, and os.waitpid if running on posix. This should help with our Twisted support, among other packages. Modified Paths: -------------- trunk/jython/Lib/os.py trunk/jython/Lib/test/regrtest.py Added Paths: ----------- trunk/jython/Lib/signal.py trunk/jython/Lib/test/test_signal.py Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2008-12-29 05:45:42 UTC (rev 5804) +++ trunk/jython/Lib/os.py 2008-12-29 06:59:00 UTC (rev 5805) @@ -41,6 +41,7 @@ 'write']) import errno +import jarray import java.lang.System import time import stat as _stat @@ -993,6 +994,45 @@ Call the system call setsid().""" return _posix.setsid() + # This implementation of fork partially works on + # Jython. Diagnosing what works, what doesn't, and fixing it is + # left for another day. In any event, this would only be + # marginally useful. + + # def fork(): + # """fork() -> pid + # + # Fork a child process. + # Return 0 to child process and PID of child to parent process.""" + # return _posix.fork() + + def kill(pid, sig): + """kill(pid, sig) + + Kill a process with a signal.""" + return _posix.kill(pid, sig) + + def wait(): + """wait() -> (pid, status) + + Wait for completion of a child process.""" + + status = jarray.zeros(1, 'i') + res_pid = _posix.wait(status) + if res_pid == -1: + raise OSError(status[0], strerror(status[0])) + return res_pid, status[0] + + def waitpid(pid, options): + """waitpid(pid, options) -> (pid, status) + + Wait for completion of a given child process.""" + status = jarray.zeros(1, 'i') + res_pid = _posix.waitpid(pid, status, options) + if res_pid == -1: + raise OSError(status[0], strerror(status[0])) + return res_pid, status[0] + def getpid(): """getpid() -> pid @@ -1029,7 +1069,6 @@ return fileno.isatty() -import jarray from java.security import SecureRandom urandom_source = None Added: trunk/jython/Lib/signal.py =================================================================== --- trunk/jython/Lib/signal.py (rev 0) +++ trunk/jython/Lib/signal.py 2008-12-29 06:59:00 UTC (rev 5805) @@ -0,0 +1,239 @@ +""" + This module provides mechanisms to use signal handlers in Python. + + Functions: + + signal(sig,action) -- set the action for a given signal (done) + pause(sig) -- wait until a signal arrives [Unix only] + alarm(seconds) -- cause SIGALRM after a specified time [Unix only] + getsignal(sig) -- get the signal action for a given signal + default_int_handler(action) -- default SIGINT handler (done, but acts string) + + Constants: + + SIG_DFL -- used to refer to the system default handler + SIG_IGN -- used to ignore the signal + NSIG -- number of defined signals + + SIGINT, SIGTERM, etc. -- signal numbers + + *** IMPORTANT NOTICES *** + A signal handler function is called with two arguments: + the first is the signal number, the second is the interrupted stack frame. + + According to http://java.sun.com/products/jdk/faq/faq-sun-packages.html + 'writing java programs that rely on sun.* is risky: they are not portable, and are not supported.' + + However, in Jython, like Python, we let you decide what makes + sense for your application. If sun.misc.Signal is not available, + an ImportError is raised. +""" + + +try: + import sun.misc.Signal +except ImportError: + raise ImportError("signal module requires sun.misc.Signal, which is not available on this platform") + +import java.util.concurrent +import os +import sun.misc.SignalHandler +import sys +import threading +import time +from java.lang import IllegalArgumentException + +debug = 0 + +def _init_signals(): + # install signals by checking for standard names + # using IllegalArgumentException to diagnose + + possible_signals = """ + SIGABRT + SIGALRM + SIGBUS + SIGCHLD + SIGCONT + SIGFPE + SIGHUP + SIGILL + SIGINFO + SIGINT + SIGIOT + SIGKILL + SIGPIPE + SIGPOLL + SIGPROF + SIGQUIT + SIGSEGV + SIGSTOP + SIGSYS + SIGTERM + SIGTRAP + SIGTSTP + SIGTTIN + SIGTTOU + SIGURG + SIGUSR1 + SIGUSR2 + SIGVTALRM + SIGWINCH + SIGXCPU + SIGXFSZ + """.split() + + _module = __import__(__name__) + signals = {} + signals_by_name = {} + for signal_name in possible_signals: + try: + java_signal = sun.misc.Signal(signal_name[3:]) + except IllegalArgumentException: + continue + + signal_number = java_signal.getNumber() + signals[signal_number] = java_signal + signals_by_name[signal_name] = java_signal + setattr(_module, signal_name, signal_number) # install as a module constant + return signals + +_signals = _init_signals() +NSIG = max(_signals.iterkeys()) + 1 +SIG_DFL = sun.misc.SignalHandler.SIG_DFL # default system handler +SIG_IGN = sun.misc.SignalHandler.SIG_IGN # handler to ignore a signal + +class JythonSignalHandler(sun.misc.SignalHandler): + def __init__(self, action): + self.action = action + + def handle(self, signal): + # passing a frame here probably don't make sense in a threaded system, + # but perhaps revisit + self.action(signal.getNumber(), None) + +def signal(sig, action): + """ + signal(sig, action) -> action + + Set the action for the given signal. The action can be SIG_DFL, + SIG_IGN, or a callable Python object. The previous action is + returned. See getsignal() for possible return values. + + *** IMPORTANT NOTICE *** + A signal handler function is called with two arguments: + the first is the signal number, the second is the interrupted stack frame. + """ + # maybe keep a weak ref map of handlers we have returned? + + try: + signal = _signals[sig] + except KeyError: + raise ValueError("signal number out of range") + + if callable(action): + prev = sun.misc.Signal.handle(signal, JythonSignalHandler(action)) + elif action in (SIG_IGN, SIG_DFL) or isinstance(action, sun.misc.SignalHandler): + prev = sun.misc.Signal.handle(signal, action) + else: + raise TypeError("signal handler must be signal.SIG_IGN, signal.SIG_DFL, or a callable object") + + if isinstance(prev, JythonSignalHandler): + return prev.action + else: + return prev + + +# dangerous! don't use! +def getsignal(sig): + """getsignal(sig) -> action + + Return the current action for the given signal. The return value can be: + SIG_IGN -- if the signal is being ignored + SIG_DFL -- if the default action for the signal is in effect + None -- if an unknown handler is in effect + anything else -- the callable Python object used as a handler + + Note for Jython: this function is NOT threadsafe. The underlying + Java support only enables getting the current signal handler by + setting a new one. So this is completely prone to race conditions. + """ + try: + signal = _signals[sig] + except KeyError: + raise ValueError("signal number out of range") + current = sun.misc.Signal.handle(signal, SIG_DFL) + sun.misc.Signal.handle(signal, current) # and reinstall + + if isinstance(current, JythonSignalHandler): + return current.action + else: + return current + +def default_int_handler(sig, frame): + """ + default_int_handler(...) + + The default handler for SIGINT installed by Python. + It raises KeyboardInterrupt. + """ + raise KeyboardInterrupt + +def pause(): + raise NotImplementedError + +_alarm_timer_holder = java.util.concurrent.atomic.AtomicReference() + +def _alarm_handler(sig, frame): + print "Alarm clock" + os._exit(0) + +# install a default alarm handler, the one we get by default doesn't +# work terribly well since it throws a bus error (at least on OS X)! +try: + SIGALRM + signal(SIGALRM, _alarm_handler) +except NameError: + pass + +class _Alarm(object): + def __init__(self, interval, task): + self.interval = interval + self.task = task + self.scheduled = None + self.timer = threading.Timer(self.interval, self.task) + + def start(self): + self.timer.start() + self.scheduled = time.time() + self.interval + + def cancel(self): + self.timer.cancel() + now = time.time() + if self.scheduled and self.scheduled > now: + return self.scheduled - now + else: + return 0 + +def alarm(time): + try: + SIGALRM + except NameError: + raise NotImplementedError("alarm not implemented on this platform") + + def raise_alarm(): + sun.misc.Signal.raise(_signals[SIGALRM]) + + if time > 0: + new_alarm_timer = _Alarm(time, raise_alarm) + else: + new_alarm_timer = None + old_alarm_timer = _alarm_timer_holder.getAndSet(new_alarm_timer) + if old_alarm_timer: + scheduled = int(old_alarm_timer.cancel()) + else: + scheduled = 0 + + if new_alarm_timer: + new_alarm_timer.start() + return scheduled Modified: trunk/jython/Lib/test/regrtest.py =================================================================== --- trunk/jython/Lib/test/regrtest.py 2008-12-29 05:45:42 UTC (rev 5804) +++ trunk/jython/Lib/test/regrtest.py 2008-12-29 06:59:00 UTC (rev 5805) @@ -1430,7 +1430,6 @@ test_resource test_rgbimg test_scriptpackages - test_signal test_socket_ssl test_socketserver test_sqlite Added: trunk/jython/Lib/test/test_signal.py =================================================================== --- trunk/jython/Lib/test/test_signal.py (rev 0) +++ trunk/jython/Lib/test/test_signal.py 2008-12-29 06:59:00 UTC (rev 5805) @@ -0,0 +1,403 @@ +# based on test_signal.py from +# http://svn.python.org/projects/python/trunk/Lib/test/test_signal.py@62194 +# due to the fact that this version is modular enough to readily run +# on Jython. +# +# most tests are disabled due to lack of 2.6 support in our signal +# module (WakeupSignalTests, SiginterruptTest, ItimerTest) and no +# os.pipe/os.fork (InterProcessSignalTests). It would seem possible to +# remedy the latter by just using subprocess. + +from __future__ import with_statement +import unittest +from test import test_support +from contextlib import closing, nested +import gc +import pickle +import select +import signal +import subprocess +import traceback +import sys, os, time, errno + +if sys.platform[:3] in ('win', 'os2') or sys.platform == 'riscos': + raise test_support.TestSkipped("Can't test signal on %s" % \ + sys.platform) + + +class HandlerBCalled(Exception): + pass + + +def exit_subprocess(): + """Use os._exit(0) to exit the current subprocess. + + Otherwise, the test catches the SystemExit and continues executing + in parallel with the original test, so you wind up with an + exponential number of tests running concurrently. + """ + os._exit(0) + + +def ignoring_eintr(__func, *args, **kwargs): + try: + return __func(*args, **kwargs) + except EnvironmentError, e: + if e.errno != errno.EINTR: + raise + return None + + +class InterProcessSignalTests(unittest.TestCase): + MAX_DURATION = 20 # Entire test should last at most 20 sec. + + def setUp(self): + self.using_gc = gc.isenabled() + #gc.disable() + + def tearDown(self): + if self.using_gc: + gc.enable() + + def format_frame(self, frame, limit=None): + return ''.join(traceback.format_stack(frame, limit=limit)) + + def handlerA(self, signum, frame): + self.a_called = True + if test_support.verbose: + print "handlerA invoked from signal %s at:\n%s" % ( + signum, self.format_frame(frame, limit=1)) + + def handlerB(self, signum, frame): + self.b_called = True + if test_support.verbose: + print "handlerB invoked from signal %s at:\n%s" % ( + signum, self.format_frame(frame, limit=1)) + raise HandlerBCalled(signum, self.format_frame(frame)) + + def wait(self, child): + """Wait for child to finish, ignoring EINTR.""" + while True: + try: + child.wait() + return + except OSError, e: + if e.errno != errno.EINTR: + raise + + def run_test(self): + # Install handlers. This function runs in a sub-process, so we + # don't worry about re-setting the default handlers. + signal.signal(signal.SIGHUP, self.handlerA) + signal.signal(signal.SIGUSR1, self.handlerB) + signal.signal(signal.SIGUSR2, signal.SIG_IGN) + signal.signal(signal.SIGALRM, signal.default_int_handler) + + # Variables the signals will modify: + self.a_called = False + self.b_called = False + + # Let the sub-processes know who to send signals to. + pid = os.getpid() + if test_support.verbose: + print "test runner's pid is", pid + + child = ignoring_eintr(subprocess.Popen, ['kill', '-HUP', str(pid)]) + if child: + self.wait(child) + if not self.a_called: + time.sleep(1) # Give the signal time to be delivered. + self.assertTrue(self.a_called) + self.assertFalse(self.b_called) + self.a_called = False + + # Make sure the signal isn't delivered while the previous + # Popen object is being destroyed, because __del__ swallows + # exceptions. + del child + try: + child = subprocess.Popen(['kill', '-USR1', str(pid)]) + # This wait should be interrupted by the signal's exception. + self.wait(child) + time.sleep(1) # Give the signal time to be delivered. + self.fail('HandlerBCalled exception not thrown') + except HandlerBCalled: + self.assertTrue(self.b_called) + self.assertFalse(self.a_called) + if test_support.verbose: + print "HandlerBCalled exception caught" + + child = ignoring_eintr(subprocess.Popen, ['kill', '-USR2', str(pid)]) + if child: + self.wait(child) # Nothing should happen. + + try: + signal.alarm(1) + # The race condition in pause doesn't matter in this case, + # since alarm is going to raise a KeyboardException, which + # will skip the call. + signal.pause() + # But if another signal arrives before the alarm, pause + # may return early. + time.sleep(1) + except KeyboardInterrupt: + if test_support.verbose: + print "KeyboardInterrupt (the alarm() went off)" + except: + self.fail("Some other exception woke us from pause: %s" % + traceback.format_exc()) + else: + self.fail("pause returned of its own accord, and the signal" + " didn't arrive after another second.") + + def test_main(self): + # This function spawns a child process to insulate the main + # test-running process from all the signals. It then + # communicates with that child process over a pipe and + # re-raises information about any exceptions the child + # throws. The real work happens in self.run_test(). + os_done_r, os_done_w = os.pipe() + with nested(closing(os.fdopen(os_done_r)), + closing(os.fdopen(os_done_w, 'w'))) as (done_r, done_w): + child = os.fork() + if child == 0: + # In the child process; run the test and report results + # through the pipe. + try: + done_r.close() + # Have to close done_w again here because + # exit_subprocess() will skip the enclosing with block. + with closing(done_w): + try: + self.run_test() + except: + pickle.dump(traceback.format_exc(), done_w) + else: + pickle.dump(None, done_w) + except: + print 'Uh oh, raised from pickle.' + traceback.print_exc() + finally: + exit_subprocess() + + done_w.close() + # Block for up to MAX_DURATION seconds for the test to finish. + r, w, x = select.select([done_r], [], [], self.MAX_DURATION) + if done_r in r: + tb = pickle.load(done_r) + if tb: + self.fail(tb) + else: + os.kill(child, signal.SIGKILL) + self.fail('Test deadlocked after %d seconds.' % + self.MAX_DURATION) + + +class BasicSignalTests(unittest.TestCase): + def trivial_signal_handler(self, *args): + pass + + def test_out_of_range_signal_number_raises_error(self): + self.assertRaises(ValueError, signal.getsignal, 4242) + + self.assertRaises(ValueError, signal.signal, 4242, + self.trivial_signal_handler) + + def test_setting_signal_handler_to_none_raises_error(self): + self.assertRaises(TypeError, signal.signal, + signal.SIGUSR1, None) + + def test_getsignal(self): + hup = signal.signal(signal.SIGHUP, self.trivial_signal_handler) + self.assertEquals(signal.getsignal(signal.SIGHUP), + self.trivial_signal_handler) + signal.signal(signal.SIGHUP, hup) + self.assertEquals(signal.getsignal(signal.SIGHUP), hup) + + +class WakeupSignalTests(unittest.TestCase): + TIMEOUT_FULL = 10 + TIMEOUT_HALF = 5 + + def test_wakeup_fd_early(self): + import select + + signal.alarm(1) + before_time = time.time() + # We attempt to get a signal during the sleep, + # before select is called + time.sleep(self.TIMEOUT_FULL) + mid_time = time.time() + self.assert_(mid_time - before_time < self.TIMEOUT_HALF) + select.select([self.read], [], [], self.TIMEOUT_FULL) + after_time = time.time() + self.assert_(after_time - mid_time < self.TIMEOUT_HALF) + + def test_wakeup_fd_during(self): + import select + + signal.alarm(1) + before_time = time.time() + # We attempt to get a signal during the select call + self.assertRaises(select.error, select.select, + [self.read], [], [], self.TIMEOUT_FULL) + after_time = time.time() + self.assert_(after_time - before_time < self.TIMEOUT_HALF) + + def setUp(self): + import fcntl + + self.alrm = signal.signal(signal.SIGALRM, lambda x,y:None) + self.read, self.write = os.pipe() + flags = fcntl.fcntl(self.write, fcntl.F_GETFL, 0) + flags = flags | os.O_NONBLOCK + fcntl.fcntl(self.write, fcntl.F_SETFL, flags) + self.old_wakeup = signal.set_wakeup_fd(self.write) + + def tearDown(self): + signal.set_wakeup_fd(self.old_wakeup) + os.close(self.read) + os.close(self.write) + signal.signal(signal.SIGALRM, self.alrm) + +class SiginterruptTest(unittest.TestCase): + signum = signal.SIGUSR1 + def readpipe_interrupted(self, cb): + r, w = os.pipe() + ppid = os.getpid() + pid = os.fork() + + oldhandler = signal.signal(self.signum, lambda x,y: None) + cb() + if pid==0: + # child code: sleep, kill, sleep. and then exit, + # which closes the pipe from which the parent process reads + try: + time.sleep(0.2) + os.kill(ppid, self.signum) + time.sleep(0.2) + finally: + exit_subprocess() + + try: + os.close(w) + + try: + d=os.read(r, 1) + return False + except OSError, err: + if err.errno != errno.EINTR: + raise + return True + finally: + signal.signal(self.signum, oldhandler) + os.waitpid(pid, 0) + + def test_without_siginterrupt(self): + i=self.readpipe_interrupted(lambda: None) + self.assertEquals(i, True) + + def test_siginterrupt_on(self): + i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 1)) + self.assertEquals(i, True) + + def test_siginterrupt_off(self): + i=self.readpipe_interrupted(lambda: signal.siginterrupt(self.signum, 0)) + self.assertEquals(i, False) + +class ItimerTest(unittest.TestCase): + def setUp(self): + self.hndl_called = False + self.hndl_count = 0 + self.itimer = None + self.old_alarm = signal.signal(signal.SIGALRM, self.sig_alrm) + + def tearDown(self): + signal.signal(signal.SIGALRM, self.old_alarm) + if self.itimer is not None: # test_itimer_exc doesn't change this attr + # just ensure that itimer is stopped + signal.setitimer(self.itimer, 0) + + def sig_alrm(self, *args): + self.hndl_called = True + if test_support.verbose: + print("SIGALRM handler invoked", args) + + def sig_vtalrm(self, *args): + self.hndl_called = True + + if self.hndl_count > 3: + # it shouldn't be here, because it should have been disabled. + raise signal.ItimerError("setitimer didn't disable ITIMER_VIRTUAL " + "timer.") + elif self.hndl_count == 3: + # disable ITIMER_VIRTUAL, this function shouldn't be called anymore + signal.setitimer(signal.ITIMER_VIRTUAL, 0) + if test_support.verbose: + print("last SIGVTALRM handler call") + + self.hndl_count += 1 + + if test_support.verbose: + print("SIGVTALRM handler invoked", args) + + def sig_prof(self, *args): + self.hndl_called = True + signal.setitimer(signal.ITIMER_PROF, 0) + + if test_support.verbose: + print("SIGPROF handler invoked", args) + + def test_itimer_exc(self): + # XXX I'm assuming -1 is an invalid itimer, but maybe some platform + # defines it ? + self.assertRaises(signal.ItimerError, signal.setitimer, -1, 0) + # Negative times are treated as zero on some platforms. + if 0: + self.assertRaises(signal.ItimerError, + signal.setitimer, signal.ITIMER_REAL, -1) + + def test_itimer_real(self): + self.itimer = signal.ITIMER_REAL + signal.setitimer(self.itimer, 1.0) + if test_support.verbose: + print("\ncall pause()...") + signal.pause() + + self.assertEqual(self.hndl_called, True) + + def test_itimer_virtual(self): + self.itimer = signal.ITIMER_VIRTUAL + signal.signal(signal.SIGVTALRM, self.sig_vtalrm) + signal.setitimer(self.itimer, 0.3, 0.2) + + for i in xrange(100000000): + if signal.getitimer(self.itimer) == (0.0, 0.0): + break # sig_vtalrm handler stopped this itimer + + # virtual itimer should be (0.0, 0.0) now + self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0)) + # and the handler should have been called + self.assertEquals(self.hndl_called, True) + + def test_itimer_prof(self): + self.itimer = signal.ITIMER_PROF + signal.signal(signal.SIGPROF, self.sig_prof) + signal.setitimer(self.itimer, 0.2, 0.2) + + for i in xrange(100000000): + if signal.getitimer(self.itimer) == (0.0, 0.0): + break # sig_prof handler stopped this itimer + + # profiling itimer should be (0.0, 0.0) now + self.assertEquals(signal.getitimer(self.itimer), (0.0, 0.0)) + # and the handler should have been called + self.assertEqual(self.hndl_called, True) + +def test_main(): + test_support.run_unittest(BasicSignalTests) #, InterProcessSignalTests) + # ignore these 2.6 tests: WakeupSignalTests, SiginterruptTest, ItimerTest + + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-29 05:45:49
|
Revision: 5804 http://jython.svn.sourceforge.net/jython/?rev=5804&view=rev Author: cgroves Date: 2008-12-29 05:45:42 +0000 (Mon, 29 Dec 2008) Log Message: ----------- test207 - Moved to test_unicode_jy test208 - Moved to test_java_visibility test209,211 - Tested by test_cpickle test210 - Tested by test_pickle test212 - Moved to test_str test213 - Tested by test_str test214,217,218,220-224,226-229,237,242,246,249,251-257 - Testing jythonc; deleted test215 - Tested by test_list test219 - Moved to org.python.tests.ExceptionTest test225 - Moved to test_grammar_jy test230,235,239,240 - Not sure what it's testing; deleted test231 - Moved to test_java_integration test232 - Moved to test_java_visibility test233 - Tested by test_import_jy test234 - Tested by test_copy test238 - Was already disabled; deleted test245 - Tested by org.python.util.InterpreterTest test247 - Moved to test_java_integration test248 - Dupe of test247 test250 - Moved to test_java_visibility test258 - Tested by test_import_jy Modified Paths: -------------- trunk/jython/Lib/test/string_tests.py trunk/jython/Lib/test/test_grammar_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/bugtests/test230.py trunk/jython/src/org/python/core/PyArray.java trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/src/org/python/core/PyReflectedFunction.java trunk/jython/tests/java/org/python/expose/generate/ExposedTypeProcessorTest.java trunk/jython/tests/java/org/python/tests/Callbacker.java trunk/jython/tests/java/org/python/tests/Coercions.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/BadStaticInitializer.java trunk/jython/tests/java/org/python/tests/ExceptionTest.java trunk/jython/tests/java/org/python/tests/HiddenSuper.java trunk/jython/tests/java/org/python/tests/OtherSubVisible.java trunk/jython/tests/java/org/python/tests/SomePyMethods.java Removed Paths: ------------- trunk/jython/bugtests/classes/test208j.java trunk/jython/bugtests/classes/test208j0.java trunk/jython/bugtests/classes/test208j1.java trunk/jython/bugtests/classes/test208j2.java trunk/jython/bugtests/classes/test217p/ trunk/jython/bugtests/classes/test219e.java trunk/jython/bugtests/classes/test219i.java trunk/jython/bugtests/classes/test219j.java trunk/jython/bugtests/classes/test220e.java trunk/jython/bugtests/classes/test220i.java trunk/jython/bugtests/classes/test220j.java trunk/jython/bugtests/classes/test231j.java trunk/jython/bugtests/classes/test231j2.java trunk/jython/bugtests/classes/test232p/ trunk/jython/bugtests/classes/test236j1.java trunk/jython/bugtests/classes/test236j2.java trunk/jython/bugtests/classes/test246p/ trunk/jython/bugtests/classes/test248j.java trunk/jython/bugtests/test207.py trunk/jython/bugtests/test208.py trunk/jython/bugtests/test209.py trunk/jython/bugtests/test209p/ trunk/jython/bugtests/test210.py trunk/jython/bugtests/test212.py trunk/jython/bugtests/test213.py trunk/jython/bugtests/test214.html trunk/jython/bugtests/test214.py trunk/jython/bugtests/test215.py trunk/jython/bugtests/test217.py trunk/jython/bugtests/test217c.py trunk/jython/bugtests/test217t.java trunk/jython/bugtests/test218.py trunk/jython/bugtests/test218c.py trunk/jython/bugtests/test219.py trunk/jython/bugtests/test220.py trunk/jython/bugtests/test220c.py trunk/jython/bugtests/test221.py trunk/jython/bugtests/test221c.py trunk/jython/bugtests/test222.py trunk/jython/bugtests/test222s.py trunk/jython/bugtests/test223.py trunk/jython/bugtests/test223s.py trunk/jython/bugtests/test224.py trunk/jython/bugtests/test224s.py trunk/jython/bugtests/test225.py trunk/jython/bugtests/test225s.py trunk/jython/bugtests/test226.py trunk/jython/bugtests/test226c.py trunk/jython/bugtests/test227.py trunk/jython/bugtests/test227c.py trunk/jython/bugtests/test228.py trunk/jython/bugtests/test228s.py trunk/jython/bugtests/test229.py trunk/jython/bugtests/test229c.py trunk/jython/bugtests/test231.py trunk/jython/bugtests/test232.py trunk/jython/bugtests/test233.py trunk/jython/bugtests/test234.py trunk/jython/bugtests/test237.py trunk/jython/bugtests/test237m1.py trunk/jython/bugtests/test237m2.py trunk/jython/bugtests/test238.py trunk/jython/bugtests/test242.py trunk/jython/bugtests/test242c.py trunk/jython/bugtests/test245.py trunk/jython/bugtests/test245j.java trunk/jython/bugtests/test246.py trunk/jython/bugtests/test246c.py trunk/jython/bugtests/test247.py trunk/jython/bugtests/test247j.java trunk/jython/bugtests/test248.py trunk/jython/bugtests/test249.py trunk/jython/bugtests/test249c.py trunk/jython/bugtests/test250.py trunk/jython/bugtests/test250j.java trunk/jython/bugtests/test251.py trunk/jython/bugtests/test251c.py trunk/jython/bugtests/test251c2.py trunk/jython/bugtests/test252.py trunk/jython/bugtests/test252c.py trunk/jython/bugtests/test252c2.py trunk/jython/bugtests/test253.py trunk/jython/bugtests/test253c.py trunk/jython/bugtests/test253c2.py trunk/jython/bugtests/test254.html trunk/jython/bugtests/test254.py trunk/jython/bugtests/test254c.py trunk/jython/bugtests/test255.py trunk/jython/bugtests/test255s1.py trunk/jython/bugtests/test255s2.py trunk/jython/bugtests/test256.html trunk/jython/bugtests/test256.py trunk/jython/bugtests/test256a.py trunk/jython/bugtests/test257.py trunk/jython/bugtests/test258.py trunk/jython/bugtests/test258m1.py Modified: trunk/jython/Lib/test/string_tests.py =================================================================== --- trunk/jython/Lib/test/string_tests.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/string_tests.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -917,7 +917,9 @@ self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 3)) self.checkequal(u'abc', 'abc', '__getitem__', slice(0, 1000)) self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1)) + self.checkequal(u'a', 'abc', '__getitem__', slice(0, 1L)) self.checkequal(u'', 'abc', '__getitem__', slice(0, 0)) + self.checkequal(u'', 'abc', '__getitem__', slice(0L, 0L)) # FIXME What about negative indices? This is handled differently by [] and __getitem__(slice) self.checkraises(TypeError, 'abc', '__getitem__', 'def') Modified: trunk/jython/Lib/test/test_grammar_jy.py =================================================================== --- trunk/jython/Lib/test/test_grammar_jy.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_grammar_jy.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -24,6 +24,14 @@ self.assertEquals(uR"spam", Ur"spam") self.assertEquals(ur"spam", UR"spam") + def testKeywordOperations(self): + def foo(a=1, b=2 + 4): + return b + self.assertEquals(6, foo()) + self.assertEquals(6, foo(1)) + self.assertEquals(7, foo(1, 7)) + self.assertEquals(10, foo(b=10)) + def test_main(): test_support.run_unittest(GrammarTest) Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -8,7 +8,7 @@ from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import (Boolean, Integer, Object, String, Runnable, +from java.lang import (Boolean, ExceptionInInitializerError, Integer, Object, String, Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte) from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath @@ -322,10 +322,12 @@ self.assertEquals(self.kws.yield(), "yield") class ImportTest(unittest.TestCase): - def test_bad_input_exception(self): self.assertRaises(ValueError, __import__, '') + def test_broken_static_initializer(self): + self.assertRaises(ExceptionInInitializerError, __import__, "org.python.tests.BadStaticInitializer") + class ColorTest(unittest.TestCase): def test_assigning_over_method(self): @@ -417,9 +419,9 @@ def call(self, extraarg=None): called.append(extraarg) Callbacker.callNoArg(PyCallback()) - Callbacker.callOneArg(PyCallback(), "arg") + Callbacker.callOneArg(PyCallback(), 4294967295L) self.assertEquals(None, called[0]) - self.assertEquals("arg", called[1]) + self.assertEquals(4294967295L, called[1]) class PyBadCallback(Callbacker.Callback): def call(pyself, extraarg): self.fail("Shouldn't be callable with a no args") Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -3,8 +3,8 @@ from test import test_support from java.lang import Class from java.util import HashMap, Observable, Observer -from org.python.tests import (Coercions, InterfaceCombination, Invisible, OnlySubclassable, - SubVisible, Visible, VisibleOverride) +from org.python.tests import (Coercions, HiddenSuper, InterfaceCombination, Invisible, OnlySubclassable, + OtherSubVisible, SomePyMethods, SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -125,6 +125,10 @@ self.assertFalse(hasattr(i, "internalMethod"), "methods from private interfaces shouldn't be visible on a private class") + def test_super_methods_visible(self): + '''Bug #222847 - Can't access public member of package private base class''' + self.assertEquals("hi", HiddenSuper().hi()) + class JavaClassTest(unittest.TestCase): def test_class_methods_visible(self): self.assertFalse(HashMap.isInterface(), @@ -138,7 +142,13 @@ self.assertEquals(Class, HashMap.__class__) self.assertEquals(None, HashMap.__doc__) -class NumberCoercionTest(unittest.TestCase): + def test_python_methods(self): + s = SomePyMethods() + self.assertEquals(6, s[3]) + self.assertEquals(2, s.a, "Undefined attributes should go through to __getattr__") + self.assertEquals(3, s.b, "Defined fields should take precedence") + +class CoercionTest(unittest.TestCase): def test_int_coercion(self): c = Coercions() self.assertEquals("5", c.takeInt(5)) @@ -151,11 +161,13 @@ self.assertEquals("4", Coercions.takePyObj(1, 2, 3, 4)) c = Coercions() self.assertEquals("5", c.takePyObjInst(1, 2, 3, 4, 5)) + self.assertEquals("OtherSubVisible[]", c.takeArray([OtherSubVisible()])) + self.assertEquals("SubVisible[]", c.takeArray([SubVisible()])) def test_main(): test_support.run_unittest(VisibilityTest, JavaClassTest, - NumberCoercionTest) + CoercionTest) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -83,7 +83,32 @@ self.assertRaises(UnicodeDecodeError, u''.join, ['foo', '毛泽东']) self.assertRaises(UnicodeDecodeError, '毛泽东'.join, [u'foo', u'bar']) + def test_file_encoding(self): + '''Ensure file writing doesn't attempt to encode things by default and reading doesn't + decode things by default. This was jython's behavior prior to 2.2.1''' + EURO_SIGN = u"\u20ac" + try: + EURO_SIGN.encode() + except UnicodeEncodeError: + # This default encoding can't handle the encoding the Euro sign. Skip the test + return + f = open(test_support.TESTFN, "w") + self.assertRaises(UnicodeEncodeError, f, write, EURO_SIGN, + "Shouldn't be able to write out a Euro sign without first encoding") + f.close() + + f = open(test_support.TESTFN, "w") + f.write(EURO_SIGN.encode('utf-8')) + f.close() + + f = open(test_support.TESTFN, "r") + encoded_euro = f.read() + f.close() + os.remove(test_support.TESTFN) + self.assertEquals('\xe2\x82\xac', encoded_euro) + self.assertEquals(EURO_SIGN, encoded_euro.decode('utf-8')) + def test_main(): test_support.run_unittest(UnicodeTestCase) Deleted: trunk/jython/bugtests/classes/test208j.java =================================================================== --- trunk/jython/bugtests/classes/test208j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,14 +0,0 @@ -public class test208j { - public static String foo(test208j1[] p) { - return "test208j1[]"; - } - public static String foo(test208j2[] p) { - return "test208j2[]"; - } - public static String foo(Object p) { - return "Object"; - } - public static String foo(Object[] p) { - return "Object[]"; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test208j0.java =================================================================== --- trunk/jython/bugtests/classes/test208j0.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j0.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -public class test208j0 {} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test208j1.java =================================================================== --- trunk/jython/bugtests/classes/test208j1.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j1.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -public class test208j1 extends test208j0 {} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test208j2.java =================================================================== --- trunk/jython/bugtests/classes/test208j2.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test208j2.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -public class test208j2 extends test208j0 {} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test219e.java =================================================================== --- trunk/jython/bugtests/classes/test219e.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test219e.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,7 +0,0 @@ - -public class test219e extends Exception { - public test219e(String msg) { - super(msg); - } -} - Deleted: trunk/jython/bugtests/classes/test219i.java =================================================================== --- trunk/jython/bugtests/classes/test219i.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test219i.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,5 +0,0 @@ - -public interface test219i { - public void foo() throws test219e; - public void foo2(int i) throws test219e, Throwable; -} Deleted: trunk/jython/bugtests/classes/test219j.java =================================================================== --- trunk/jython/bugtests/classes/test219j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test219j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,25 +0,0 @@ - -public class test219j { - public static void checkFoo(test219i o) { - try { - o.foo(); - } catch (test219e t) { - // Success. - } catch (Throwable t) { - System.out.println(t.getClass() + " " + t); - } - } - - - public static void checkFoo2(test219i o, int i) { - try { - o.foo2(i); - } catch (test219e t) { - if (i != 0) - System.out.println("failure to catch test219e"); - } catch (Throwable t) { - if (i != 1) - System.out.println("failure to catch Throwable"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test220e.java =================================================================== --- trunk/jython/bugtests/classes/test220e.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test220e.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,7 +0,0 @@ - -public class test220e extends Exception { - public test220e(String msg) { - super(msg); - } -} - Deleted: trunk/jython/bugtests/classes/test220i.java =================================================================== --- trunk/jython/bugtests/classes/test220i.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test220i.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,5 +0,0 @@ - -public interface test220i { - public void foo() throws test220e; - public void foo2(int i) throws test220e, Throwable; -} Deleted: trunk/jython/bugtests/classes/test220j.java =================================================================== --- trunk/jython/bugtests/classes/test220j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test220j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,25 +0,0 @@ - -public class test220j { - public static void checkFoo(test220i o) { - try { - o.foo(); - } catch (test220e t) { - // Success. - } catch (Throwable t) { - System.out.println(t.getClass() + " " + t); - } - } - - - public static void checkFoo2(test220i o, int i) { - try { - o.foo2(i); - } catch (test220e t) { - if (i != 0) - System.out.println("failure to catch test220e"); - } catch (Throwable t) { - if (i != 1) - System.out.println("failure to catch Throwable"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test231j.java =================================================================== --- trunk/jython/bugtests/classes/test231j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test231j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,4 +0,0 @@ - -public interface test231j{ - public void handleRemove(long start); -} Deleted: trunk/jython/bugtests/classes/test231j2.java =================================================================== --- trunk/jython/bugtests/classes/test231j2.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test231j2.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,6 +0,0 @@ - -public class test231j2 { - public static void callback(test231j t) { - t.handleRemove(4294967295l); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test236j1.java =================================================================== --- trunk/jython/bugtests/classes/test236j1.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test236j1.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,4 +0,0 @@ -public class test236j1 { - static int foo_ = test236j2.foo(); -} - Deleted: trunk/jython/bugtests/classes/test236j2.java =================================================================== --- trunk/jython/bugtests/classes/test236j2.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test236j2.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,3 +0,0 @@ -public class test236j2 { - public static int foo() { return 12; } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test248j.java =================================================================== --- trunk/jython/bugtests/classes/test248j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/classes/test248j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,10 +0,0 @@ - -public class test248j { - static { - //System.out.println("hello1"); - String s = null; - s.length(); - //It seems like jdk1.4 doesn't like a naked throws in static. - //throw new NullPointerException("init failure"); - } -} Deleted: trunk/jython/bugtests/test207.py =================================================================== --- trunk/jython/bugtests/test207.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test207.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,34 +0,0 @@ -""" -Test that file writing doesn't attempt to encode things by default and reading -doesn't decode things by default. -""" - -import support - -EURO_SIGN = u"\u20ac" -try: - EURO_SIGN.encode() - import sys - raise support.TestError('Your default encoding, %s, can handle encoding the Euro sign. This test needs the default encoding to be unable to handle on its test character' % - sys.getdefaultencoding()) -except UnicodeEncodeError: - pass - -f = open("test207.out", "w") -try: - f.write(EURO_SIGN) - raise support.TestError("Shouldn't be able to write out a Euro sign without first encoding") -except UnicodeEncodeError: - pass -f.close() - -f = open("test207.out", "w") -f.write(EURO_SIGN.encode('utf-8')) -f.close() - -f = open("test207.out", "r") -encoded_euro = f.read() -f.close() -if encoded_euro != '\xe2\x82\xac' or encoded_euro.decode('utf-8') != EURO_SIGN: - raise support.TestError("Read something other than the euro sign that we wrote out") -f.close() Deleted: trunk/jython/bugtests/test208.py =================================================================== --- trunk/jython/bugtests/test208.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test208.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,17 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test208j.java") - -import test208j -import test208j1 -import test208j2 - -p=[test208j2()] -support.compare(test208j.foo(p), "test208j2\[\]") - -p=[test208j1()] -support.compare(test208j.foo(p), "test208j1\[\]") Deleted: trunk/jython/bugtests/test209.py =================================================================== --- trunk/jython/bugtests/test209.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test209.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -import cPickle - -import test209p.foo.bar - -o = test209p.foo.bar.baz() - -s = cPickle.dumps(o) -#print s - -o2 = cPickle.loads(s) - - - Deleted: trunk/jython/bugtests/test210.py =================================================================== --- trunk/jython/bugtests/test210.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test210.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,29 +0,0 @@ - -import sys -import pickle -tmpfile = "test210.tmp" - -try: - import test118 -except: - pass - -def saveValue( value): - f = open(tmpfile,"wb") - p = pickle.Pickler(f,1) - p.dump(value) - f.close() - -def loadValue(): - f=open(tmpfile,"rb") - retVal = pickle.Unpickler(f).load() - f.close() - return retVal - -for x in range(256): - saveValue(x) - y = loadValue() - if x != y: - print "saved: ", x, - print "loaded: ", y - Deleted: trunk/jython/bugtests/test212.py =================================================================== --- trunk/jython/bugtests/test212.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test212.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,14 +0,0 @@ -""" -Test long indexing of sequences (1.6) -""" - -import support - - -l = (0,1,2,3) - -if l[2L:4L] != (2, 3): - raise support.TestError, "long slice error #1" - -if "abcbdef"[2L:4L] != "cb": - raise support.TestError, "long slice error #2" Deleted: trunk/jython/bugtests/test213.py =================================================================== --- trunk/jython/bugtests/test213.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test213.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,15 +0,0 @@ -""" -Test %r on strings -""" - -import support - - - - -r = "%s %r" % ("abc", "abc") - -if r != "abc 'abc'": - raise support.TestError, "wrong output %s" % r - - Deleted: trunk/jython/bugtests/test214.html =================================================================== --- trunk/jython/bugtests/test214.html 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test214.html 2008-12-29 05:45:42 UTC (rev 5804) @@ -1 +0,0 @@ -<applet code="test214a" archive="test214.jar" width=300 height=200></applet> \ No newline at end of file Deleted: trunk/jython/bugtests/test214.py =================================================================== --- trunk/jython/bugtests/test214.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test214.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test214a.py", core=1, jar="test214.jar", output="test214.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test215.py =================================================================== --- trunk/jython/bugtests/test215.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test215.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,24 +0,0 @@ -""" - -""" - -import support - - - -l = [] -try: - l.insert('a', 1) -except TypeError: - pass -else: - raise support.TestError("Should raise TypeError") - - - -l = [] -l.insert(1, 'a') -l.insert(6, 'b') -l.insert(-1, 'c') -l.insert(3, 'd') - Deleted: trunk/jython/bugtests/test217.py =================================================================== --- trunk/jython/bugtests/test217.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test217.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import os -import support -support.compileJava("classes/test217p/test217i.java") - -support.compileJPythonc("test217c.py", output="test217.err") -support.compileJava("test217t.java", classpath="jpywork") -support.runJava("test217t", classpath="jpywork" + os.pathsep + ".") Deleted: trunk/jython/bugtests/test217c.py =================================================================== --- trunk/jython/bugtests/test217c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test217c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,10 +0,0 @@ -from java.lang import Object, String -from java.io import Serializable -from test217p import test217i -import java - -class test217c(Object, Serializable, test217i): - def add(self, x, y): - "@sig public java.lang.String add(int x, int y)" - return "The sum of %d and %d is %d" % (x, y, x+y) - Deleted: trunk/jython/bugtests/test217t.java =================================================================== --- trunk/jython/bugtests/test217t.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test217t.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,8 +0,0 @@ -public class test217t { - public static void main(String args[]) { - test217p.test217i c = new test217c(); - String s = c.add(1, 2); - if (!"The sum of 1 and 2 is 3".equals(s)) - System.out.println("Wrong output:" + s); - } -} Deleted: trunk/jython/bugtests/test218.py =================================================================== --- trunk/jython/bugtests/test218.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test218.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test218c.py", output="test218.err") - -support.runJava("test218c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test218c.py =================================================================== --- trunk/jython/bugtests/test218c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test218c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -a,b, = 1,2 Deleted: trunk/jython/bugtests/test219.py =================================================================== --- trunk/jython/bugtests/test219.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test219.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,22 +0,0 @@ - -import support - -support.compileJava("classes/test219j.java") - -import test219i, test219e, test219j - -class test219(test219i): - def foo(self): - raise test219e("raised in foo()") - def foo2(self, i): - if i == 0: - raise test219e("test219e raised in foo()") - else: - raise java.lang.Throwable("Throwable raised in foo()") - - -a = test219() - -test219j.checkFoo(a) -test219j.checkFoo2(a, 0) -test219j.checkFoo2(a, 1) Deleted: trunk/jython/bugtests/test220.py =================================================================== --- trunk/jython/bugtests/test220.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test220.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test220j.java") -support.compileJPythonc("test220c.py", output="test220.err") - -support.runJava("test220c", classpath="jpywork") Deleted: trunk/jython/bugtests/test220c.py =================================================================== --- trunk/jython/bugtests/test220c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test220c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,18 +0,0 @@ - -import test219i, test219e, test219j - -class test219(test219i): - def foo(self): - raise test219e("raised in foo()") - def foo2(self, i): - if i == 0: - raise test219e("test219e raised in foo()") - else: - raise java.lang.Throwable("Throwable raised in foo()") - - -a = test219() - -test219j.checkFoo(a) -test219j.checkFoo2(a, 0) -test219j.checkFoo2(a, 1) Deleted: trunk/jython/bugtests/test221.py =================================================================== --- trunk/jython/bugtests/test221.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test221.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -import test221c - -support.compileJPythonc("test221c.py", deep=1, output="test221.err") - -support.runJava("test221c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test221c.py =================================================================== --- trunk/jython/bugtests/test221c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test221c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,33 +0,0 @@ - -import support - -a = 1 -a += 1 + 2 -if a != 4: - raise support.TestError, "Wrong result #1 %s" % a - -a=[0,1,2,3,4,5] -if a[1:3] != [1, 2]: - raise support.TestError, "Wrong result #2 %s" % a[1:3] - -a[1:3] += ["a", "b"] -if a != [0, 1, 2, 'a', 'b', 3, 4, 5]: - raise support.TestError, "Wrong result #3 %s" % a - - -s = None - -class A: - def __getitem__(self, i): - global s - if s is None: - s = i - else: - raise support.TestError, "__getitem__ should only be called once" - return 11 - def __setitem__(self, i, v): - if s != i: - raise support.TestError, "__setitem__ should have same index af __getitem__" - -a = A() -a[:, ..., ::, 0:10:2, :10:, 1, 2:, ::-1] += 1 \ No newline at end of file Deleted: trunk/jython/bugtests/test222.py =================================================================== --- trunk/jython/bugtests/test222.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test222.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -try: - import test222s -except SyntaxError: - pass -else: - raise support.TestError('Should raise SyntaxError #1') - -ret = support.compileJPythonc("test222s.py", output="test222.err", - expectError=1) - -if ret == 0: - raise support.TestError('Should raise SyntaxError #2') - Deleted: trunk/jython/bugtests/test222s.py =================================================================== --- trunk/jython/bugtests/test222s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test222s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -(a, b, c) += 1,2,3 Deleted: trunk/jython/bugtests/test223.py =================================================================== --- trunk/jython/bugtests/test223.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test223.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -try: - import test223s -except SyntaxError: - pass -else: - raise support.TestError('Should raise SyntaxError #1') - -ret = support.compileJPythonc("test223s.py", output="test223.err", - expectError=1) - -if ret == 0: - raise support.TestError('Should raise SyntaxError #2') - Deleted: trunk/jython/bugtests/test223s.py =================================================================== --- trunk/jython/bugtests/test223s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test223s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -a += b += c Deleted: trunk/jython/bugtests/test224.py =================================================================== --- trunk/jython/bugtests/test224.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test224.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,19 +0,0 @@ -""" - -""" - -import support - -try: - import test224s -except SyntaxError: - pass -else: - raise support.TestError('Should raise SyntaxError #1') - -ret = support.compileJPythonc("test224s.py", output="test224.err", - expectError=1) - -if ret == 0: - raise support.TestError('Should raise SyntaxError #2') - Deleted: trunk/jython/bugtests/test224s.py =================================================================== --- trunk/jython/bugtests/test224s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test224s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -[a, b, c] += 1,2,3 Deleted: trunk/jython/bugtests/test225.py =================================================================== --- trunk/jython/bugtests/test225.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test225.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -import test225s Deleted: trunk/jython/bugtests/test225s.py =================================================================== --- trunk/jython/bugtests/test225s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test225s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ - -import support - -def foo(a=1, b=2+4): - return b - -v = foo() - -if v != 6: - raise support.TestError, "Wrong return value %d" % d - Deleted: trunk/jython/bugtests/test226.py =================================================================== --- trunk/jython/bugtests/test226.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test226.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test226c.py", output="test226.err") - -support.runJava("test226c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test226c.py =================================================================== --- trunk/jython/bugtests/test226c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test226c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,20 +0,0 @@ - -cnt = 0 - -def f(i): - global cnt - cnt = cnt + 1 - return i - - -l=[1,2,3,4,5,6] - -l[f(2):f(4)] += ['a', 'b', 'c'] - -if cnt != 2: - raise support.TestError('Number of calls is wrong') - - -if l != [1, 2, 3, 4, 'a', 'b', 'c', 5, 6]: - raise support.TestError('list is wrong') - Deleted: trunk/jython/bugtests/test227.py =================================================================== --- trunk/jython/bugtests/test227.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test227.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test227c.py", output="test227.err") - -support.runJava("test227c", classpath="jpywork", output="test227.out") \ No newline at end of file Deleted: trunk/jython/bugtests/test227c.py =================================================================== --- trunk/jython/bugtests/test227c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test227c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,232 +0,0 @@ - -# Augmented assignment test. - -x = 2 -x += 1 -x *= 2 -x **= 2 -x -= 8 -x /= 2 -x %= 12 -x &= 2 -x |= 5 -x ^= 1 - -print x - -x = [2] -x[0] += 1 -x[0] *= 2 -x[0] **= 2 -x[0] -= 8 -x[0] /= 2 -x[0] %= 12 -x[0] &= 2 -x[0] |= 5 -x[0] ^= 1 - -print x - -x = {0: 2} -x[0] += 1 -x[0] *= 2 -x[0] **= 2 -x[0] -= 8 -x[0] /= 2 -x[0] %= 12 -x[0] &= 2 -x[0] |= 5 -x[0] ^= 1 - -print x[0] - -x = [1,2] -x += [3,4] -x *= 2 - -print x - -x = [1, 2, 3] -y = x -x[1:2] *= 2 -y[1:2] += [1] - -print x -print x is y - -class aug_test: - def __init__(self, value): - self.val = value - def __radd__(self, val): - return self.val + val - def __add__(self, val): - return aug_test(self.val + val) - - -class aug_test2(aug_test): - def __iadd__(self, val): - self.val = self.val + val - return self - -class aug_test3(aug_test): - def __iadd__(self, val): - return aug_test3(self.val + val) - -x = aug_test(1) -y = x -x += 10 - -print isinstance(x, aug_test) -print y is not x -print x.val - -x = aug_test2(2) -y = x -x += 10 - -print y is x -print x.val - -x = aug_test3(3) -y = x -x += 10 - -print isinstance(x, aug_test3) -print y is not x -print x.val - -class testall: - - def __add__(self, val): - print "__add__ called" - def __radd__(self, val): - print "__radd__ called" - def __iadd__(self, val): - print "__iadd__ called" - return self - - def __sub__(self, val): - print "__sub__ called" - def __rsub__(self, val): - print "__rsub__ called" - def __isub__(self, val): - print "__isub__ called" - return self - - def __mul__(self, val): - print "__mul__ called" - def __rmul__(self, val): - print "__rmul__ called" - def __imul__(self, val): - print "__imul__ called" - return self - - def __div__(self, val): - print "__div__ called" - def __rdiv__(self, val): - print "__rdiv__ called" - def __idiv__(self, val): - print "__idiv__ called" - return self - - def __mod__(self, val): - print "__mod__ called" - def __rmod__(self, val): - print "__rmod__ called" - def __imod__(self, val): - print "__imod__ called" - return self - - def __pow__(self, val): - print "__pow__ called" - def __rpow__(self, val): - print "__rpow__ called" - def __ipow__(self, val): - print "__ipow__ called" - return self - - def __or__(self, val): - print "__or__ called" - def __ror__(self, val): - print "__ror__ called" - def __ior__(self, val): - print "__ior__ called" - return self - - def __and__(self, val): - print "__and__ called" - def __rand__(self, val): - print "__rand__ called" - def __iand__(self, val): - print "__iand__ called" - return self - - def __xor__(self, val): - print "__xor__ called" - def __rxor__(self, val): - print "__rxor__ called" - def __ixor__(self, val): - print "__ixor__ called" - return self - - def __rshift__(self, val): - print "__rshift__ called" - def __rrshift__(self, val): - print "__rrshift__ called" - def __irshift__(self, val): - print "__irshift__ called" - return self - - def __lshift__(self, val): - print "__lshift__ called" - def __rlshift__(self, val): - print "__rlshift__ called" - def __ilshift__(self, val): - print "__ilshift__ called" - return self - -x = testall() -x + 1 -1 + x -x += 1 - -x - 1 -1 - x -x -= 1 - -x * 1 -1 * x -x *= 1 - -x / 1 -1 / x -x /= 1 - -x % 1 -1 % x -x %= 1 - -x ** 1 -1 ** x -x **= 1 - -x | 1 -1 | x -x |= 1 - -x & 1 -1 & x -x &= 1 - -x ^ 1 -1 ^ x -x ^= 1 - -x >> 1 -1 >> x -x >>= 1 - -x << 1 -1 << x -x <<= 1 - Deleted: trunk/jython/bugtests/test228.py =================================================================== --- trunk/jython/bugtests/test228.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test228.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -import test228s - -support.compileJPythonc("test228s.py", deep=1, output="test228.err") - -support.runJava("test228s", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test228s.py =================================================================== --- trunk/jython/bugtests/test228s.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test228s.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,26 +0,0 @@ - -from java import util as ut, io, awt as aw, text as te -import java - -import support - -if java.util != ut: - raise support.TestError("util not the same") -if java.awt != aw: - raise support.TestError("awt not the same") -if java.io != io: - raise support.TestError("io not the same") -if java.text != te: - raise support.TestError("text not the same") - - -import java.util.Vector as vec -import java.util.Date as date, java.io.File as file - -if java.util.Vector != vec: - raise support.TestError("Vector not the same") -if java.util.Date != date: - raise support.TestError("Date not the same") -if java.io.File != file: - raise support.TestError("File not the same") - Deleted: trunk/jython/bugtests/test229.py =================================================================== --- trunk/jython/bugtests/test229.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test229.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,8 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test229c.py", output="test229.err") - Deleted: trunk/jython/bugtests/test229c.py =================================================================== --- trunk/jython/bugtests/test229c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test229c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,2 +0,0 @@ - -zeros((3,3))[:,0] Modified: trunk/jython/bugtests/test230.py =================================================================== --- trunk/jython/bugtests/test230.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test230.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -7,8 +7,7 @@ class P: def do_help(self, arg): - pass - #print "do_help", arg + print "do_help", arg #print do_help, id(do_help) def onecmd(self, cmd, arg): Deleted: trunk/jython/bugtests/test231.py =================================================================== --- trunk/jython/bugtests/test231.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test231.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,15 +0,0 @@ - -import support - -support.compileJava("classes/test231j2.java") - -import test231j, test231j2 - -class MyHandler(test231j): - def handleRemove(self, start): - if start != 4294967295L: - raise support.TestError("long not passed correcttly") - -m = MyHandler() - -test231j2.callback(m); Deleted: trunk/jython/bugtests/test232.py =================================================================== --- trunk/jython/bugtests/test232.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test232.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,15 +0,0 @@ -""" -Bug #222847 - Can't access public member of package private base class -""" - -import support - -support.compileJava("classes/test232p/Foo.java") - -from test232p import Foo -try: - Foo().hi() -except IllegalAccessException: - raise support.TestError('Should be able to call public method on package protected superclass') - - Deleted: trunk/jython/bugtests/test233.py =================================================================== --- trunk/jython/bugtests/test233.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test233.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,9 +0,0 @@ - -import support - -try: - from test233s import foobar -except ImportError: - pass -else: - raise support.TestError("Should raise ImportError") Deleted: trunk/jython/bugtests/test234.py =================================================================== --- trunk/jython/bugtests/test234.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test234.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,7 +0,0 @@ -import copy -class X: pass - -x=X() -y=copy.deepcopy(x) - -y=copy.copy(x) Deleted: trunk/jython/bugtests/test237.py =================================================================== --- trunk/jython/bugtests/test237.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test237.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,4 +0,0 @@ -import support - -support.compileJPythonc("test237m2.py", output="test237.err", deep=1) - Deleted: trunk/jython/bugtests/test237m1.py =================================================================== --- trunk/jython/bugtests/test237m1.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test237m1.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,97 +0,0 @@ -from jarray import array - -from javax import swing -from java import awt -from java.beans import PropertyChangeListener - -import java.lang -import string - - -class DlgClick(PropertyChangeListener) : - # - # this delegates propertyChange events - # subclassing and interface extending doesn't seem to work - # properly - # - def __init__(self, delegate) : - self.cb = delegate - - def propertyChange(self, e) : - self.cb(e) - -class UiDialog(swing.JDialog) : - - def __init__(self, widget, title="") : - swing.JDialog.__init__(self, swing.JOptionPane.getFrameForComponent(widget), 1) - - self.setTitle(title) - self.dlg_body = None - self.create_body() - - self.dlg_option_pane = swing.JOptionPane( \ - array(self.dlg_body, java.lang.Object), \ - self.get_type(), \ - self.get_options(), \ - self.get_icon(), \ - self.get_buttons(), \ - self.get_default()) - - self.setContentPane(self.dlg_option_pane) - self.setDefaultCloseOperation(swing.JDialog.DO_NOTHING_ON_CLOSE) - - self.dlg_option_pane.addPropertyChangeListener(DlgClick(self.dlg_click)) - - - self.pack() - self.setResizable(0) - self.show() - - def create_body(self) : - if self.dlg_body is None : - self.dlg_body = ["This is a dialog"] - - def get_type(self) : - return swing.JOptionPane.PLAIN_MESSAGE - - def get_options(self) : - return swing.JOptionPane.OK_CANCEL_OPTION - - def get_icon(self) : - return None - - def get_buttons(self) : - return ["Ok", "Cancel"] - - def get_default(self) : - return self.get_buttons()[0] - - def dlg_click(self, event) : - - prop = event.getPropertyName() - value = self.dlg_option_pane.getValue() - - # don't run after initialisation - if self.isVisible() and (event.getSource() == self.dlg_option_pane) \ - and (prop == swing.JOptionPane.VALUE_PROPERTY or prop == swing.JOptionPane.INPUT_VALUE_PROPERTY) : - - # reset for new input - if value == swing.JOptionPane.UNINITIALIZED_VALUE : - return - - self.dlg_option_pane.setValue(swing.JOptionPane.UNINITIALIZED_VALUE) - - if self.dlg_validate(value) : - self.dlg_make_result(value) - self.dispose() - - def dlg_validate(self, pressed) : - # return whether input is valid depending on pressed button - return 1 - - def dlg_make_result(self, pressed) : - # the result is read afterwards to figure out the outcome of the user input - if pressed == "Ok" : - self.result = 1 - else : - self.result = 0 Deleted: trunk/jython/bugtests/test237m2.py =================================================================== --- trunk/jython/bugtests/test237m2.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test237m2.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,56 +0,0 @@ -import test237m1 -from javax import swing -from java import awt -import string - -class PSetNameDlg(test237m1.UiDialog) : - - def __init__(self, frame, label="Enter a name for the property set:", must_not_exist=1, must_exist=0) : - self.must_exist = must_exist - self.must_not_exist = must_not_exist - self.label_text = label - - test237m1.UiDialog.__init__(self, frame, title="property set name") - - def create_body(self) : - self.ps_name_input = swing.JTextField(10) - self.label_widget = swing.JLabel(self.label_text) - - - if self.dlg_body is None : - self.dlg_body = [self.label_widget, self.ps_name_input] - - - def dlg_validate(self, pressed) : - # check whether the name is correct - if pressed != "Ok" : - return 1 - - name = self.ps_name_input.getText() - - # comment this out for testing - #if len(name) < 1 : - # error = "A reasonbale name should at least have one character." - # test237m1.ErrorMsg(self, error) - # return 0 - #if self.must_not_exist : - # if conf.main.psb.find_property_set(name) is not None : - # error = "There is already a property set with this name." - # test237m1.ErrorMsg(self, error) - # return 0 - #if self.must_exist : - # if conf.main.psb.find_property_set(name) is None : - # error = "There is no property set with this name." - # test237m1.ErrorMsg(self, error) - # return 0 - # comment out until here - - - return 1 - - def dlg_make_result(self, pressed) : - # input value as result or None for cancel - if pressed != "Ok" : - self.result = None - else : - self.result = self.ps_name_input.getText() \ No newline at end of file Deleted: trunk/jython/bugtests/test238.py =================================================================== --- trunk/jython/bugtests/test238.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test238.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,43 +0,0 @@ -""" -Try reloading a javaclass located on sys.path. -""" - -import support -import java -import sys - -def mkspam(a): - f = open("test238p/test238j.java", "w") - f.write(""" -package test238p; -public class test238j { - public static String spam() { return "%s"; } - public static void %s() {} -} -""" % (a, a)) - f.close() - support.compileJava("test238p/test238j.java") - - -mkspam("foo") - -import test238p - -spam1 = test238p.test238j.spam() -support.compare(spam1, "foo") - -mkspam("bar") - -# -# Test removed. Reloading a java package is not supposed to work. -# -#reload(test238p) -#spam1 = test238p.test238j.spam() -#support.compare(spam1, "bar") -# -#mkspam("baz") -# -#reload(test238p) -#spam1 = test238p.test238j.spam() -#support.compare(spam1, "baz") - Deleted: trunk/jython/bugtests/test242.py =================================================================== --- trunk/jython/bugtests/test242.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test242.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -import test242c - -support.compileJPythonc("test242c.py", deep=1, output="test242.err") - -support.runJava("test242c", classpath="jpywork") \ No newline at end of file Deleted: trunk/jython/bugtests/test242c.py =================================================================== --- trunk/jython/bugtests/test242c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test242c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,67 +0,0 @@ - -import support - -# list comprehension tests -nums = [1, 2, 3, 4, 5] -strs = ["Apple", "Banana", "Coconut"] -spcs = [" Apple", " Banana ", "Coco nut "] - -if [s.strip() for s in spcs] != ['Apple', 'Banana', 'Coco nut']: - raise support.TestError, "Wrong value #1" - -if [3 * x for x in nums] != [3, 6, 9, 12, 15]: - raise support.TestError, "Wrong value #2" - -if [x for x in nums if x > 2] != [3, 4, 5]: - raise support.TestError, "Wrong value #3" - -if len([(i, s) for i in nums for s in strs]) != len(nums) * len(strs): - raise support.TestError, "Wrong value #4" - -if [(i, s) for i in nums for s in [f for f in strs if "n" in f]] != [ - (1, 'Banana'), (1, 'Coconut'), (2, 'Banana'), (2, 'Coconut'), - (3, 'Banana'), (3, 'Coconut'), (4, 'Banana'), (4, 'Coconut'), - (5, 'Banana'), (5, 'Coconut')]: - raise support.TestError, "Wrong value #5" - - -try: - eval("[i, s for i in nums for s in strs]") - print "FAIL: should have raised a SyntaxError!" -except SyntaxError: - pass - -try: - eval("[x if y]") - print "FAIL: should have raised a SyntaxError!" -except SyntaxError: - pass - -suppliers = [ - (1, "Boeing"), - (2, "Ford"), - (3, "Macdonalds") -] - -parts = [ - (10, "Airliner"), - (20, "Engine"), - (30, "Cheeseburger") -] - -suppart = [ - (1, 10), (1, 20), (2, 20), (3, 30) -] - -l = [ - (sname, pname) - for (sno, sname) in suppliers - for (pno, pname) in parts - for (sp_sno, sp_pno) in suppart - if sno == sp_sno and pno == sp_pno -] - - -if l != [('Boeing', 'Airliner'), ('Boeing', 'Engine'), - ('Ford', 'Engine'), ('Macdonalds', 'Cheeseburger')]: - raise support.TestError, "Wrong value #6" Deleted: trunk/jython/bugtests/test245.py =================================================================== --- trunk/jython/bugtests/test245.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test245.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,11 +0,0 @@ - - -import support - -support.compileJava("test245j.java") - -#import test245j -#test245j.main([]) - -support.runJava("test245j", classpath=".") - Deleted: trunk/jython/bugtests/test245j.java =================================================================== --- trunk/jython/bugtests/test245j.java 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test245j.java 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,75 +0,0 @@ -import java.util.*; -import org.python.util.PythonInterpreter; -import org.python.core.*; -import java.lang.reflect.*; - -public abstract class test245j { - - public static test245j createPythonScriptClass( - String var[],String script,String name) { - StringTokenizer st=new StringTokenizer(script,"\n\r"); - - StringBuffer scr=new StringBuffer( - "import test245j\n"); - - scr.append("class PySS"); - scr.append(name); - scr.append("(test245j):\n def get(self,variables):\n"); - - for (int i=0;i<var.length;i++) { - scr.append(" "); - scr.append(var[i]); - scr.append("=variables["); - scr.append(i); - scr.append("]\n"); - } - - while (st.hasMoreTokens()) { - scr.append(" "); - scr.append(st.nextToken()); - scr.append("\n"); - } - scr.append(" return "); - scr.append(name); - scr.append("\nrr=PySS"); - scr.append(name); - scr.append("()\n\n"); - - String scriptString=scr.toString(); - -//System.out.println("------------------------\n"+scriptString+"------------------------\n"); - PythonInterpreter interp = new PythonInterpreter(); - interp.exec("import sys"); - interp.exec(scriptString); - - - Object pso = interp.get("rr",Object.class); -// System.out.println("pso class: "+pso.getClass().getName()); -// System.out.println("pso superclass:"+(pso.getClass()).getSuperclass().getName()); -// Method met[]=pso.getClass().getMethods(); -// for(int i=0;i<met.length;i++) -// System.out.println("Met: "+met[i]); - - test245j psc = null; - - psc =(test245j) pso; //<-------------------------------------------------------------------------EXCEPTION -// System.out.println(" psc class: "+psc.getClass().getName()); -// System.out.println(" psc superclass:"+(psc.getClass()).getSuperclass().getName()); - return psc; - } - - public double get(double variable[]) { - return 0.0; - }; - - public static void main(String args[]) throws Exception { - String names[]={"a","b"}; - double variables[]={1.0,2.0}; - String script="c = a + b"; - test245j psc=test245j.createPythonScriptClass(names,script,"c"); - double c=psc.get(variables); - if (c != 3.0) - throw new Exception("Wrong result"); - //System.out.println("C = "+c); - } -} Deleted: trunk/jython/bugtests/test246.py =================================================================== --- trunk/jython/bugtests/test246.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test246.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,35 +0,0 @@ - -import support - -support.compileJava("classes/test246p/test246j.java") - -support.compileJPythonc("test246c.py", package="test246p", output="test246.err") - - -# -# This will fuck up the remaining tests if this test is aborted midways. -# -import sys -sys.path[:0] = ["jpywork"] - -# make the test246 a package. Hmm. -open("jpywork/test246p/__init__.py", "w").close() - -from test246c import testStatic -#from test246p.test246c import testStatic - -v = testStatic.staticMethode('test') -if v != "staticMethode called in testStaticBase": - raise support.TestError, "wrong result #1: %s" % v - -t=testStatic() - -v = t.staticMethode('test') -if v != "staticMethode called in testStaticBase": - raise support.TestError, "wrong result #2: %s" % v - -v = t.notStaticMethode('test') -if v != "notStaticMethode is called in testStatic": - raise support.TestError, "wrong result #3: %s" % v - -del sys.path[0] Deleted: trunk/jython/bugtests/test246c.py =================================================================== --- trunk/jython/bugtests/test246c.py 2008-12-29 01:30:27 UTC (rev 5803) +++ trunk/jython/bugtests/test246c.py 2008-12-29 05:45:42 UTC (rev 5804) @@ -1,13 +0,0 @@ -import java -from test246p import test246j - -class testStatic(test246j): - def __init__(self): - #return "testStatic.__init__ is called" - pass - - def notStaticMethode(self,group): - return "notStaticMethode is called in testStatic" - -def staticMethode(group): - return "staticMethode is called in test246c" Deleted: trunk/jython/bugtests/te... [truncated message content] |
From: <zy...@us...> - 2008-12-29 02:22:09
|
Revision: 5803 http://jython.svn.sourceforge.net/jython/?rev=5803&view=rev Author: zyasoft Date: 2008-12-29 01:30:27 +0000 (Mon, 29 Dec 2008) Log Message: ----------- Supports timeit. Ignore NotImplementedError when attempting to disable gc, along with some rudimentary unit tests extracted from the docs of timeit. Modified Paths: -------------- trunk/jython/Lib/timeit.py Added Paths: ----------- trunk/jython/Lib/test/test_timeit.py Added: trunk/jython/Lib/test/test_timeit.py =================================================================== --- trunk/jython/Lib/test/test_timeit.py (rev 0) +++ trunk/jython/Lib/test/test_timeit.py 2008-12-29 01:30:27 UTC (rev 5803) @@ -0,0 +1,37 @@ +import timeit +import unittest +import test.test_support + +# some uninspired unit tests extracted from the docs for timeit; +# changed number=10000 so we don't spend too much time testing this +# module in the regrtest + +class TestTimeit(unittest.TestCase): + + def test_oct(self): + timing = timeit.Timer('for i in xrange(10): oct(i)', 'gc.enable()').timeit(number=10000) + self.assertTrue(timing > 0.) + timing_vector = timeit.Timer('for i in xrange(10): oct(i)').repeat(number=10000) + self.assertEqual(len(timing_vector), 3) + self.assertTrue(min(timing_vector) > 0.) + + def test_str(self): + s = """\ + try: + str.__nonzero__ + except AttributeError: + pass + """ + t = timeit.Timer(stmt=s) + self.assertTrue(t.timeit(number=10000) > 0.) + + timing_vector = t.repeat(number=10000, repeat=10) + self.assertEqual(len(timing_vector), 10) + self.assertTrue(min(timing_vector) > 0.) + + +def test_main(): + test.test_support.run_unittest(TestTimeit) + +if __name__ == "__main__": + test_main() Modified: trunk/jython/Lib/timeit.py =================================================================== --- trunk/jython/Lib/timeit.py 2008-12-29 01:28:24 UTC (rev 5802) +++ trunk/jython/Lib/timeit.py 2008-12-29 01:30:27 UTC (rev 5803) @@ -157,7 +157,10 @@ else: it = [None] * number gcold = gc.isenabled() - gc.disable() + try: + gc.disable() + except NotImplementedError: + pass # ignore on platforms like Jython timing = self.inner(it, self.timer) if gcold: gc.enable() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2008-12-29 01:28:26
|
Revision: 5802 http://jython.svn.sourceforge.net/jython/?rev=5802&view=rev Author: zyasoft Date: 2008-12-29 01:28:24 +0000 (Mon, 29 Dec 2008) Log Message: ----------- >From http://svn.python.org/projects/python/branches/release25-maint/Lib/timeit.py@35073 Added Paths: ----------- trunk/jython/Lib/timeit.py Added: trunk/jython/Lib/timeit.py =================================================================== --- trunk/jython/Lib/timeit.py (rev 0) +++ trunk/jython/Lib/timeit.py 2008-12-29 01:28:24 UTC (rev 5802) @@ -0,0 +1,285 @@ +#! /usr/bin/env python + +"""Tool for measuring execution time of small code snippets. + +This module avoids a number of common traps for measuring execution +times. See also Tim Peters' introduction to the Algorithms chapter in +the Python Cookbook, published by O'Reilly. + +Library usage: see the Timer class. + +Command line usage: + python timeit.py [-n N] [-r N] [-s S] [-t] [-c] [-h] [statement] + +Options: + -n/--number N: how many times to execute 'statement' (default: see below) + -r/--repeat N: how many times to repeat the timer (default 3) + -s/--setup S: statement to be executed once initially (default 'pass') + -t/--time: use time.time() (default on Unix) + -c/--clock: use time.clock() (default on Windows) + -v/--verbose: print raw timing results; repeat for more digits precision + -h/--help: print this usage message and exit + statement: statement to be timed (default 'pass') + +A multi-line statement may be given by specifying each line as a +separate argument; indented lines are possible by enclosing an +argument in quotes and using leading spaces. Multiple -s options are +treated similarly. + +If -n is not given, a suitable number of loops is calculated by trying +successive powers of 10 until the total time is at least 0.2 seconds. + +The difference in default timer function is because on Windows, +clock() has microsecond granularity but time()'s granularity is 1/60th +of a second; on Unix, clock() has 1/100th of a second granularity and +time() is much more precise. On either platform, the default timer +functions measure wall clock time, not the CPU time. This means that +other processes running on the same computer may interfere with the +timing. The best thing to do when accurate timing is necessary is to +repeat the timing a few times and use the best time. The -r option is +good for this; the default of 3 repetitions is probably enough in most +cases. On Unix, you can use clock() to measure CPU time. + +Note: there is a certain baseline overhead associated with executing a +pass statement. The code here doesn't try to hide it, but you should +be aware of it. The baseline overhead can be measured by invoking the +program without arguments. + +The baseline overhead differs between Python versions! Also, to +fairly compare older Python versions to Python 2.3, you may want to +use python -O for the older versions to avoid timing SET_LINENO +instructions. +""" + +import gc +import sys +import time +try: + import itertools +except ImportError: + # Must be an older Python version (see timeit() below) + itertools = None + +__all__ = ["Timer"] + +dummy_src_name = "<timeit-src>" +default_number = 1000000 +default_repeat = 3 + +if sys.platform == "win32": + # On Windows, the best timer is time.clock() + default_timer = time.clock +else: + # On most other platforms the best timer is time.time() + default_timer = time.time + +# Don't change the indentation of the template; the reindent() calls +# in Timer.__init__() depend on setup being indented 4 spaces and stmt +# being indented 8 spaces. +template = """ +def inner(_it, _timer): + %(setup)s + _t0 = _timer() + for _i in _it: + %(stmt)s + _t1 = _timer() + return _t1 - _t0 +""" + +def reindent(src, indent): + """Helper to reindent a multi-line statement.""" + return src.replace("\n", "\n" + " "*indent) + +class Timer: + """Class for timing execution speed of small code snippets. + + The constructor takes a statement to be timed, an additional + statement used for setup, and a timer function. Both statements + default to 'pass'; the timer function is platform-dependent (see + module doc string). + + To measure the execution time of the first statement, use the + timeit() method. The repeat() method is a convenience to call + timeit() multiple times and return a list of results. + + The statements may contain newlines, as long as they don't contain + multi-line string literals. + """ + + def __init__(self, stmt="pass", setup="pass", timer=default_timer): + """Constructor. See class doc string.""" + self.timer = timer + stmt = reindent(stmt, 8) + setup = reindent(setup, 4) + src = template % {'stmt': stmt, 'setup': setup} + self.src = src # Save for traceback display + code = compile(src, dummy_src_name, "exec") + ns = {} + exec code in globals(), ns + self.inner = ns["inner"] + + def print_exc(self, file=None): + """Helper to print a traceback from the timed code. + + Typical use: + + t = Timer(...) # outside the try/except + try: + t.timeit(...) # or t.repeat(...) + except: + t.print_exc() + + The advantage over the standard traceback is that source lines + in the compiled template will be displayed. + + The optional file argument directs where the traceback is + sent; it defaults to sys.stderr. + """ + import linecache, traceback + linecache.cache[dummy_src_name] = (len(self.src), + None, + self.src.split("\n"), + dummy_src_name) + traceback.print_exc(file=file) + + def timeit(self, number=default_number): + """Time 'number' executions of the main statement. + + To be precise, this executes the setup statement once, and + then returns the time it takes to execute the main statement + a number of times, as a float measured in seconds. The + argument is the number of times through the loop, defaulting + to one million. The main statement, the setup statement and + the timer function to be used are passed to the constructor. + """ + if itertools: + it = itertools.repeat(None, number) + else: + it = [None] * number + gcold = gc.isenabled() + gc.disable() + timing = self.inner(it, self.timer) + if gcold: + gc.enable() + return timing + + def repeat(self, repeat=default_repeat, number=default_number): + """Call timeit() a few times. + + This is a convenience function that calls the timeit() + repeatedly, returning a list of results. The first argument + specifies how many times to call timeit(), defaulting to 3; + the second argument specifies the timer argument, defaulting + to one million. + + Note: it's tempting to calculate mean and standard deviation + from the result vector and report these. However, this is not + very useful. In a typical case, the lowest value gives a + lower bound for how fast your machine can run the given code + snippet; higher values in the result vector are typically not + caused by variability in Python's speed, but by other + processes interfering with your timing accuracy. So the min() + of the result is probably the only number you should be + interested in. After that, you should look at the entire + vector and apply common sense rather than statistics. + """ + r = [] + for i in range(repeat): + t = self.timeit(number) + r.append(t) + return r + +def main(args=None): + """Main program, used when run as a script. + + The optional argument specifies the command line to be parsed, + defaulting to sys.argv[1:]. + + The return value is an exit code to be passed to sys.exit(); it + may be None to indicate success. + + When an exception happens during timing, a traceback is printed to + stderr and the return value is 1. Exceptions at other times + (including the template compilation) are not caught. + """ + if args is None: + args = sys.argv[1:] + import getopt + try: + opts, args = getopt.getopt(args, "n:s:r:tcvh", + ["number=", "setup=", "repeat=", + "time", "clock", "verbose", "help"]) + except getopt.error, err: + print err + print "use -h/--help for command line help" + return 2 + timer = default_timer + stmt = "\n".join(args) or "pass" + number = 0 # auto-determine + setup = [] + repeat = default_repeat + verbose = 0 + precision = 3 + for o, a in opts: + if o in ("-n", "--number"): + number = int(a) + if o in ("-s", "--setup"): + setup.append(a) + if o in ("-r", "--repeat"): + repeat = int(a) + if repeat <= 0: + repeat = 1 + if o in ("-t", "--time"): + timer = time.time + if o in ("-c", "--clock"): + timer = time.clock + if o in ("-v", "--verbose"): + if verbose: + precision += 1 + verbose += 1 + if o in ("-h", "--help"): + print __doc__, + return 0 + setup = "\n".join(setup) or "pass" + # Include the current directory, so that local imports work (sys.path + # contains the directory of this script, rather than the current + # directory) + import os + sys.path.insert(0, os.curdir) + t = Timer(stmt, setup, timer) + if number == 0: + # determine number so that 0.2 <= total time < 2.0 + for i in range(1, 10): + number = 10**i + try: + x = t.timeit(number) + except: + t.print_exc() + return 1 + if verbose: + print "%d loops -> %.*g secs" % (number, precision, x) + if x >= 0.2: + break + try: + r = t.repeat(repeat, number) + except: + t.print_exc() + return 1 + best = min(r) + if verbose: + print "raw times:", " ".join(["%.*g" % (precision, x) for x in r]) + print "%d loops," % number, + usec = best * 1e6 / number + if usec < 1000: + print "best of %d: %.*g usec per loop" % (repeat, precision, usec) + else: + msec = usec / 1000 + if msec < 1000: + print "best of %d: %.*g msec per loop" % (repeat, precision, msec) + else: + sec = msec / 1000 + print "best of %d: %.*g sec per loop" % (repeat, precision, sec) + return None + +if __name__ == "__main__": + sys.exit(main()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-28 17:39:07
|
Revision: 5801 http://jython.svn.sourceforge.net/jython/?rev=5801&view=rev Author: cgroves Date: 2008-12-28 17:39:01 +0000 (Sun, 28 Dec 2008) Log Message: ----------- test132 - Moved to org.python.util. test137 - Tested by test_array_jy test145 - Tested by test_java_integration test146 - Tested by test_java_integration test147 - Tested by test_builtin test148 - Tested by test_str test149 - Moved to test_int_jy test150 - Moved to test_java_visibility test151 - Not sure what it was testing; deleted test152 - Tested by regrtest with the tokenize option test153 - Tested by test_java_integration test154 - Not sure what it was testing; deleted test155 - Subclassing Java Python Types as that class from Python is no longer supported; deleted test156 - Tested by test_jser2 test157 - Moved to test_java_visibility test158 - Tested by test_userdict test159 - Tested by test_exceptions test160 - Seems to be testing Java static calling; deleted test161 - Moved to test_java_visibility test162 - Moved Jython specific test to test_class_jy test163 - Module tests handled by test_class_jy; Java test moved to test_java_visibility test164,test165 - Tested by test_str test166 - Tested by test_exceptions test167 - Moved to test_thread_jy test168 - Tested by test_import test169 - Testing jythonc; deleted test170,test171 - Tested by test_cpickle test172 - Moved to test_java_visibility test173 - Tested by test_builtins test174 - Tested by test_classes test175,test176 - Tested by test_list test177 - Tested by test_userdict test178 - Moved to test_grammar_jy test179 - Tested by test_compiler test180 - Tested by test_builtin test181 - Moved to test_grammar_jy test182 - Testing jythonc; deleted test183 - Tested by test_re test184-199 - Testing jythonc; deleted test200 - Tested by test_java_integration test201 - Testing jythonc; deleted test202,203 - Tested by test_jser2 test204,205 - Moved to test_java_visibility test206 - Tested by test_java_integration Modified Paths: -------------- trunk/jython/Lib/test/test_class_jy.py trunk/jython/Lib/test/test_grammar_jy.py trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/Lib/test/test_thread_jy.py trunk/jython/tests/java/org/python/tests/Coercions.java trunk/jython/tests/java/org/python/tests/SubVisible.java trunk/jython/tests/java/org/python/tests/VisibilityResults.java trunk/jython/tests/java/org/python/tests/Visible.java trunk/jython/tests/java/org/python/util/InterpreterTest.java Added Paths: ----------- trunk/jython/Lib/test/test_int_jy.py Removed Paths: ------------- trunk/jython/bugtests/classes/test139j1.java trunk/jython/bugtests/classes/test139j2.java trunk/jython/bugtests/classes/test139j3.java trunk/jython/bugtests/classes/test142j.java trunk/jython/bugtests/classes/test160j1.java trunk/jython/bugtests/classes/test160j2.java trunk/jython/bugtests/classes/test182j.java trunk/jython/bugtests/classes/test202j.java trunk/jython/bugtests/classes/test204j0.java trunk/jython/bugtests/classes/test204j1.java trunk/jython/bugtests/classes/test204j2.java trunk/jython/bugtests/classes/test204j3.java trunk/jython/bugtests/classes/test205j0.java trunk/jython/bugtests/classes/test205j1.java trunk/jython/bugtests/classes/test205j2.java trunk/jython/bugtests/classes/test206j0.java trunk/jython/bugtests/classes/test206j1.java trunk/jython/bugtests/test132.py trunk/jython/bugtests/test132j.java trunk/jython/bugtests/test132m.py trunk/jython/bugtests/test137.py trunk/jython/bugtests/test137j.java trunk/jython/bugtests/test145.py trunk/jython/bugtests/test146.py trunk/jython/bugtests/test147.py trunk/jython/bugtests/test148.py trunk/jython/bugtests/test149.py trunk/jython/bugtests/test150.py trunk/jython/bugtests/test151.py trunk/jython/bugtests/test152.py trunk/jython/bugtests/test153.py trunk/jython/bugtests/test154.py trunk/jython/bugtests/test154p/ trunk/jython/bugtests/test155.py trunk/jython/bugtests/test156.py trunk/jython/bugtests/test157.py trunk/jython/bugtests/test157j.java trunk/jython/bugtests/test158.py trunk/jython/bugtests/test159.py trunk/jython/bugtests/test160.py trunk/jython/bugtests/test161.py trunk/jython/bugtests/test162.py trunk/jython/bugtests/test162m.py trunk/jython/bugtests/test163.py trunk/jython/bugtests/test164.py trunk/jython/bugtests/test165.py trunk/jython/bugtests/test166.py trunk/jython/bugtests/test167.py trunk/jython/bugtests/test168.py trunk/jython/bugtests/test168p/ trunk/jython/bugtests/test169.py trunk/jython/bugtests/test169c.py trunk/jython/bugtests/test170.py trunk/jython/bugtests/test170p/ trunk/jython/bugtests/test171.py trunk/jython/bugtests/test171p/ trunk/jython/bugtests/test172.py trunk/jython/bugtests/test172j.java trunk/jython/bugtests/test173.py trunk/jython/bugtests/test173p/ trunk/jython/bugtests/test174.py trunk/jython/bugtests/test175.py trunk/jython/bugtests/test176.py trunk/jython/bugtests/test177.py trunk/jython/bugtests/test178.py trunk/jython/bugtests/test179.py trunk/jython/bugtests/test180.py trunk/jython/bugtests/test181.py trunk/jython/bugtests/test182.py trunk/jython/bugtests/test182c.py trunk/jython/bugtests/test183.py trunk/jython/bugtests/test184.py trunk/jython/bugtests/test184s1.py trunk/jython/bugtests/test184s2.py trunk/jython/bugtests/test185.html trunk/jython/bugtests/test185.py trunk/jython/bugtests/test185a.py trunk/jython/bugtests/test185m.py trunk/jython/bugtests/test186.html trunk/jython/bugtests/test186.py trunk/jython/bugtests/test186a.py trunk/jython/bugtests/test187.py trunk/jython/bugtests/test187c.py trunk/jython/bugtests/test188.py trunk/jython/bugtests/test188c.py trunk/jython/bugtests/test189.py trunk/jython/bugtests/test189c.py trunk/jython/bugtests/test190.py trunk/jython/bugtests/test190c.py trunk/jython/bugtests/test191.py trunk/jython/bugtests/test191c.py trunk/jython/bugtests/test192.html trunk/jython/bugtests/test192.py trunk/jython/bugtests/test192c.py trunk/jython/bugtests/test192c1.py trunk/jython/bugtests/test192c2.py trunk/jython/bugtests/test193.py trunk/jython/bugtests/test193c.py trunk/jython/bugtests/test194.html trunk/jython/bugtests/test194.py trunk/jython/bugtests/test194c.py trunk/jython/bugtests/test194m/ trunk/jython/bugtests/test195.py trunk/jython/bugtests/test195c.py trunk/jython/bugtests/test196.py trunk/jython/bugtests/test196c.py trunk/jython/bugtests/test197.py trunk/jython/bugtests/test197c.py trunk/jython/bugtests/test198.py trunk/jython/bugtests/test198c.py trunk/jython/bugtests/test199.py trunk/jython/bugtests/test199c.py trunk/jython/bugtests/test200.py trunk/jython/bugtests/test200p1.py trunk/jython/bugtests/test201.py trunk/jython/bugtests/test201c.py trunk/jython/bugtests/test202.py trunk/jython/bugtests/test203.py trunk/jython/bugtests/test204.py trunk/jython/bugtests/test205.py trunk/jython/bugtests/test206.py Modified: trunk/jython/Lib/test/test_class_jy.py =================================================================== --- trunk/jython/Lib/test/test_class_jy.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_class_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -6,6 +6,7 @@ import __builtin__ import new import unittest +from java.lang import Object from test import test_support class ClassGeneralTestCase(unittest.TestCase): @@ -24,11 +25,14 @@ class Bar(object): pass - self.assertEqual(Bar.__module__, __name__) - self.assertEqual(str(Bar), "<class '%s.Bar'>" % __name__) - self.assertEqual(repr(Bar), "<class '%s.Bar'>" % __name__) - bar = Bar() - self.assert_(str(bar).startswith('<%s.Bar object at' % __name__)) + class Baz(Object): + pass + for cls in Bar, Baz: + self.assertEqual(cls.__module__, __name__) + self.assertEqual(str(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) + self.assertEqual(repr(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) + self.assert_(str(Bar()).startswith('<%s.Bar object at' % __name__)) + self.assert_(str(Baz()).startswith("org.python.proxies.%s$Baz" % __name__)) def test_builtin_attributes(self): Modified: trunk/jython/Lib/test/test_grammar_jy.py =================================================================== --- trunk/jython/Lib/test/test_grammar_jy.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_grammar_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -5,7 +5,19 @@ import unittest class GrammarTest(unittest.TestCase): + def test_triple_quote_len(self): + s1 = r""" + \""" 1.triple-quote + \""" 2.triple-quote + """ + s2 = r''' + \""" 1.triple-quote + \""" 2.triple-quote + ''' + self.assert_(not '\r' in s1) + self.assertEquals(len(s1), len(s2)) + def testStringPrefixes(self): self.assertEquals(u"spam",U"spam") self.assertEquals(r"spam", R"spam") Added: trunk/jython/Lib/test/test_int_jy.py =================================================================== --- trunk/jython/Lib/test/test_int_jy.py (rev 0) +++ trunk/jython/Lib/test/test_int_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -0,0 +1,18 @@ +"""Int tests + +Additional tests for Jython. +""" +import unittest +import types +from test import test_support + +class IntTestCase(unittest.TestCase): + + def test_type_matches(self): + self.assert_(isinstance(1, types.IntType)) + +def test_main(): + test_support.run_unittest(IntTestCase) + +if __name__ == '__main__': + test_main() Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -4,8 +4,7 @@ import re from test import test_support -from java.awt import (Dimension, Component, Rectangle, Button, Color, - HeadlessException) +from java.awt import Dimension, Color, Component, Rectangle from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter @@ -95,7 +94,6 @@ class ExtendJavaTest(unittest.TestCase): def test_override_tostring(self): - from java.lang import Object, String class A(Object): def toString(self): return 'name' @@ -109,8 +107,6 @@ except TypeError: pass - - class SysIntegrationTest(unittest.TestCase): def test_stdout_outputstream(self): out = FileOutputStream(test_support.TESTFN) @@ -124,7 +120,6 @@ sys.stdout = out class AutoSuperTest(unittest.TestCase): - def test_auto_super(self): class R(Rectangle): def __init__(self): @@ -142,7 +137,6 @@ self.assertRaises(TypeError, Math) class PyObjectCmpTest(unittest.TestCase): - def test_vect_cmp(self): "Check comparing a PyJavaClass with a Object." class X(Runnable): @@ -169,7 +163,6 @@ class VectorTest(unittest.TestCase): - def test_looping(self): for i in Vector(): pass @@ -432,12 +425,10 @@ self.fail("Shouldn't be callable with a no args") self.assertRaises(TypeError, Callbacker.callNoArg, PyBadCallback()) - class JavaStringTest(unittest.TestCase): def test_string_not_iterable(self): - from java import lang - x = lang.String('test') + x = String('test') self.assertRaises(TypeError, list, x) class JavaDelegationTest(unittest.TestCase): Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +1,10 @@ +import array import unittest from test import test_support -from java.util import HashMap -from org.python.tests import (InterfaceCombination, Invisible, OnlySubclassable, SubVisible, - Visible, VisibleOverride) +from java.lang import Class +from java.util import HashMap, Observable, Observer +from org.python.tests import (Coercions, InterfaceCombination, Invisible, OnlySubclassable, + SubVisible, Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -21,14 +23,17 @@ Visible.__init__(self, publicValue) else: Visible.__init__(self) + class SubSubVisible(SubVisible): + pass # TODO - protectedStaticMethod, protectedStaticField, StaticInner, and protectedField should # be here - s = SubVisible() - self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) - self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) - self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) - self.assertRaises(TypeError, OnlySubclassable, - "Calling a Java class with protected constructors should raise a TypeError") + for cls in SubVisible, SubSubVisible: + s = cls() + self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) + self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) + self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) + self.assertRaises(TypeError, OnlySubclassable, + "Calling a Java class with protected constructors should raise a TypeError") class SubSubclassable(OnlySubclassable): pass sub = SubSubclassable() @@ -36,7 +41,26 @@ '''Creating SubSubclassable should call OnlySubclassable's constructor to fill in filledInByConstructor''') + # Check that the protected setChanged method on Observable is visible and propogates + # properly from a python subclass + class TestObservable(Observable): + def __init__(self): + self.props = {} + def set(self, key, val): + self.props[key] = val + self.setChanged() + self.notifyObservers() + to = TestObservable() + self.updated = False + class TestObserver(Observer): + def update(observerself, observable, arg): + self.assertEquals(to, observable) + self.assertEquals(None, arg) + self.updated = True + to.addObserver(TestObserver()) + to.set('k', 'v') + self.assert_(self.updated, "Calling set should notify the added observer") def test_visible(self): v = Visible() @@ -74,6 +98,11 @@ # return the subclass value here. self.assertEquals(Results.SUBCLASS_OVERRIDE, Visible.visibleInstance(s, 3)) self.assertEquals(Results.PUBLIC_STATIC_FIELD, SubVisible.StaticInner.visibleStaticField) + + self.assertEquals(Results.VISIBLE_SHARED_NAME_FIELD, Visible.sharedNameField) + self.assertEquals(Results.SUBVISIBLE_SHARED_NAME_FIELD, SubVisible.sharedNameField) + self.assertEquals(Results.VISIBLE_SHARED_NAME_FIELD * 10, Visible().sharedNameField) + self.assertEquals(Results.SUBVISIBLE_SHARED_NAME_FIELD * 10, s.sharedNameField) def test_in_dict(self): @@ -104,14 +133,25 @@ 'java.lang.Class bean methods should be visible on instances') self.assertEquals(3, len(HashMap.getInterfaces())) + def test_python_fields(self): + self.assertEquals('java.util', HashMap.__module__) + self.assertEquals(Class, HashMap.__class__) + self.assertEquals(None, HashMap.__doc__) + class NumberCoercionTest(unittest.TestCase): def test_int_coercion(self): - from org.python.tests import Coercions c = Coercions() self.assertEquals("5", c.takeInt(5)) self.assertEquals("15", c.takeInteger(15)) self.assertEquals("150", c.takeNumber(150)) + def test_array_coercion(self): + self.assertEquals("double", Coercions.takeArray(array.zeros('d', 2))) + self.assertEquals("float", Coercions.takeArray(array.zeros('f', 2))) + self.assertEquals("4", Coercions.takePyObj(1, 2, 3, 4)) + c = Coercions() + self.assertEquals("5", c.takePyObjInst(1, 2, 3, 4, 5)) + def test_main(): test_support.run_unittest(VisibilityTest, JavaClassTest, Modified: trunk/jython/Lib/test/test_thread_jy.py =================================================================== --- trunk/jython/Lib/test/test_thread_jy.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/Lib/test/test_thread_jy.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +1,9 @@ import thread +import synchronize import unittest import test.test_support +from java.lang import Thread +from java.util.concurrent import CountDownLatch class AllocateLockTest(unittest.TestCase): @@ -10,8 +13,23 @@ self.assertEquals(t, type(thread.allocate_lock()), "thread.LockType has wrong value") +class SynchronizeTest(unittest.TestCase): + def test_make_synchronized(self): + self.doneSignal = CountDownLatch(10) + self.i = 0 + class SynchedRun(Thread): + def run(synchself): + self.i = self.i + 1 + self.doneSignal.countDown() + run = synchronize.make_synchronized(run) + for _ in xrange(10): + SynchedRun().start() + self.doneSignal.await() + self.assertEquals(10, self.i) + + def test_main(): - test.test_support.run_unittest(AllocateLockTest) + test.test_support.run_unittest(AllocateLockTest, SynchronizeTest) if __name__ == "__main__": test_main() Deleted: trunk/jython/bugtests/classes/test139j1.java =================================================================== --- trunk/jython/bugtests/classes/test139j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test139j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public class test139j1 { - public void foo() {} -} Deleted: trunk/jython/bugtests/classes/test139j2.java =================================================================== --- trunk/jython/bugtests/classes/test139j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test139j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public interface test139j2 { - public void bar(); -} Deleted: trunk/jython/bugtests/classes/test139j3.java =================================================================== --- trunk/jython/bugtests/classes/test139j3.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test139j3.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -public class test139j3 { - public static boolean baz(test139j1 o) { - return o instanceof test139j2; - } -} Deleted: trunk/jython/bugtests/classes/test142j.java =================================================================== --- trunk/jython/bugtests/classes/test142j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test142j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,27 +0,0 @@ - -import org.python.core.*; - -public class test142j extends PyObject { - double[] data; - int len; - public test142j(double[] darray) { - data=darray; - len=data.length; - } - public int __len__() { - return len; - } - - public PyString __repr__() { - StringBuffer buf = new StringBuffer(); - for(int i=0; i<len; i++) { - buf.append(data[i]); - buf.append(", "); - } - return new PyString(buf.toString()); - } - - public static test142j new$(double[] array) { - return new test142j(array); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test160j1.java =================================================================== --- trunk/jython/bugtests/classes/test160j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test160j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,18 +0,0 @@ - -public class test160j1 { - public static test160j1 clField; - - public void go() { - clField = this; - test160j2 b = new test160j2(); - } - - public String func() { - return "success!"; - } - - public static void main( String[] arg ) { - test160j1 a = new test160j1(); - a.go(); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test160j2.java =================================================================== --- trunk/jython/bugtests/classes/test160j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test160j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -public class test160j2 { - public test160j2() { - test160j1.clField.func(); - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test182j.java =================================================================== --- trunk/jython/bugtests/classes/test182j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test182j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,46 +0,0 @@ - -public abstract class test182j { - public String tstPublic() { - return "tstPublic"; - } - - protected String tstProtected() { - return "tstProtected"; - } - - final protected String tstFinalProtected() { - return "tstFinalProtected"; - } - - final public String tstFinalPublic() { - return "tstFinalPublic"; - } - - - - public String tstOverridePublic() { - return "tstOverridePublic"; - } - - protected String tstOverrideProtected() { - return "tstOverrideProtected"; - } - - final protected String tstOverrideFinalProtected() { - return "tstOverrideFinalProtected"; - } - - final public String tstOverrideFinalPublic() { - return "tstOverrideFinalPublic"; - } - - - abstract public String tstAbstractPublic(); - - abstract protected String tstAbstractProtected(); - - abstract public String tstOverrideAbstractPublic(); - - abstract protected String tstOverrideAbstractProtected(); - -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test202j.java =================================================================== --- trunk/jython/bugtests/classes/test202j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test202j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,5 +0,0 @@ - - -public class test202j implements java.io.Serializable { - public int a = 1; -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test204j0.java =================================================================== --- trunk/jython/bugtests/classes/test204j0.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j0.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public interface test204j0 { - public long getClassID(); -} Deleted: trunk/jython/bugtests/classes/test204j1.java =================================================================== --- trunk/jython/bugtests/classes/test204j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test204j1 implements test204j0 { - public static final long classID = 2041; - - public long getClassID() { - return classID*2; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test204j2.java =================================================================== --- trunk/jython/bugtests/classes/test204j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test204j2 extends test204j1 { - public static final long classID = 2042; - - public long getClassID() { - return classID*2; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test204j3.java =================================================================== --- trunk/jython/bugtests/classes/test204j3.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test204j3.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test204j3 extends test204j1 { - public static final long classID = 2043; - - public long getClassID() { - return classID*2; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test205j0.java =================================================================== --- trunk/jython/bugtests/classes/test205j0.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test205j0.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -public interface test205j0 { - public long getClassID(); -} Deleted: trunk/jython/bugtests/classes/test205j1.java =================================================================== --- trunk/jython/bugtests/classes/test205j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test205j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ - -public class test205j1 implements test205j0 { - public static final long classID = 2051; - - public long getClassID() { - return classID*10; - } - -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test205j2.java =================================================================== --- trunk/jython/bugtests/classes/test205j2.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test205j2.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test205j2 extends test205j1 { - public static final long classID = 2052; - - public long getClassID() { - return classID*10; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/classes/test206j0.java =================================================================== --- trunk/jython/bugtests/classes/test206j0.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test206j0.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,4 +0,0 @@ - -interface test206j0 { - public int getInt(); -} Deleted: trunk/jython/bugtests/classes/test206j1.java =================================================================== --- trunk/jython/bugtests/classes/test206j1.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/classes/test206j1.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ - -public class test206j1 implements test206j0 { - public int getInt() { - return 3; - } - public int getInt2() { - return 4; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test132.py =================================================================== --- trunk/jython/bugtests/test132.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test132.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test132j.java") - -import test132j -test132j.main(None) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test132j.java =================================================================== --- trunk/jython/bugtests/test132j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test132j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -import org.python.core.*; -import org.python.util.PythonInterpreter; - -public class test132j { - public static void main(String[] args) { - PythonInterpreter interp = new PythonInterpreter(); - interp.execfile("test132m.py"); - PyObject FooClass = interp.get("Foo"); - PyObject fooInstance = FooClass.__call__(new PyInteger(42)); - for (int i=0; i<4; i++) { - fooInstance.invoke("execute"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test132m.py =================================================================== --- trunk/jython/bugtests/test132m.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test132m.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,7 +0,0 @@ - -class Foo: - def __init__(self, x): - self.x = x - - def execute(self): - return self.x \ No newline at end of file Deleted: trunk/jython/bugtests/test137.py =================================================================== --- trunk/jython/bugtests/test137.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test137.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,17 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test137j.java") - -import jarray -a = jarray.array(range(5), 'i') - -import test137j - - -test137j.zeroOutArray(a) -if a[-1] != 0: - raise support.TestError("All elements should be 0") Deleted: trunk/jython/bugtests/test137j.java =================================================================== --- trunk/jython/bugtests/test137j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test137j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ - -public class test137j { - public static void zeroOutArray(int [] array){ - for(int i=0; i < array.length; i++){ - array[i] = 0; - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test145.py =================================================================== --- trunk/jython/bugtests/test145.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test145.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" -Check autocreate of proxy. -""" - -import support - -import java - -class myPanel(java.awt.Panel) : - def __init__(self) : - self.layout = java.awt.GridLayout(1,2) - -p = myPanel() -if p.layout != p.getLayout(): - raise support.TestError("Should be same") Deleted: trunk/jython/bugtests/test146.py =================================================================== --- trunk/jython/bugtests/test146.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test146.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,16 +0,0 @@ -""" - -""" - -import support - -from javax.swing import * -class TestAction(AbstractAction): - def __init__(self, verb): - AbstractAction.__init__(self, verb) - def actionPerformed(self, evt): - print str(self.getValue(Action.NAME)) + " performed by " + str(self) - -m = TestAction("Crash") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test147.py =================================================================== --- trunk/jython/bugtests/test147.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test147.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ -""" - -""" - -import support - -if 'abc' is 'a'+'b'+'c': - raise support.TestError("Test1") -if not intern('abc') is intern('a'+'b'+'c'): - raise support.TestError("Test2") - Deleted: trunk/jython/bugtests/test148.py =================================================================== --- trunk/jython/bugtests/test148.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test148.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -import string -support.compare(string.replace("Synnove Finden Meierier ASA", "AS", "B"), "Synnove Finden Meierier BA") - Deleted: trunk/jython/bugtests/test149.py =================================================================== --- trunk/jython/bugtests/test149.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test149.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -from types import * -if not isinstance(1, IntType): - raise support.TestError("Test") Deleted: trunk/jython/bugtests/test150.py =================================================================== --- trunk/jython/bugtests/test150.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test150.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,27 +0,0 @@ -""" -setChanged was not found. -""" - -import support - -from java.util import Observable -class TestProperties( Observable ): - def __init__( self ): - self.props = { - 'logFileDir' : "./", - 'logFileName' : "testLog.txt", - 'maxFailures' : 1, - } - - def get( self, name ): - return self.props[ name ] - - def set( self, name, value ): - self.props[ name ] = value - self.notifyObservers() - self.setChanged() - -t = TestProperties() -t.set("k", "v") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test151.py =================================================================== --- trunk/jython/bugtests/test151.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test151.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - -class Test: - def method1( self ): - __local = "buttercup" - __local - - -Test().method1() - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test152.py =================================================================== --- trunk/jython/bugtests/test152.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test152.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,24 +0,0 @@ -""" - -""" - -import support - -import tokenize - -f = open("test152.out", "w") -f.write("for i in range(1,10):") -f.close() - -f = open("test152.out") - -s = "" -def gettoken(type, token, (srow, scol), (erow, ecol), line): # for testing - global s - s = s + " " + token - -r = tokenize.tokenize(f.readline, gettoken) - -support.compare(s, "for") - -#raise support.TestError("Should raise") Deleted: trunk/jython/bugtests/test153.py =================================================================== --- trunk/jython/bugtests/test153.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test153.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -""" - -""" - -import support - -from java.util import Hashtable -class Test(Hashtable): - def isEmpty(self): - return Hashtable.isEmpty(self) - -t = Test() -if not t.isEmpty(): - raise support.TestError("Should be empty") Deleted: trunk/jython/bugtests/test154.py =================================================================== --- trunk/jython/bugtests/test154.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test154.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -""" - -""" - -import support - -import test154p -from test154p.testing import testing - -reload(test154p.testing) -reload(test154p.testing) -reload(test154p.testing) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test155.py =================================================================== --- trunk/jython/bugtests/test155.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test155.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,20 +0,0 @@ -""" - -""" - -import support - -#raise support.TestError("Test removed, it destroyes the test environment") - - -from org.python.core import PyList -class Test2(PyList): - def foo(self): - return self[0] - -y = Test2() -y.append('spam') -v = y.foo() - -if v != "spam": - raise support.TestError("Should return 'spam' : " + `v`) Deleted: trunk/jython/bugtests/test156.py =================================================================== --- trunk/jython/bugtests/test156.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test156.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,36 +0,0 @@ -""" -#unitcheck -""" - -import support - -import sys, org -from java import io -from java.awt import Panel - -class MyPanel (Panel): - pass - -def serialize_object (obj, filename): - #print "serializing", obj, "to", filename - file = io.FileOutputStream (filename) - objstream = io.ObjectOutputStream (file) - objstream.writeObject (obj) - objstream.close() ; file.close() - #print "done" - -def unserialize_object (filename): - #print "reading serialized object from", filename - file = io.FileInputStream (filename) - objstream = org.python.util.PythonObjectInputStream (file) - obj = objstream.readObject () - objstream.close() ; file.close() - #print "unserialized", obj - -filename = 'test156.ser' - -p = MyPanel () -serialize_object (p, filename) -unserialize_object (filename) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test157.py =================================================================== --- trunk/jython/bugtests/test157.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test157.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,22 +0,0 @@ -""" - -""" - -import support - -support.compileJava("test157j.java") - -import test157j - -from jarray import * -f = zeros(2,'d'); -support.compare(test157j.test(f), "double"); -if f[0] == 0: - raise support.TestError("array not changed") - - -f = zeros(2,'f'); -support.compare(test157j.test(f), "float"); -if f[0] == 0: - raise support.TestError("array not changed") - Deleted: trunk/jython/bugtests/test157j.java =================================================================== --- trunk/jython/bugtests/test157j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test157j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - -public class test157j { - public static String test(double[] arr) { - arr[0]=100; - return "double"; - } - public static String test(float[] arr) { - arr[0]=100; - return "float"; - } -} Deleted: trunk/jython/bugtests/test158.py =================================================================== --- trunk/jython/bugtests/test158.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test158.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,14 +0,0 @@ -""" - -""" - -import support - -alfa = {} -alfa["test"] = "test1" -try: - del alfa["beta"] -except KeyError, e: - pass -else: - raise support.TestError("Should raise") Deleted: trunk/jython/bugtests/test159.py =================================================================== --- trunk/jython/bugtests/test159.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test159.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -try: - raise RuntimeError -except RuntimeError: - pass -else: - raise support.TestError("Should raise") Deleted: trunk/jython/bugtests/test160.py =================================================================== --- trunk/jython/bugtests/test160.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test160.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,13 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test160j1.java") - -import test160j1 -a = test160j1() -a.go() - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test161.py =================================================================== --- trunk/jython/bugtests/test161.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test161.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - -from javax import swing -class a(swing.JPanel): - pass - -class b(a): - pass - - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test162.py =================================================================== --- trunk/jython/bugtests/test162.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test162.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -import test162m -support.compare(test162m.ParentlessClass.__module__, "test162m") -support.compare(test162m.DerivedPyClass.__module__, "test162m") -support.compare(test162m.DerivedJClass.__module__, "test162m") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test162m.py =================================================================== --- trunk/jython/bugtests/test162m.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test162m.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - -import java, java.lang - -class ParentlessClass: - pass - -class DerivedPyClass(ParentlessClass): - pass - -class DerivedJClass(java.lang.Object): - pass \ No newline at end of file Deleted: trunk/jython/bugtests/test163.py =================================================================== --- trunk/jython/bugtests/test163.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test163.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,28 +0,0 @@ -""" - -""" - -import support - -from java.lang import Object - -class A: - pass - -class B(A): - pass - -class C(Object): - pass - -class D: - pass - -support.compare(A.__module__, "__main__|test163") -support.compare(B.__module__, "__main__|test163") -support.compare(C.__module__, "__main__|test163") -support.compare(D.__module__, "__main__|test163") -if hasattr(Object, "__module__"): - raise support.TestError("a java object should not have a __module__") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test164.py =================================================================== --- trunk/jython/bugtests/test164.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test164.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -import string -support.compare(string.replace ("2. .. 3.", ". .", " ."), "2 \.\. 3\.") - - Deleted: trunk/jython/bugtests/test165.py =================================================================== --- trunk/jython/bugtests/test165.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test165.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compare("%g" % 1, "1") -support.compare("%g .. %g" % (1,2), "1 .. 2") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test166.py =================================================================== --- trunk/jython/bugtests/test166.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test166.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,13 +0,0 @@ -""" - -""" - -import support - -try: - raise KeyError, "abc" -except KeyError, value: - support.compare(value, "abc") - support.compare(value.__class__, "exceptions.KeyError") - - Deleted: trunk/jython/bugtests/test167.py =================================================================== --- trunk/jython/bugtests/test167.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test167.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - - -from java import lang -import synchronize - -class test167(lang.Thread): - def run(self): pass - run = synchronize.make_synchronized(run) - -test167().start() \ No newline at end of file Deleted: trunk/jython/bugtests/test168.py =================================================================== --- trunk/jython/bugtests/test168.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test168.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,7 +0,0 @@ - -import test168p - -import support - -support.compare(test168p.foo(), "foo") -support.compare(test168p.bar.bar(), "bar") Deleted: trunk/jython/bugtests/test169.py =================================================================== --- trunk/jython/bugtests/test169.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test169.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test169c.py", core=1, jar="test169c.jar", output="test169.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test169c.py =================================================================== --- trunk/jython/bugtests/test169c.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test169c.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - -#import urllib - -a = None -if string.split('abc'): - a = "abc" - -if a: - import base64 - -import base64 \ No newline at end of file Deleted: trunk/jython/bugtests/test170.py =================================================================== --- trunk/jython/bugtests/test170.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test170.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,24 +0,0 @@ -""" - -""" - -import support - -import cPickle, cStringIO - -#print cPickle.__version__ - -import test170p.Stack - -s = test170p.Stack.Stack() - -#print s - -cs = cStringIO.StringIO() - -cPickle.dump(s, cs) -#print cs.getvalue() -cs.seek(0) -cPickle.load(cs) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test171.py =================================================================== --- trunk/jython/bugtests/test171.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test171.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" - -""" - -import support - -import cPickle - -import test171p.Stack - -s = test171p.Stack.Stack() - -cPickle.dumps(s) - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test172.py =================================================================== --- trunk/jython/bugtests/test172.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test172.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,11 +0,0 @@ - - -import support - -support.compileJava("test172j.java") - -import test172j - -support.compare(test172j.foo(1,2,3,4), "foo called with 4 arguments") - -support.compare(test172j().bar(1,2,3,4), "bar called with 4 arguments") Deleted: trunk/jython/bugtests/test172j.java =================================================================== --- trunk/jython/bugtests/test172j.java 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test172j.java 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ - -import org.python.core.*; - -public class test172j { - public static String foo(PyObject[] args) { - return "foo called with " + args.length + " arguments"; - } - - public String bar(PyObject[] args) { - return "bar called with " + args.length + " arguments"; - } -} Deleted: trunk/jython/bugtests/test173.py =================================================================== --- trunk/jython/bugtests/test173.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test173.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -import support - - -import test173p -support.compare(test173p, "sys") \ No newline at end of file Deleted: trunk/jython/bugtests/test174.py =================================================================== --- trunk/jython/bugtests/test174.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test174.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,21 +0,0 @@ - -import support - -class A: - def foo(self): - return "A.foo" - -class B: - def foo(self): - return "B.foo" - -class C(A, B): - pass - - -list(C.__bases__).reverse() - - -c = C() -#print c.foo -support.compare(c.foo(), "A.foo") Deleted: trunk/jython/bugtests/test175.py =================================================================== --- trunk/jython/bugtests/test175.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test175.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,6 +0,0 @@ - -import support - -t = (1,2,3) -list(t).reverse() -support.compare(t, "1, 2, 3") Deleted: trunk/jython/bugtests/test176.py =================================================================== --- trunk/jython/bugtests/test176.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test176.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,13 +0,0 @@ -""" -Check that a list based on a tuple can not change the tuple -""" - -import support - -t1 = (1,2,3) -t2 = (1,2,3) -list(t1).reverse() - -if t1 != t2: - raise support.TestError('tuple was modified.') - Deleted: trunk/jython/bugtests/test177.py =================================================================== --- trunk/jython/bugtests/test177.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test177.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" -Check that two equal, but diffrently sorted dict compare equal. -""" - -import support - -d1 = {'status':1, 'background':2, 'borderwidth':3, 'foreground':4} -d2 = {'status':1, 'background':2, 'foreground':4, 'borderwidth':3} - -if d1 != d2: - raise support.TestError('equal dicts does not compare equal.') - Deleted: trunk/jython/bugtests/test178.py =================================================================== --- trunk/jython/bugtests/test178.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test178.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,20 +0,0 @@ - -import support - -s1 = r""" - \""" 1.triple-quote - \""" 2.triple-quote -""" - -s2 = r''' - \""" 1.triple-quote - \""" 2.triple-quote -''' - - -for i in range(len(s2)): - if s1[i] != s2[i]: print "diff at", i - - -if s1 != s2: - raise support.TestError, "TQS different" \ No newline at end of file Deleted: trunk/jython/bugtests/test179.py =================================================================== --- trunk/jython/bugtests/test179.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test179.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,22 +0,0 @@ -""" - The traceback linenumber does not match the throw line. -""" -import support - -def foo(): - assert 0 - -try: - try: - - - foo() - - - - finally: - pass -except: - import sys - info = sys.exc_info() - support.compare(info[2].tb_lineno, "13") Deleted: trunk/jython/bugtests/test180.py =================================================================== --- trunk/jython/bugtests/test180.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test180.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,18 +0,0 @@ -""" - -""" - -import support - - -class A: - def __init__(self): - self.foo = 'bar' - -def f(*args, **kw): - #print args, kw - support.compare(args, "(1, 2, 3)") - support.compare(kw, "{'foo': 'bar'}") - -apply(f, (1,2,3), A().__dict__) - Deleted: trunk/jython/bugtests/test181.py =================================================================== --- trunk/jython/bugtests/test181.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test181.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,15 +0,0 @@ -""" -Test TQS -""" - -import support - -s1 = r""" - \""" 1.triple-quote - \""" 2.triple-quote -""" - -import string - -if '\r' in s1: - raise support.TestError, "TQS should not contain CR" \ No newline at end of file Deleted: trunk/jython/bugtests/test182.py =================================================================== --- trunk/jython/bugtests/test182.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test182.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,12 +0,0 @@ -""" - -""" - -import support - -support.compileJava("classes/test182j.java") - -support.compileJPythonc("test182c.py", core=1, jar="test182c.jar", output="test182.err") -support.runJava("test182c", classpath="test182c.jar") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test182c.py =================================================================== --- trunk/jython/bugtests/test182c.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test182c.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,38 +0,0 @@ - -import support - -import test182j - -class test182c(test182j): - def tstOverridePublic(self): - #print "her1" - return "test182c." + test182j.tstOverridePublic(self) - def tstOverrideProtected(self): - #print "her2" - return "test182c." + self.super__tstOverrideProtected() - def tstOverrideFinalProtected(self): - return "test182c." + self.super__tstOverrideFinalProtected() - def tstOverrideFinalPublic(self): - return "test182c." + test182j.tstOverrideFinalPublic(self) - - def tstAbstractPublic(self): - return "test182c.tstAbstractPublic" - def tstAbstractProtected(self): - return "test182c.tstAbstractProtected" - -i = test182c() - -support.compare(i.tstPublic(), "tstPublic") -support.compare(i.tstProtected(), "tstProtected") -support.compare(i.super__tstFinalProtected(), "tstFinalProtected") -support.compare(i.tstFinalPublic(), "tstFinalPublic") - - -support.compare(i.tstOverridePublic(), "test182c.tstOverridePublic") -support.compare(i.tstOverrideProtected(), "test182c.tstOverrideProtected") -support.compare(i.tstOverrideFinalProtected(), "test182c.tstOverrideFinalProtected") -support.compare(i.tstOverrideFinalPublic(), "test182c.tstOverrideFinalPublic") - - -support.compare(i.tstAbstractPublic(), "test182c.tstAbstractPublic") -support.compare(i.tstAbstractProtected(), "test182c.tstAbstractProtected") Deleted: trunk/jython/bugtests/test183.py =================================================================== --- trunk/jython/bugtests/test183.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test183.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,19 +0,0 @@ -""" -Test the re.M flag. Fails when using re. Success with sre. -""" - -import support - -import re - -var ="T\nO" - -m = re.search("^O",var,re.M) -if m == None: - raise support.TestError("Should match") - - -m = re.search("^O",var) -if m != None: - raise support.TestError("Should not match") - Deleted: trunk/jython/bugtests/test184.py =================================================================== --- trunk/jython/bugtests/test184.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test184.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test184s1.py", "test184s2.py", deep=1, output="test184.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test184s1.py =================================================================== --- trunk/jython/bugtests/test184s1.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test184s1.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,16 +0,0 @@ - -from javax.servlet.http import HttpServlet - -import test184p - -class test184s1(HttpServlet): - def doGet(self, request, response): - response.setContentType("text/html") - out = response.getOutputStream() - out.println("<html>") - out.println("<head> <title> JPython test184s1 servlet </title></head>") - out.println("<body> <h2> Hello World! JPython %s </h2> </body>" % test184p.foo()) - out.println(" </html>") - - -print test184s1, Exception Deleted: trunk/jython/bugtests/test184s2.py =================================================================== --- trunk/jython/bugtests/test184s2.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test184s2.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,17 +0,0 @@ - -from javax.servlet.http import * - -import test184p - - -class test184s2(HttpServlet): - def doGet(self, request, response): - response.setContentType("text/html") - out = response.getOutputStream() - out.println("<html>") - out.println("<head> <title> JPython test184s2 servlet </title></head>") - out.println("<body> <h2> Hello World! JPython %s </h2> </body>" % test184p.foo()) - out.println(" </html>") - - -print test184s2, ServletConfig Deleted: trunk/jython/bugtests/test185.html =================================================================== --- trunk/jython/bugtests/test185.html 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185.html 2008-12-28 17:39:01 UTC (rev 5801) @@ -1 +0,0 @@ -<applet code="test185a" archive="test185.jar" width=300 height=200></applet> \ No newline at end of file Deleted: trunk/jython/bugtests/test185.py =================================================================== --- trunk/jython/bugtests/test185.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,9 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test185a.py", core=1, jar="test185.jar", output="test185.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test185a.py =================================================================== --- trunk/jython/bugtests/test185a.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185a.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,20 +0,0 @@ -from java.awt import Frame -from java.applet import Applet -from test185m import * - -class test185a(Applet): - def __init__(self): - self.mydd = dd() - self.add(self.mydd) - - -class foo: - pass - -class bar(foo): - pass - -if __name__ == "__main__": - f = Frame(); c = c() - f.add(c); f.pack(); f.show() - Deleted: trunk/jython/bugtests/test185m.py =================================================================== --- trunk/jython/bugtests/test185m.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test185m.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,7 +0,0 @@ - -from java.awt import * - -class dd(Panel): - def __init__(self): - self.add(Label("Running")) - \ No newline at end of file Deleted: trunk/jython/bugtests/test186.html =================================================================== --- trunk/jython/bugtests/test186.html 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test186.html 2008-12-28 17:39:01 UTC (rev 5801) @@ -1 +0,0 @@ -<applet code="com.mycompany.mypackage.test186a" archive="test186.jar" width=300 height=200></applet> \ No newline at end of file Deleted: trunk/jython/bugtests/test186.py =================================================================== --- trunk/jython/bugtests/test186.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test186.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,10 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test186a.py", core=1, package="com.mycompany.mypackage", - jar="test186.jar", output="test186.err") - -#raise support.TestError("" + `x`) Deleted: trunk/jython/bugtests/test186a.py =================================================================== --- trunk/jython/bugtests/test186a.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test186a.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,17 +0,0 @@ -import java - -# Define a Python class that subclasses the Applet class -# (java.applet.Applet) - -class test186a (java.applet.Applet): - def __init__(self): - self.list = java.awt.List() - self.add(self.list) - def init(self): - self.list.add("Init called") - def destroy(self): - self.list.add("Destroy called") - def start(self): - self.list.add("Start called") - def stop(self): - self.list.add("Stop called") Deleted: trunk/jython/bugtests/test187.py =================================================================== --- trunk/jython/bugtests/test187.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test187.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,8 +0,0 @@ -""" - -""" - -import support - -support.compileJPythonc("test187c.py", output="test187.err") - Deleted: trunk/jython/bugtests/test187c.py =================================================================== --- trunk/jython/bugtests/test187c.py 2008-12-25 15:30:20 UTC (rev 5800) +++ trunk/jython/bugtests/test187c.py 2008-12-28 17:39:01 UTC (rev 5801) @@ -1,40 +0,0 @@ - -def a1(): - if a: - return 22 - else: - return 10 - print "abc" - - -def a2(): - if a: - return 22 - else: - return 10 - return None - - -def a3(): - """docstring""" - if a: - return 22 - else: - return 10 - 5 - -def a4(): - """docstring""" - a = 1 - raise "Error", 1 - b... [truncated message content] |
From: <cg...@us...> - 2008-12-25 15:30:22
|
Revision: 5800 http://jython.svn.sourceforge.net/jython/?rev=5800&view=rev Author: cgroves Date: 2008-12-25 15:30:20 +0000 (Thu, 25 Dec 2008) Log Message: ----------- test_117,119,120 - Tested by test_jser2 test_121 - Moved to test_java_visibility test_122 - Testing java package reloading that never worked test_123 - Moved to org.python.util.InterpreterTest test_129 - Tested by test_array_jy Modified Paths: -------------- trunk/jython/Lib/test/test_array_jy.py trunk/jython/Lib/test/test_java_visibility.py trunk/jython/tests/java/org/python/tests/Invisible.java trunk/jython/tests/java/org/python/tests/SubVisible.java trunk/jython/tests/java/org/python/util/InterpreterTest.java Added Paths: ----------- trunk/jython/tests/java/org/python/tests/OnlySubclassable.java Removed Paths: ------------- trunk/jython/bugtests/classes/test092m/ trunk/jython/bugtests/classes/test119j.java trunk/jython/bugtests/classes/test121p/ trunk/jython/bugtests/test117.py trunk/jython/bugtests/test117j.java trunk/jython/bugtests/test119.py trunk/jython/bugtests/test120.py trunk/jython/bugtests/test121.py trunk/jython/bugtests/test122.py trunk/jython/bugtests/test122p/ trunk/jython/bugtests/test123.py trunk/jython/bugtests/test123j.java trunk/jython/bugtests/test125m.py trunk/jython/bugtests/test129.py trunk/jython/bugtests/test129j.java Modified: trunk/jython/Lib/test/test_array_jy.py =================================================================== --- trunk/jython/Lib/test/test_array_jy.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/Lib/test/test_array_jy.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -28,20 +28,20 @@ (jStringArr.typecode, str(String))) self.assertEqual(zeros(String, 5), Array.newInstance(String, 5)) - import java # require for eval to work + import java.lang.String # require for eval to work self.assertEqual(jStringArr, eval(str(jStringArr))) def test_java_compat(self): - from java import awt - hsb = awt.Color.RGBtoHSB(0,255,255, None) + from java.awt import Color + hsb = Color.RGBtoHSB(0,255,255, None) self.assertEqual(hsb, array('f', [0.5,1,1]), "output hsb float array does not correspond to input rgb values") - rgb = apply(awt.Color.HSBtoRGB, tuple(hsb)) + rgb = apply(Color.HSBtoRGB, tuple(hsb)) self.assertEqual(rgb, -0xff0001, "output rgb bytes don't match input hsb floats") hsb1 = zeros('f', 3) - awt.Color.RGBtoHSB(0,255,255, hsb1) + Color.RGBtoHSB(0, 255, 255, hsb1) self.assertEqual(hsb, hsb1, "hsb float arrays were not equal") def test_main(): Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,7 +1,8 @@ import unittest from test import test_support from java.util import HashMap -from org.python.tests import InterfaceCombination, Invisible, SubVisible, Visible, VisibleOverride +from org.python.tests import (InterfaceCombination, Invisible, OnlySubclassable, SubVisible, + Visible, VisibleOverride) from org.python.tests import VisibilityResults as Results class VisibilityTest(unittest.TestCase): @@ -10,6 +11,8 @@ self.assert_(not item.startswith("package")) self.assert_(not item.startswith("private")) self.assert_(not item.startswith("protected")) + self.assertRaises(TypeError, Invisible, + "Calling a Java class with package protected constructors should raise a TypeError") def test_protected_from_python_subclass(self): class SubVisible(Visible): @@ -24,7 +27,17 @@ self.assertEquals(Results.PROTECTED_METHOD, s.protectedMethod(0)) self.assertEquals(Results.OVERLOADED_PROTECTED_METHOD, s.protectedMethod('foo')) self.assertEquals(Results.UNUSED, SubVisible(Results.UNUSED).visibleField) + self.assertRaises(TypeError, OnlySubclassable, + "Calling a Java class with protected constructors should raise a TypeError") + class SubSubclassable(OnlySubclassable): + pass + sub = SubSubclassable() + self.assert_(not sub.filledInByConstructor == 0, + '''Creating SubSubclassable should call OnlySubclassable's constructor to fill in + filledInByConstructor''') + + def test_visible(self): v = Visible() self.assertEquals(Results.PUBLIC_FIELD, v.visibleField) Deleted: trunk/jython/bugtests/classes/test119j.java =================================================================== --- trunk/jython/bugtests/classes/test119j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/classes/test119j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,5 +0,0 @@ - - -public class test119j implements java.io.Serializable { - public int a = 1; -} \ No newline at end of file Deleted: trunk/jython/bugtests/test117.py =================================================================== --- trunk/jython/bugtests/test117.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test117.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,41 +0,0 @@ -""" -Check serialization of PyJavaInstance subclasses. (from Lib). -#unitcheck -""" - -import support - -support.compileJava("test117j.java") - -import java, org -pi = java.io.PipedInputStream() -po = java.io.PipedOutputStream(pi) -oo = java.io.ObjectOutputStream(po) -oi = org.python.util.PythonObjectInputStream(pi) - -import test117j - -class B: - b = 2 - -class C(test117j): - c = 3 - -foo = test117j() -oo.writeObject(foo) -bar = oi.readObject() -#print type(foo), type(bar) -#print foo.__class__, bar.__class__ -if bar.a != 1: - raise support.TestError("Restored attrib should be 1") - -oo.writeObject(B()) -x = oi.readObject() -if x.b != 2: - raise support.TestError("Restored attrib should be 2") - -oo.writeObject(C()) -x = oi.readObject() -if x.c != 3: - raise support.TestError("Restored attrib should be 3") - Deleted: trunk/jython/bugtests/test117j.java =================================================================== --- trunk/jython/bugtests/test117j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test117j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,6 +0,0 @@ - -import java.io.*; - -public class test117j implements java.io.Serializable { - public int a = 1; -} \ No newline at end of file Deleted: trunk/jython/bugtests/test119.py =================================================================== --- trunk/jython/bugtests/test119.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test119.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,35 +0,0 @@ -""" -Check serialization of PyJavaInstance subclasses. (from classpath). -#unitcheck -""" - -import support - -support.compileJava("classes/test119j.java") - -import java, org -pi = java.io.PipedInputStream() -po = java.io.PipedOutputStream(pi) -oo = java.io.ObjectOutputStream(po) -oi = org.python.util.PythonObjectInputStream(pi) - -import test119j - -class B: - b = 2 - -class C(test119j): - c = 3 - -oo.writeObject(test119j()) -if oi.readObject().a != 1: - raise support.TestError("Deser of java class failed") - - -oo.writeObject(B()) -if oi.readObject().b != 2: - raise support.TestError("Deser of python class failed") - -oo.writeObject(C()) -if oi.readObject().c != 3: - raise support.TestError("Deser of java subclass class failed") Deleted: trunk/jython/bugtests/test120.py =================================================================== --- trunk/jython/bugtests/test120.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test120.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,20 +0,0 @@ -""" -Check serialization of java subclasses. -#unitcheck -""" - -import support - -import java, org - -class V(java.util.Vector): - foo = 1 - -#print java.io.ObjectStreamClass.lookup(V); - -oo = java.io.ObjectOutputStream(java.io.FileOutputStream("test120.out")) -oo.writeObject(V()) - -oi = org.python.util.PythonObjectInputStream(java.io.FileInputStream("test120.out")) -o = oi.readObject() -#print o Deleted: trunk/jython/bugtests/test121.py =================================================================== --- trunk/jython/bugtests/test121.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test121.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,16 +0,0 @@ -""" -Check nonpublic constructor. -""" - -import support - -support.compileJava("classes/test121p/test121j.java") - -from test121p import test121j - -try: - test121j() -except TypeError, e: - support.compare(e, "no public constructor") -else: - raise support.TestError("Should fail (access)") Deleted: trunk/jython/bugtests/test122.py =================================================================== --- trunk/jython/bugtests/test122.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test122.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,33 +0,0 @@ -""" -Should reloading a python module cause java classes to be reloaded? -""" - -import support -src= """ -package test122p; -public class test122j { - public String version = "%s"; -} -""" - -def mk(v): - f = open("test122p/test122j.java", "w") - f.write(src % v) - f.close() - support.compileJava("test122p/test122j.java") - -mk(1) - -import test122p -bar1 = test122p.test122j() -if bar1.version != "1": - raise support.TestError("Wrong version#1 %s" % bar1.version) - -# -# Test removed. Reloading java packages are not supposed to work. -# -#mk(2) -#reload(test122p) -#bar2 = test122p.test122j() -#if bar2.version != "2": -# raise support.TestError("Wrong version#2 %s" % bar2.version) Deleted: trunk/jython/bugtests/test123.py =================================================================== --- trunk/jython/bugtests/test123.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test123.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,14 +0,0 @@ - -""" - -""" - -import support - -support.compileJava("test123j.java") - -import test123j - -test123j.main(None) - - Deleted: trunk/jython/bugtests/test123j.java =================================================================== --- trunk/jython/bugtests/test123j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test123j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,24 +0,0 @@ - -import org.python.util.PythonInterpreter; -import org.python.core.*; - -public class test123j { - public static void main(String args[]) { - for(int i=0; i<10; i++) { - PyThread p1 = new PyThread(); - Thread t1 = new Thread(p1); - t1.start(); - } - } - - public static class PyThread implements Runnable { - public void run() { - PythonInterpreter interp = new PythonInterpreter(); - interp.exec("import sys"); - interp.set("a", new PyInteger(41)); - //interp.exec("print a"); - interp.exec("x = 2+2"); - PyObject x = interp.get("x"); - } - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test125m.py =================================================================== --- trunk/jython/bugtests/test125m.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test125m.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,3 +0,0 @@ - -def fun2(): - return 2 Deleted: trunk/jython/bugtests/test129.py =================================================================== --- trunk/jython/bugtests/test129.py 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test129.py 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,18 +0,0 @@ -""" - -""" - -import support -import java, jarray - -support.compileJava("test129j.java") - -arr = jarray.zeros(10, java.lang.Class.forName('[I')) -for x in range(10): arr[x] = jarray.zeros(10, 'i') - -import test129j - -test129j.chk(arr) - -if arr[0][0] != 47: - raise support.TestError("Array[0][0] should be 47: %d" % arr[0][0]) Deleted: trunk/jython/bugtests/test129j.java =================================================================== --- trunk/jython/bugtests/test129j.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/bugtests/test129j.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,7 +0,0 @@ - -public class test129j { - public static int chk(int[][] arr) { - arr[0][0] = 47; - return arr.length * arr[0].length; - } -} \ No newline at end of file Modified: trunk/jython/tests/java/org/python/tests/Invisible.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Invisible.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/tests/java/org/python/tests/Invisible.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -18,6 +18,8 @@ int packageField = PACKAGE_FIELD; + Invisible() {} + private static int privateStaticMethod() { return 7; } Added: trunk/jython/tests/java/org/python/tests/OnlySubclassable.java =================================================================== --- trunk/jython/tests/java/org/python/tests/OnlySubclassable.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/OnlySubclassable.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -0,0 +1,10 @@ +package org.python.tests; + +public class OnlySubclassable { + + public int filledInByConstructor; + + protected OnlySubclassable() { + filledInByConstructor = 1; + } +} Modified: trunk/jython/tests/java/org/python/tests/SubVisible.java =================================================================== --- trunk/jython/tests/java/org/python/tests/SubVisible.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/tests/java/org/python/tests/SubVisible.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,7 +1,6 @@ package org.python.tests; public class SubVisible extends Visible implements VisibleOverride { - /** * Overrides {@link Visible#visibleStatic(int)} */ Modified: trunk/jython/tests/java/org/python/util/InterpreterTest.java =================================================================== --- trunk/jython/tests/java/org/python/util/InterpreterTest.java 2008-12-25 00:49:33 UTC (rev 5799) +++ trunk/jython/tests/java/org/python/util/InterpreterTest.java 2008-12-25 15:30:20 UTC (rev 5800) @@ -1,8 +1,11 @@ package org.python.util; +import java.util.concurrent.CountDownLatch; import junit.framework.TestCase; +import org.python.core.Py; import org.python.core.PyDictionary; +import org.python.core.PyInteger; import org.python.core.PyObject; import org.python.core.PyUnicode; @@ -19,4 +22,28 @@ PyObject pyo = interp.eval("{u'one': u'two'}"); assertEquals(test, pyo); } + + public void testMultipleThreads() { + final CountDownLatch doneSignal = new CountDownLatch(10); + for (int i = 0; i < 10; i++) { + new Thread() { + @Override + public void run() { + PythonInterpreter interp = new PythonInterpreter(); + interp.exec("import sys"); + interp.set("a", new PyInteger(41)); + int set = Py.tojava(interp.get("a"), Integer.class); + assertEquals(41, set); + interp.exec("x = 'hello ' + 'goodbye'"); + assertEquals("hello goodbye", Py.tojava(interp.get("x"), String.class)); + doneSignal.countDown(); + } + }.start(); + } + try { + doneSignal.await(); + } catch (InterruptedException e) { + System.err.println("Interpreters in multiple threads test interrupted, bailing"); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-25 00:49:37
|
Revision: 5799 http://jython.svn.sourceforge.net/jython/?rev=5799&view=rev Author: cgroves Date: 2008-12-25 00:49:33 +0000 (Thu, 25 Dec 2008) Log Message: ----------- test_091 - moved to test_java_visibility.py test_092 - deleted; not testing anything test_093 - deleted; check of a jythonc hack test_094 - deleted; tested by test_import_jy test_100 - deleted; tested by test_userdict test_101 - deleted; tested by test_jser2 test_104 - moved to test_java_integration.py test_114 - deleted; testing importing Tkinter from someone's i:\ drive test_116 - moved to test_java_integration.py Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py trunk/jython/Lib/test/test_java_visibility.py Added Paths: ----------- trunk/jython/tests/java/org/python/tests/Coercions.java Removed Paths: ------------- trunk/jython/bugtests/test091.py trunk/jython/bugtests/test091j.java trunk/jython/bugtests/test092.py trunk/jython/bugtests/test093.py trunk/jython/bugtests/test094.py trunk/jython/bugtests/test100.py trunk/jython/bugtests/test100j.java trunk/jython/bugtests/test101.py trunk/jython/bugtests/test104.py trunk/jython/bugtests/test114.py trunk/jython/bugtests/test116.py Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -5,11 +5,13 @@ from test import test_support from java.awt import (Dimension, Component, Rectangle, Button, Color, - HeadlessException) + HeadlessException) from java.util import ArrayList, HashMap, Hashtable, StringTokenizer, Vector from java.io import FileOutputStream, FileWriter, OutputStreamWriter -from java.lang import Runnable, Thread, ThreadGroup, System, Runtime, Math, Byte +from java.lang import (Boolean, Integer, Object, String, Runnable, + Thread, ThreadGroup, System, Runtime, Math, Byte) +from javax.swing.table import AbstractTableModel from javax.swing.tree import TreePath from java.math import BigDecimal @@ -150,22 +152,22 @@ v.indexOf(X()) class IOTest(unittest.TestCase): - def test_io_errors(self): "Check that IOException isn't mangled into an IOError" from java.io import UnsupportedEncodingException - self.assertRaises(UnsupportedEncodingException, OutputStreamWriter, - System.out, "garbage") - + self.assertRaises(UnsupportedEncodingException, OutputStreamWriter, System.out, "garbage") + self.assertRaises(IOError, OutputStreamWriter, System.out, "garbage") + def test_fileio_error(self): from java.io import FileInputStream, FileNotFoundException self.assertRaises(FileNotFoundException, FileInputStream, "garbage") - def test_unsupported(self): + def test_unsupported_tell(self): from org.python.core.util import FileUtil fp = FileUtil.wrap(System.out) self.assertRaises(IOError, fp.tell) + class VectorTest(unittest.TestCase): def test_looping(self): @@ -354,7 +356,34 @@ treePath = TreePath([1,2,3]) self.assertEquals(len(treePath.path), 3, "Object[] not passed correctly") self.assertEquals(TreePath(treePath.path).path, treePath.path, "Object[] not passed and returned correctly") - + +class TableModelTest(unittest.TestCase): + def test_column_classes(self): + class TableModel(AbstractTableModel): + columnNames = "First Name", "Last Name","Sport","# of Years","Vegetarian" + data = [("Mary", "Campione", "Snowboarding", 5, False)] + + def getColumnCount(self): + return len(self.columnNames) + + def getRowCount(self): + return len(self.data) + + def getColumnName(self, col): + return self.columnNames[col] + + def getValueAt(self, row, col): + return self.data[row][col] + + def getColumnClass(self, c): + return Object.getClass(self.getValueAt(0, c)) + + def isCellEditable(self, row, col): + return col >= 2 + model = TableModel() + for i, expectedClass in enumerate([String, String, String, Integer, Boolean]): + self.assertEquals(expectedClass, model.getColumnClass(i)) + class BigDecimalTest(unittest.TestCase): def test_coerced_bigdecimal(self): @@ -460,6 +489,7 @@ PyReservedNamesTest, ImportTest, ColorTest, + TableModelTest, TreePathTest, BigDecimalTest, MethodInvTest, Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -91,9 +91,18 @@ 'java.lang.Class bean methods should be visible on instances') self.assertEquals(3, len(HashMap.getInterfaces())) +class NumberCoercionTest(unittest.TestCase): + def test_int_coercion(self): + from org.python.tests import Coercions + c = Coercions() + self.assertEquals("5", c.takeInt(5)) + self.assertEquals("15", c.takeInteger(15)) + self.assertEquals("150", c.takeNumber(150)) + def test_main(): test_support.run_unittest(VisibilityTest, - JavaClassTest) + JavaClassTest, + NumberCoercionTest) if __name__ == "__main__": test_main() Deleted: trunk/jython/bugtests/test091.py =================================================================== --- trunk/jython/bugtests/test091.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test091.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,18 +0,0 @@ -""" -Coercion of Integer and Number. -""" - -import support - -support.compileJava("test091j.java") - -import test091j - -r = test091j.takeInt(12) -support.compare(r, "takeInt") - -r = test091j.takeInteger(12) -support.compare(r, "takeInteger") - -r = test091j.takeNumber(12) -support.compare(r, "takeNumber") Deleted: trunk/jython/bugtests/test091j.java =================================================================== --- trunk/jython/bugtests/test091j.java 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test091j.java 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,11 +0,0 @@ -public class test091j { - public static String takeInt(int num) { - return "takeInt"; - } - public static String takeInteger(Integer num) { - return "takeInteger"; - } - public static String takeNumber(Number num) { - return "takeNumber"; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test092.py =================================================================== --- trunk/jython/bugtests/test092.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test092.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,64 +0,0 @@ -""" -Check reload a java package (not a java class) (properly shouldn't work). -""" - -import support - -j1file = """ -package test092m; -public class test092j1 { - final static String j1_Version = "j1 Version %s"; - public String getJ1Version() { - return j1_Version; - } -} -""" - -j2file = """ -package test092m; -public class test092j2 extends test092j1 { - final static String j2_Version = "j2 Version %s"; - public String getJ2Version() { - return j2_Version; - } -} -""" - -def mkj1(v): - f = open("classes/test092m/test092j1.java", "w") - f.write(j1file % v) - f.close() - support.compileJava("classes/test092m/test092j1.java") - -def mkj2(v): - f = open("classes/test092m/test092j2.java", "w") - f.write(j2file % v); - f.close(); - support.compileJava("classes/test092m/test092j2.java") - -import sys - -mkj1("1") -mkj2("2") - -import test092m - -foo = test092m.test092j2() - -support.compare(foo.j1Version, "j1 Version 1") -support.compare(foo.j2Version, "j2 Version 2") - -mkj1("3") -mkj2("4") - -# -# Removed. Reloading java packages is not supposed to work -# -#reload(test092m) -# -#foo = test092m.test092j2() -#support.compare(foo.j1Version, "j1 Version 3") -#support.compare(foo.j2Version, "j2 Version 4") - - - Deleted: trunk/jython/bugtests/test093.py =================================================================== --- trunk/jython/bugtests/test093.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test093.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,14 +0,0 @@ -""" -Check name of the pawt.swing package. -""" - -import support - -from pawt import swing - - -support.compare(swing, "java package") -support.compare(swing.__name__, "javax.swing") -support.compare(swing.__jpythonc_name__, "pawt.swing") -#support.compare(swing.__file__, r"Lib\\pawt\\swing.py") - Deleted: trunk/jython/bugtests/test094.py =================================================================== --- trunk/jython/bugtests/test094.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test094.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,13 +0,0 @@ -""" -Check simple __import__ call with 4 args. -""" - -import support - -mod = __import__("pawt", globals(), locals(), "swing") - -import pawt - -if pawt != mod: - raise support.TestError("__import__ returned wrong module") - Deleted: trunk/jython/bugtests/test100.py =================================================================== --- trunk/jython/bugtests/test100.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test100.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,14 +0,0 @@ -""" -Iterate over the "keys" sequence. -""" - -import support - -support.compileJava("test100j.java") - -import test100j - -r = test100j().iterate({'a':'1', 'b':'2', 3:'c'}) - -if len(r) != 6: - raise support.TestError("len should be 6, %d" % len(r)) Deleted: trunk/jython/bugtests/test100j.java =================================================================== --- trunk/jython/bugtests/test100j.java 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test100j.java 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,16 +0,0 @@ - -import java.util.*; -import org.python.core.*; - -public class test100j { - public Vector iterate(PyObject dict) { - Vector v = new Vector(); - PyObject keys = dict.invoke("keys"); - PyObject key; - for (int i = 0; (key = keys.__finditem__(i)) != null; i++) { - v.addElement(key); - v.addElement(dict.__getitem__(key)); - } - return v; - } -} Deleted: trunk/jython/bugtests/test101.py =================================================================== --- trunk/jython/bugtests/test101.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test101.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,41 +0,0 @@ -""" -Serialization test. -#unitcheck -""" - -import support - - -class Data: - data = "Hello World" - -class Test: - text = Data() - -class Factory: - def createTest(x): - return Test() - -factory = Factory() -foo = factory.createTest() - - -from java import io -import sys - -filename = "test101.out" - -fout = io.ObjectOutputStream(io.FileOutputStream(filename)) -fout.writeObject(foo) -fout.close() - -fin = io.ObjectInputStream(io.FileInputStream(filename)) -foo = fin.readObject() -fin.close() - - -support.compare(foo, "<(__main__|test101).Test instance") -support.compare(foo.text, "<(__main__|test101).Data instance") -support.compare(foo.text.data, "Hello World") - - Deleted: trunk/jython/bugtests/test104.py =================================================================== --- trunk/jython/bugtests/test104.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test104.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,38 +0,0 @@ -""" - -""" - -import support - - -import java -from pawt import swing, test - -class TableModel0(swing.table.AbstractTableModel): - columnNames = "First Name", "Last Name","Sport","# of Years","Vegetarian" - data = [("Mary", "Campione", "Snowboarding", 5, java.lang.Boolean(0))] - - def getColumnCount(self): - return len(self.columnNames) - - def getRowCount(self): - return len(self.data) - - def getColumnName(self, col): - return self.columnNames[col] - - def getValueAt(self, row, col): - return self.data[row][col] - - def getColumnClass(self, c): - return java.lang.Class.getClass(self.getValueAt(0, c)) - - def isCellEditable(self, row, col): - return col >= 2 - -model0 = TableModel0() -support.compare(model0.getColumnClass(0), "java.lang.String") -support.compare(model0.getColumnClass(1), "java.lang.String") -support.compare(model0.getColumnClass(2), "java.lang.String") -support.compare(model0.getColumnClass(3), "java.lang.Integer") -support.compare(model0.getColumnClass(4), "java.lang.Boolean") Deleted: trunk/jython/bugtests/test114.py =================================================================== --- trunk/jython/bugtests/test114.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test114.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,14 +0,0 @@ -""" -Check sane error when importing TKinter. -""" - -import support - - -import sys -sys.path.append(r"i:\Python-1.5.2\Lib\lib-tk") - -try: - from Tkinter import * -except ImportError, e: - support.compare(e, "_tkinter|Tkinter") Deleted: trunk/jython/bugtests/test116.py =================================================================== --- trunk/jython/bugtests/test116.py 2008-12-25 00:05:29 UTC (rev 5798) +++ trunk/jython/bugtests/test116.py 2008-12-25 00:49:33 UTC (rev 5799) @@ -1,23 +0,0 @@ -""" -Check that UEE also matches IOError. -""" - -import support - - -import java - -try: - x = java.io.OutputStreamWriter(java.lang.System.out, "garbage") -except java.io.UnsupportedEncodingException, e: - pass -else: - raise support.TestError("Should raise an exception") - - -try: - x = java.io.OutputStreamWriter(java.lang.System.out, "garbage") -except IOError, e: - pass -else: - raise support.TestError("Should raise an exception") Added: trunk/jython/tests/java/org/python/tests/Coercions.java =================================================================== --- trunk/jython/tests/java/org/python/tests/Coercions.java (rev 0) +++ trunk/jython/tests/java/org/python/tests/Coercions.java 2008-12-25 00:49:33 UTC (rev 5799) @@ -0,0 +1,16 @@ +package org.python.tests; + +public class Coercions { + + public String takeInt(int i) { + return "" + i; + } + + public String takeInteger(Integer i) { + return "" + i; + } + + public String takeNumber(Number n) { + return "" + n; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-25 00:05:36
|
Revision: 5798 http://jython.svn.sourceforge.net/jython/?rev=5798&view=rev Author: cgroves Date: 2008-12-25 00:05:29 +0000 (Thu, 25 Dec 2008) Log Message: ----------- Check that java.lang.Class methods are visible on Java class instances Modified Paths: -------------- trunk/jython/Lib/test/test_java_visibility.py Modified: trunk/jython/Lib/test/test_java_visibility.py =================================================================== --- trunk/jython/Lib/test/test_java_visibility.py 2008-12-24 22:57:21 UTC (rev 5797) +++ trunk/jython/Lib/test/test_java_visibility.py 2008-12-25 00:05:29 UTC (rev 5798) @@ -1,5 +1,6 @@ import unittest from test import test_support +from java.util import HashMap from org.python.tests import InterfaceCombination, Invisible, SubVisible, Visible, VisibleOverride from org.python.tests import VisibilityResults as Results @@ -82,8 +83,17 @@ self.assertFalse(hasattr(i, "internalMethod"), "methods from private interfaces shouldn't be visible on a private class") +class JavaClassTest(unittest.TestCase): + def test_class_methods_visible(self): + self.assertFalse(HashMap.isInterface(), + 'java.lang.Class methods should be visible on Class instances') + self.assertFalse(HashMap.interface, + 'java.lang.Class bean methods should be visible on instances') + self.assertEquals(3, len(HashMap.getInterfaces())) + def test_main(): - test_support.run_unittest(VisibilityTest) + test_support.run_unittest(VisibilityTest, + JavaClassTest) if __name__ == "__main__": test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2008-12-24 22:57:25
|
Revision: 5797 http://jython.svn.sourceforge.net/jython/?rev=5797&view=rev Author: amak Date: 2008-12-24 22:57:21 +0000 (Wed, 24 Dec 2008) Log Message: ----------- Fixed a small bug with the setting log levels in modjy; checking in updated version. Added Paths: ----------- trunk/jython/extlibs/modjy_0_25_1.zip Removed Paths: ------------- trunk/jython/extlibs/modjy_0_25_0.zip Deleted: trunk/jython/extlibs/modjy_0_25_0.zip =================================================================== (Binary files differ) Added: trunk/jython/extlibs/modjy_0_25_1.zip =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/modjy_0_25_1.zip ___________________________________________________________________ Added: svn:mime-type + application/octet-stream This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |