You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2008-12-17 03:57:00
|
Revision: 5771 http://jython.svn.sourceforge.net/jython/?rev=5771&view=rev Author: fwierzbicki Date: 2008-12-17 03:56:56 +0000 (Wed, 17 Dec 2008) Log Message: ----------- On the advice of the original poster of http://bugs.jython.org/issue1205 known to us only as pb, switching the test cases to the more poetic computation of the Hardy-Ramanujan number http://en.wikipedia.org/wiki/1729_(number). Modified Paths: -------------- trunk/jython/Lib/test/test_genexps_jy.py trunk/jython/Lib/test/test_listcomp_jy.py Modified: trunk/jython/Lib/test/test_genexps_jy.py =================================================================== --- trunk/jython/Lib/test/test_genexps_jy.py 2008-12-16 19:24:41 UTC (rev 5770) +++ trunk/jython/Lib/test/test_genexps_jy.py 2008-12-17 03:56:56 UTC (rev 5771) @@ -17,11 +17,15 @@ #http://bugs.jython.org/issue1205 applied to genexps. def test_long_genexp(self): - r = 2 - g = ((x1**3+x2**3,(x1,x2),(y1,y2)) for x1 in range(4) for x2 in range(4) - if x1 < x2 for y1 in range(r) for y2 in range(r) if y1 < y2 - if x1**3+x2**3 == y1**3+y2**3 ) - self.assertEquals(g.next(), (1, (0, 1), (0, 1))) + #for a long genexp, we compute the Hardy-Ramanujan number + #http://en.wikipedia.org/wiki/1729_(number) + res = ((x1**3+x2**3,(x1,x2),(y1,y2)) + for x1 in range(20) for x2 in range(20) if x1 < x2 # x-Paare + for y1 in range(20) for y2 in range(20) if y1 < y2 # y-Paare + if x1**3+x2**3 == y1**3+y2**3 # gleiche Summe + if (x1,x2) < (y1,y2) + ) + self.assertEquals(1729, res.next()[0]) def test_main(): test_support.run_unittest(GeneratorExpressionsTestCase) Modified: trunk/jython/Lib/test/test_listcomp_jy.py =================================================================== --- trunk/jython/Lib/test/test_listcomp_jy.py 2008-12-16 19:24:41 UTC (rev 5770) +++ trunk/jython/Lib/test/test_listcomp_jy.py 2008-12-17 03:56:56 UTC (rev 5771) @@ -5,12 +5,16 @@ #http://bugs.jython.org/issue1205 def test_long_listcomp(self): - r = 2 - lc = [(x1**3+x2**3,(x1,x2),(y1,y2)) for x1 in range(4) for x2 in range(4) - if x1 < x2 for y1 in range(r) for y2 in range(r) if y1 < y2 - if x1**3+x2**3 == y1**3+y2**3 ] - self.assertEquals(len(lc), 1) - self.assertEquals(lc, [(1, (0, 1), (0, 1))]) + #for a long list comp, we compute the Hardy-Ramanujan number + #http://en.wikipedia.org/wiki/1729_(number) + res = [(x1**3+x2**3,(x1,x2),(y1,y2)) + for x1 in range(20) for x2 in range(20) if x1 < x2 # x-Paare + for y1 in range(20) for y2 in range(20) if y1 < y2 # y-Paare + if x1**3+x2**3 == y1**3+y2**3 # gleiche Summe + if (x1,x2) < (y1,y2) + ] + self.assertEquals(1729, min(res)[0]) + self.assertEquals(len(res), 2) def test_main(): test_support.run_unittest(ListCompTestCase) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-16 19:24:45
|
Revision: 5770 http://jython.svn.sourceforge.net/jython/?rev=5770&view=rev Author: fwierzbicki Date: 2008-12-16 19:24:41 +0000 (Tue, 16 Dec 2008) Log Message: ----------- Fix for http://bugs.jython.org/issue1205, thanks to pb for the report and Philip Jenvey for the AST analysis. List Comprehensions where only including one "list_if" in a series of "list_if". Generator Expressions had the same issue. Added a test to test_genexprs_jy.py and created test_listcomp_jy.py to test for the issue. Modified Paths: -------------- trunk/jython/Lib/test/test_genexps_jy.py trunk/jython/grammar/Python.g Added Paths: ----------- trunk/jython/Lib/test/test_listcomp_jy.py Modified: trunk/jython/Lib/test/test_genexps_jy.py =================================================================== --- trunk/jython/Lib/test/test_genexps_jy.py 2008-12-16 16:58:32 UTC (rev 5769) +++ trunk/jython/Lib/test/test_genexps_jy.py 2008-12-16 19:24:41 UTC (rev 5770) @@ -15,6 +15,13 @@ # this far we've already passed self.assert_(sorted(locals_test) == ['test_support', 'unittest']) + #http://bugs.jython.org/issue1205 applied to genexps. + def test_long_genexp(self): + r = 2 + g = ((x1**3+x2**3,(x1,x2),(y1,y2)) for x1 in range(4) for x2 in range(4) + if x1 < x2 for y1 in range(r) for y2 in range(r) if y1 < y2 + if x1**3+x2**3 == y1**3+y2**3 ) + self.assertEquals(g.next(), (1, (0, 1), (0, 1))) def test_main(): test_support.run_unittest(GeneratorExpressionsTestCase) Added: trunk/jython/Lib/test/test_listcomp_jy.py =================================================================== --- trunk/jython/Lib/test/test_listcomp_jy.py (rev 0) +++ trunk/jython/Lib/test/test_listcomp_jy.py 2008-12-16 19:24:41 UTC (rev 5770) @@ -0,0 +1,19 @@ +import unittest +from test import test_support + +class ListCompTestCase(unittest.TestCase): + + #http://bugs.jython.org/issue1205 + def test_long_listcomp(self): + r = 2 + lc = [(x1**3+x2**3,(x1,x2),(y1,y2)) for x1 in range(4) for x2 in range(4) + if x1 < x2 for y1 in range(r) for y2 in range(r) if y1 < y2 + if x1**3+x2**3 == y1**3+y2**3 ] + self.assertEquals(len(lc), 1) + self.assertEquals(lc, [(1, (0, 1), (0, 1))]) + +def test_main(): + test_support.run_unittest(ListCompTestCase) + +if __name__ == '__main__': + test_main() Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-12-16 16:58:32 UTC (rev 5769) +++ trunk/jython/grammar/Python.g 2008-12-16 19:24:41 UTC (rev 5770) @@ -1516,60 +1516,55 @@ ; //list_iter: list_for | list_if -list_iter [List gens] returns [expr etype] +list_iter [List gens, List ifs] : list_for[gens] - | list_if[gens] { - $etype = $list_if.etype; - } + | list_if[gens, ifs] ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] list_for [List gens] - : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens])? +@init { + List ifs = new ArrayList(); +} + : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] (list_iter[gens, ifs])? { - List<expr> e = new ArrayList<expr>(); - if ($list_iter.etype != null) { - e.add($list_iter.etype); - } - gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($testlist.tree), e)); + Collections.reverse(ifs); + gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($testlist.tree), ifs)); } ; //list_if: 'if' test [list_iter] -list_if[List gens] returns [expr etype] - : IF test[expr_contextType.Load] (list_iter[gens])? +list_if[List gens, List ifs] + : IF test[expr_contextType.Load] (list_iter[gens, ifs])? { - $etype = actions.castExpr($test.tree); + ifs.add(actions.castExpr($test.tree)); } ; //gen_iter: gen_for | gen_if -gen_iter [List gens] returns [expr etype] +gen_iter [List gens, List ifs] : gen_for[gens] - | gen_if[gens] - { - $etype = $gen_if.etype; - } + | gen_if[gens, ifs] ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] gen_for [List gens] - : FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens]? +@init { + List ifs = new ArrayList(); +} + : FOR exprlist[expr_contextType.Store] IN or_test[expr_contextType.Load] gen_iter[gens, ifs]? { - List<expr> e = new ArrayList<expr>(); - if ($gen_iter.etype != null) { - e.add($gen_iter.etype); - } - gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($or_test.tree), e)); + Collections.reverse(ifs); + gens.add(new comprehension($FOR, $exprlist.etype, actions.castExpr($or_test.tree), ifs)); } ; //gen_if: 'if' old_test [gen_iter] -gen_if[List gens] returns [expr etype] - : IF test[expr_contextType.Load] gen_iter[gens]? - { - $etype = actions.castExpr($test.tree); - } +gen_if[List gens, List ifs] + : IF test[expr_contextType.Load] gen_iter[gens, ifs]? + { + ifs.add(actions.castExpr($test.tree)); + } ; //yield_expr: 'yield' [testlist] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2008-12-16 16:58:36
|
Revision: 5769 http://jython.svn.sourceforge.net/jython/?rev=5769&view=rev Author: amak Date: 2008-12-16 16:58:32 +0000 (Tue, 16 Dec 2008) Log Message: ----------- Updating the version of modjy distributed with jython; this one inter-operates fully with jython 2.5 post b0. Added Paths: ----------- trunk/jython/extlibs/modjy_0_25_0.zip Removed Paths: ------------- trunk/jython/extlibs/modjy_0_22_3.zip Deleted: trunk/jython/extlibs/modjy_0_22_3.zip =================================================================== (Binary files differ) Added: trunk/jython/extlibs/modjy_0_25_0.zip =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/modjy_0_25_0.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. |
From: <pj...@us...> - 2008-12-15 19:14:44
|
Revision: 5768 http://jython.svn.sourceforge.net/jython/?rev=5768&view=rev Author: pjenvey Date: 2008-12-15 19:14:40 +0000 (Mon, 15 Dec 2008) Log Message: ----------- update to jna-posix 76492a187ed8 for the utimes API change for large 64 bit timestamps fixes #1166 Modified Paths: -------------- trunk/jython/Lib/os.py trunk/jython/extlibs/jna-posix.jar Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2008-12-15 17:04:17 UTC (rev 5767) +++ trunk/jython/Lib/os.py 2008-12-15 19:14:40 UTC (rev 5768) @@ -170,6 +170,9 @@ # successful termination EX_OK = 0 +# Java class representing the size of a time_t. internal use, lazily set +_time_t = None + class stat_result: _stat_members = ( @@ -537,13 +540,40 @@ if path is None: raise TypeError('path must be specified, not None') - if times is not None: - atime, mtime = times + if times is None: + atimeval = mtimeval = None + elif isinstance(times, tuple) and len(times) == 2: + atimeval = _to_timeval(times[0]) + mtimeval = _to_timeval(times[1]) else: - atime = mtime = time.time() + raise TypeError('utime() arg 2 must be a tuple (atime, mtime)') - _posix.utimes(path, long(atime * 1000), long(mtime * 1000)) + _posix.utimes(path, atimeval, mtimeval) +def _to_timeval(seconds): + """Convert seconds (with a fraction) from epoch to a 2 item tuple of + seconds, microseconds from epoch as longs + """ + global _time_t + if _time_t is None: + from java.lang import Integer, Long + from org.python.posix.util import Platform + _time_t = Integer if Platform.IS_32_BIT else Long + + try: + floor = long(seconds) + except TypeError: + raise TypeError('an integer is required') + if floor < _time_t.MIN_VALUE or floor > _time_t.MAX_VALUE: + raise OverflowError('long int too large to convert to int') + + # usec can't exceed 1000000 + usec = long((seconds - floor) * 1e6) + if usec < 0: + # If rounding gave us a negative number, truncate + usec = 0 + return floor, usec + def close(fd): """close(fd) Modified: trunk/jython/extlibs/jna-posix.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-15 17:04:21
|
Revision: 5767 http://jython.svn.sourceforge.net/jython/?rev=5767&view=rev Author: fwierzbicki Date: 2008-12-15 17:04:17 +0000 (Mon, 15 Dec 2008) Log Message: ----------- results of object.derived change for http://bugs.jython.org/issue1758318. We now pass unmodified test_bool.py, so deleting our version of that as well. Modified Paths: -------------- trunk/jython/src/org/python/antlr/ast/AssertDerived.java trunk/jython/src/org/python/antlr/ast/AssignDerived.java trunk/jython/src/org/python/antlr/ast/AttributeDerived.java trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java trunk/jython/src/org/python/antlr/ast/BinOpDerived.java trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java trunk/jython/src/org/python/antlr/ast/BreakDerived.java trunk/jython/src/org/python/antlr/ast/CallDerived.java trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java trunk/jython/src/org/python/antlr/ast/CompareDerived.java trunk/jython/src/org/python/antlr/ast/ContinueDerived.java trunk/jython/src/org/python/antlr/ast/DeleteDerived.java trunk/jython/src/org/python/antlr/ast/DictDerived.java trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java trunk/jython/src/org/python/antlr/ast/ExecDerived.java trunk/jython/src/org/python/antlr/ast/ExprDerived.java trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java trunk/jython/src/org/python/antlr/ast/ForDerived.java trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java trunk/jython/src/org/python/antlr/ast/GlobalDerived.java trunk/jython/src/org/python/antlr/ast/IfDerived.java trunk/jython/src/org/python/antlr/ast/IfExpDerived.java trunk/jython/src/org/python/antlr/ast/ImportDerived.java trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java trunk/jython/src/org/python/antlr/ast/IndexDerived.java trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java trunk/jython/src/org/python/antlr/ast/LambdaDerived.java trunk/jython/src/org/python/antlr/ast/ListCompDerived.java trunk/jython/src/org/python/antlr/ast/ListDerived.java trunk/jython/src/org/python/antlr/ast/ModuleDerived.java trunk/jython/src/org/python/antlr/ast/NameDerived.java trunk/jython/src/org/python/antlr/ast/NumDerived.java trunk/jython/src/org/python/antlr/ast/PassDerived.java trunk/jython/src/org/python/antlr/ast/PrintDerived.java trunk/jython/src/org/python/antlr/ast/RaiseDerived.java trunk/jython/src/org/python/antlr/ast/ReprDerived.java trunk/jython/src/org/python/antlr/ast/ReturnDerived.java trunk/jython/src/org/python/antlr/ast/SliceDerived.java trunk/jython/src/org/python/antlr/ast/StrDerived.java trunk/jython/src/org/python/antlr/ast/SubscriptDerived.java trunk/jython/src/org/python/antlr/ast/SuiteDerived.java trunk/jython/src/org/python/antlr/ast/TryExceptDerived.java trunk/jython/src/org/python/antlr/ast/TryFinallyDerived.java trunk/jython/src/org/python/antlr/ast/TupleDerived.java trunk/jython/src/org/python/antlr/ast/UnaryOpDerived.java trunk/jython/src/org/python/antlr/ast/WhileDerived.java trunk/jython/src/org/python/antlr/ast/WithDerived.java trunk/jython/src/org/python/antlr/ast/YieldDerived.java trunk/jython/src/org/python/antlr/ast/aliasDerived.java trunk/jython/src/org/python/antlr/ast/argumentsDerived.java trunk/jython/src/org/python/antlr/ast/comprehensionDerived.java trunk/jython/src/org/python/antlr/ast/keywordDerived.java trunk/jython/src/org/python/antlr/op/AddDerived.java trunk/jython/src/org/python/antlr/op/AndDerived.java trunk/jython/src/org/python/antlr/op/AugLoadDerived.java trunk/jython/src/org/python/antlr/op/AugStoreDerived.java trunk/jython/src/org/python/antlr/op/BitAndDerived.java trunk/jython/src/org/python/antlr/op/BitOrDerived.java trunk/jython/src/org/python/antlr/op/BitXorDerived.java trunk/jython/src/org/python/antlr/op/DelDerived.java trunk/jython/src/org/python/antlr/op/DivDerived.java trunk/jython/src/org/python/antlr/op/EqDerived.java trunk/jython/src/org/python/antlr/op/FloorDivDerived.java trunk/jython/src/org/python/antlr/op/GtDerived.java trunk/jython/src/org/python/antlr/op/GtEDerived.java trunk/jython/src/org/python/antlr/op/InDerived.java trunk/jython/src/org/python/antlr/op/InvertDerived.java trunk/jython/src/org/python/antlr/op/IsDerived.java trunk/jython/src/org/python/antlr/op/IsNotDerived.java trunk/jython/src/org/python/antlr/op/LShiftDerived.java trunk/jython/src/org/python/antlr/op/LoadDerived.java trunk/jython/src/org/python/antlr/op/LtDerived.java trunk/jython/src/org/python/antlr/op/LtEDerived.java trunk/jython/src/org/python/antlr/op/ModDerived.java trunk/jython/src/org/python/antlr/op/MultDerived.java trunk/jython/src/org/python/antlr/op/NotDerived.java trunk/jython/src/org/python/antlr/op/NotEqDerived.java trunk/jython/src/org/python/antlr/op/NotInDerived.java trunk/jython/src/org/python/antlr/op/OrDerived.java trunk/jython/src/org/python/antlr/op/ParamDerived.java trunk/jython/src/org/python/antlr/op/PowDerived.java trunk/jython/src/org/python/antlr/op/RShiftDerived.java trunk/jython/src/org/python/antlr/op/StoreDerived.java trunk/jython/src/org/python/antlr/op/SubDerived.java trunk/jython/src/org/python/antlr/op/UAddDerived.java trunk/jython/src/org/python/antlr/op/USubDerived.java trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBaseExceptionDerived.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyEnumerateDerived.java trunk/jython/src/org/python/core/PyFileDerived.java trunk/jython/src/org/python/core/PyFloatDerived.java trunk/jython/src/org/python/core/PyFrozenSetDerived.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyLongDerived.java trunk/jython/src/org/python/core/PyModuleDerived.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PySetDerived.java trunk/jython/src/org/python/core/PySliceDerived.java trunk/jython/src/org/python/core/PyStringDerived.java trunk/jython/src/org/python/core/PySuperDerived.java trunk/jython/src/org/python/core/PyTupleDerived.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/modules/_collections/PyDefaultDictDerived.java trunk/jython/src/org/python/modules/_collections/PyDequeDerived.java trunk/jython/src/org/python/modules/_csv/PyDialectDerived.java trunk/jython/src/org/python/modules/_functools/PyPartialDerived.java trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java trunk/jython/src/org/python/modules/random/PyRandomDerived.java trunk/jython/src/org/python/modules/thread/PyLocalDerived.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java Removed Paths: ------------- trunk/jython/Lib/test/test_bool.py Deleted: trunk/jython/Lib/test/test_bool.py =================================================================== --- trunk/jython/Lib/test/test_bool.py 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/Lib/test/test_bool.py 2008-12-15 17:04:17 UTC (rev 5767) @@ -1,351 +0,0 @@ -# Test properties of bool promised by PEP 285 - -import unittest -from test import test_support - -import os - -class BoolTest(unittest.TestCase): - - def assertIs(self, a, b): - self.assert_(a is b) - - def assertIsNot(self, a, b): - self.assert_(a is not b) - - def test_subclass(self): - try: - class C(bool): - pass - except TypeError: - pass - else: - self.fail("bool should not be subclassable") - - self.assertRaises(TypeError, int.__new__, bool, 0) - - def test_print(self): - try: - fo = open(test_support.TESTFN, "wb") - print >> fo, False, True - fo.close() - fo = open(test_support.TESTFN, "rb") - self.assertEqual(fo.read(), 'False True\n') - finally: - fo.close() - os.remove(test_support.TESTFN) - - def test_repr(self): - self.assertEqual(repr(False), 'False') - self.assertEqual(repr(True), 'True') - self.assertEqual(eval(repr(False)), False) - self.assertEqual(eval(repr(True)), True) - - def test_str(self): - self.assertEqual(str(False), 'False') - self.assertEqual(str(True), 'True') - - def test_int(self): - self.assertEqual(int(False), 0) - self.assertIsNot(int(False), False) - self.assertEqual(int(True), 1) - self.assertIsNot(int(True), True) - - def test_math(self): - self.assertEqual(+False, 0) - self.assertIsNot(+False, False) - self.assertEqual(-False, 0) - self.assertIsNot(-False, False) - self.assertEqual(abs(False), 0) - self.assertIsNot(abs(False), False) - self.assertEqual(+True, 1) - self.assertIsNot(+True, True) - self.assertEqual(-True, -1) - self.assertEqual(abs(True), 1) - self.assertIsNot(abs(True), True) - self.assertEqual(~False, -1) - self.assertEqual(~True, -2) - - self.assertEqual(False+2, 2) - self.assertEqual(True+2, 3) - self.assertEqual(2+False, 2) - self.assertEqual(2+True, 3) - - self.assertEqual(False+False, 0) - self.assertIsNot(False+False, False) - self.assertEqual(False+True, 1) - self.assertIsNot(False+True, True) - self.assertEqual(True+False, 1) - self.assertIsNot(True+False, True) - self.assertEqual(True+True, 2) - - self.assertEqual(True-True, 0) - self.assertIsNot(True-True, False) - self.assertEqual(False-False, 0) - self.assertIsNot(False-False, False) - self.assertEqual(True-False, 1) - self.assertIsNot(True-False, True) - self.assertEqual(False-True, -1) - - self.assertEqual(True*1, 1) - self.assertEqual(False*1, 0) - self.assertIsNot(False*1, False) - - self.assertEqual(True/1, 1) - self.assertIsNot(True/1, True) - self.assertEqual(False/1, 0) - self.assertIsNot(False/1, False) - - for b in False, True: - for i in 0, 1, 2: - self.assertEqual(b**i, int(b)**i) - self.assertIsNot(b**i, bool(int(b)**i)) - - for a in False, True: - for b in False, True: - self.assertIs(a&b, bool(int(a)&int(b))) - self.assertIs(a|b, bool(int(a)|int(b))) - self.assertIs(a^b, bool(int(a)^int(b))) - self.assertEqual(a&int(b), int(a)&int(b)) - self.assertIsNot(a&int(b), bool(int(a)&int(b))) - self.assertEqual(a|int(b), int(a)|int(b)) - self.assertIsNot(a|int(b), bool(int(a)|int(b))) - self.assertEqual(a^int(b), int(a)^int(b)) - self.assertIsNot(a^int(b), bool(int(a)^int(b))) - self.assertEqual(int(a)&b, int(a)&int(b)) - self.assertIsNot(int(a)&b, bool(int(a)&int(b))) - self.assertEqual(int(a)|b, int(a)|int(b)) - self.assertIsNot(int(a)|b, bool(int(a)|int(b))) - self.assertEqual(int(a)^b, int(a)^int(b)) - self.assertIsNot(int(a)^b, bool(int(a)^int(b))) - - self.assertIs(1==1, True) - self.assertIs(1==0, False) - self.assertIs(0<1, True) - self.assertIs(1<0, False) - self.assertIs(0<=0, True) - self.assertIs(1<=0, False) - self.assertIs(1>0, True) - self.assertIs(1>1, False) - self.assertIs(1>=1, True) - self.assertIs(0>=1, False) - self.assertIs(0!=1, True) - self.assertIs(0!=0, False) - - x = [1] - self.assertIs(x is x, True) - self.assertIs(x is not x, False) - - self.assertIs(1 in x, True) - self.assertIs(0 in x, False) - self.assertIs(1 not in x, False) - self.assertIs(0 not in x, True) - - x = {1: 2} - self.assertIs(x is x, True) - self.assertIs(x is not x, False) - - self.assertIs(1 in x, True) - self.assertIs(0 in x, False) - self.assertIs(1 not in x, False) - self.assertIs(0 not in x, True) - - self.assertIs(not True, False) - self.assertIs(not False, True) - - def test_convert(self): - self.assertRaises(TypeError, bool, 42, 42) - self.assertIs(bool(10), True) - self.assertIs(bool(1), True) - self.assertIs(bool(-1), True) - self.assertIs(bool(0), False) - self.assertIs(bool("hello"), True) - self.assertIs(bool(""), False) - self.assertIs(bool(), False) - - def test_hasattr(self): - self.assertIs(hasattr([], "append"), True) - self.assertIs(hasattr([], "wobble"), False) - - def test_callable(self): - self.assertIs(callable(len), True) - self.assertIs(callable(1), False) - - def test_isinstance(self): - self.assertIs(isinstance(True, bool), True) - self.assertIs(isinstance(False, bool), True) - self.assertIs(isinstance(True, int), True) - self.assertIs(isinstance(False, int), True) - self.assertIs(isinstance(1, bool), False) - self.assertIs(isinstance(0, bool), False) - - def test_issubclass(self): - self.assertIs(issubclass(bool, int), True) - self.assertIs(issubclass(int, bool), False) - - def test_haskey(self): - self.assertIs({}.has_key(1), False) - self.assertIs({1:1}.has_key(1), True) - - def test_string(self): - self.assertIs("xyz".endswith("z"), True) - self.assertIs("xyz".endswith("x"), False) - self.assertIs("xyz0123".isalnum(), True) - self.assertIs("@#$%".isalnum(), False) - self.assertIs("xyz".isalpha(), True) - self.assertIs("@#$%".isalpha(), False) - self.assertIs("0123".isdigit(), True) - self.assertIs("xyz".isdigit(), False) - self.assertIs("xyz".islower(), True) - self.assertIs("XYZ".islower(), False) - self.assertIs(" ".isspace(), True) - self.assertIs("XYZ".isspace(), False) - self.assertIs("X".istitle(), True) - self.assertIs("x".istitle(), False) - self.assertIs("XYZ".isupper(), True) - self.assertIs("xyz".isupper(), False) - self.assertIs("xyz".startswith("x"), True) - self.assertIs("xyz".startswith("z"), False) - - if test_support.have_unicode: - self.assertIs(unicode("xyz", 'ascii').endswith(unicode("z", 'ascii')), True) - self.assertIs(unicode("xyz", 'ascii').endswith(unicode("x", 'ascii')), False) - self.assertIs(unicode("xyz0123", 'ascii').isalnum(), True) - self.assertIs(unicode("@#$%", 'ascii').isalnum(), False) - self.assertIs(unicode("xyz", 'ascii').isalpha(), True) - self.assertIs(unicode("@#$%", 'ascii').isalpha(), False) - self.assertIs(unicode("0123", 'ascii').isdecimal(), True) - self.assertIs(unicode("xyz", 'ascii').isdecimal(), False) - self.assertIs(unicode("0123", 'ascii').isdigit(), True) - self.assertIs(unicode("xyz", 'ascii').isdigit(), False) - self.assertIs(unicode("xyz", 'ascii').islower(), True) - self.assertIs(unicode("XYZ", 'ascii').islower(), False) - self.assertIs(unicode("0123", 'ascii').isnumeric(), True) - self.assertIs(unicode("xyz", 'ascii').isnumeric(), False) - self.assertIs(unicode(" ", 'ascii').isspace(), True) - self.assertIs(unicode("XYZ", 'ascii').isspace(), False) - self.assertIs(unicode("X", 'ascii').istitle(), True) - self.assertIs(unicode("x", 'ascii').istitle(), False) - self.assertIs(unicode("XYZ", 'ascii').isupper(), True) - self.assertIs(unicode("xyz", 'ascii').isupper(), False) - self.assertIs(unicode("xyz", 'ascii').startswith(unicode("x", 'ascii')), True) - self.assertIs(unicode("xyz", 'ascii').startswith(unicode("z", 'ascii')), False) - - def test_boolean(self): - self.assertEqual(True & 1, 1) - self.assert_(not isinstance(True & 1, bool)) - self.assertIs(True & True, True) - - self.assertEqual(True | 1, 1) - self.assert_(not isinstance(True | 1, bool)) - self.assertIs(True | True, True) - - self.assertEqual(True ^ 1, 0) - self.assert_(not isinstance(True ^ 1, bool)) - self.assertIs(True ^ True, False) - - def test_fileclosed(self): - try: - f = file(test_support.TESTFN, "w") - self.assertIs(f.closed, False) - f.close() - self.assertIs(f.closed, True) - finally: - os.remove(test_support.TESTFN) - - def test_operator(self): - import operator - self.assertIs(operator.truth(0), False) - self.assertIs(operator.truth(1), True) - self.assertIs(operator.isCallable(0), False) - self.assertIs(operator.isCallable(len), True) - self.assertIs(operator.isNumberType(None), False) - self.assertIs(operator.isNumberType(0), True) - self.assertIs(operator.not_(1), False) - self.assertIs(operator.not_(0), True) - self.assertIs(operator.isSequenceType(0), False) - self.assertIs(operator.isSequenceType([]), True) - self.assertIs(operator.contains([], 1), False) - self.assertIs(operator.contains([1], 1), True) - self.assertIs(operator.isMappingType(1), False) - self.assertIs(operator.isMappingType({}), True) - self.assertIs(operator.lt(0, 0), False) - self.assertIs(operator.lt(0, 1), True) - self.assertIs(operator.is_(True, True), True) - self.assertIs(operator.is_(True, False), False) - self.assertIs(operator.is_not(True, True), False) - self.assertIs(operator.is_not(True, False), True) - - def test_marshal(self): - import marshal - self.assertIs(marshal.loads(marshal.dumps(True)), True) - self.assertIs(marshal.loads(marshal.dumps(False)), False) - - def test_pickle(self): - import pickle - self.assertIs(pickle.loads(pickle.dumps(True)), True) - self.assertIs(pickle.loads(pickle.dumps(False)), False) - self.assertIs(pickle.loads(pickle.dumps(True, True)), True) - self.assertIs(pickle.loads(pickle.dumps(False, True)), False) - - def test_cpickle(self): - import cPickle - self.assertIs(cPickle.loads(cPickle.dumps(True)), True) - self.assertIs(cPickle.loads(cPickle.dumps(False)), False) - self.assertIs(cPickle.loads(cPickle.dumps(True, True)), True) - self.assertIs(cPickle.loads(cPickle.dumps(False, True)), False) - - def test_mixedpickle(self): - import pickle, cPickle - self.assertIs(pickle.loads(cPickle.dumps(True)), True) - self.assertIs(pickle.loads(cPickle.dumps(False)), False) - self.assertIs(pickle.loads(cPickle.dumps(True, True)), True) - self.assertIs(pickle.loads(cPickle.dumps(False, True)), False) - - self.assertIs(cPickle.loads(pickle.dumps(True)), True) - self.assertIs(cPickle.loads(pickle.dumps(False)), False) - self.assertIs(cPickle.loads(pickle.dumps(True, True)), True) - self.assertIs(cPickle.loads(pickle.dumps(False, True)), False) - - def test_picklevalues(self): - import pickle, cPickle - - # Test for specific backwards-compatible pickle values - self.assertEqual(pickle.dumps(True), "I01\n.") - self.assertEqual(pickle.dumps(False), "I00\n.") - self.assertEqual(cPickle.dumps(True), "I01\n.") - self.assertEqual(cPickle.dumps(False), "I00\n.") - self.assertEqual(pickle.dumps(True, True), "I01\n.") - self.assertEqual(pickle.dumps(False, True), "I00\n.") - self.assertEqual(cPickle.dumps(True, True), "I01\n.") - self.assertEqual(cPickle.dumps(False, True), "I00\n.") - - def test_convert_to_bool(self): - # Verify that TypeError occurs when bad things are returned - # from __nonzero__(). This isn't really a bool test, but - # it's related. - check = lambda o: self.assertRaises(TypeError, bool, o) - class Foo(object): - def __nonzero__(self): - return self - check(Foo()) - - class Bar(object): - def __nonzero__(self): - return "Yes" - check(Bar()) - - class Baz(int): - def __nonzero__(self): - return self - check(Baz()) - -# StackOverflow if __nonzero__ returns self -# http://jython.org/bugs/1758318 -del BoolTest.test_convert_to_bool - -def test_main(): - test_support.run_unittest(BoolTest) - -if __name__ == "__main__": - test_main() Modified: trunk/jython/src/org/python/antlr/ast/AssertDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AssertDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/AssertDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/AssignDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AssignDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/AssignDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/AttributeDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AttributeDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/AttributeDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/AugAssignDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/BinOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BinOpDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/BinOpDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/BoolOpDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/BreakDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BreakDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/BreakDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/CallDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/CallDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/CallDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ClassDefDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/CompareDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/CompareDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/CompareDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ContinueDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ContinueDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ContinueDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/DeleteDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/DeleteDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/DeleteDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/DictDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/DictDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/DictDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/EllipsisDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ExceptHandlerDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ExecDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExecDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ExecDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ExprDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExprDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ExprDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ExpressionDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ExtSliceDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ForDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ForDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ForDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/FunctionDefDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/GeneratorExpDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/GlobalDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GlobalDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/GlobalDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/IfDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/IfDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/IfExpDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfExpDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/IfExpDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ImportDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ImportDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ImportFromDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/IndexDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IndexDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/IndexDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/InteractiveDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/LambdaDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/LambdaDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/LambdaDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ListCompDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ListCompDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ListCompDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ListDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ListDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ListDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/ModuleDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ModuleDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/ModuleDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); } } } Modified: trunk/jython/src/org/python/antlr/ast/NameDerived.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/NameDerived.java 2008-12-15 17:01:52 UTC (rev 5766) +++ trunk/jython/src/org/python/antlr/ast/NameDerived.java 2008-12-15 17:04:17 UTC (rev 5767) @@ -793,7 +793,12 @@ if (impl==null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { @@ -1093,6 +1098,7 @@ if (res!=Py.None) { throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); } + proxyInit(); ... [truncated message content] |
From: <fwi...@us...> - 2008-12-15 17:01:55
|
Revision: 5766 http://jython.svn.sourceforge.net/jython/?rev=5766&view=rev Author: fwierzbicki Date: 2008-12-15 17:01:52 +0000 (Mon, 15 Dec 2008) Log Message: ----------- Fix for http://bugs.jython.org/issue1758318. subclasses of __nonzero__ must return *exactly* PyInteger or PyBoolean. Just checking in template for now will check in the results of the template next. Modified Paths: -------------- trunk/jython/src/templates/object.derived Modified: trunk/jython/src/templates/object.derived =================================================================== --- trunk/jython/src/templates/object.derived 2008-12-15 14:12:18 UTC (rev 5765) +++ trunk/jython/src/templates/object.derived 2008-12-15 17:01:52 UTC (rev 5766) @@ -125,7 +125,13 @@ if (impl == null) return super.__nonzero__(); } - return impl.__get__(this,self_type).__call__().__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) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-15 14:12:23
|
Revision: 5765 http://jython.svn.sourceforge.net/jython/?rev=5765&view=rev Author: fwierzbicki Date: 2008-12-15 14:12:18 +0000 (Mon, 15 Dec 2008) Log Message: ----------- Sigh, restore updates to test_list_jy.py that I blew away. Mainly test_subclass_richcmp and ListTest -> ListTestCase. Modified Paths: -------------- trunk/jython/Lib/test/test_list_jy.py Modified: trunk/jython/Lib/test/test_list_jy.py =================================================================== --- trunk/jython/Lib/test/test_list_jy.py 2008-12-15 14:01:24 UTC (rev 5764) +++ trunk/jython/Lib/test/test_list_jy.py 2008-12-15 14:12:18 UTC (rev 5765) @@ -1,39 +1,50 @@ import unittest import test.test_support -class ListTest(unittest.TestCase): - +class ListTestCase(unittest.TestCase): + def test_recursive_list_slices(self): x = [1,2,3,4,5] x[1:] = x - self.assertEquals(x, [1, 1, 2, 3, 4, 5], - "Recursive assignment to list slices failed") + "Recursive assignment to list slices failed") + def test_subclass_richcmp(self): + # http://bugs.jython.org/issue1115 + class Foo(list): + def __init__(self, dotstring): + list.__init__(self, map(int, dotstring.split("."))) + bar1 = Foo('1.2.3') + bar2 = Foo('1.2.4') + self.assert_(bar1 < bar2) + self.assert_(bar1 <= bar2) + self.assert_(bar2 > bar1) + self.assert_(bar2 >= bar1) + #From http://bugs.jython.org/issue600790 def test_setget_override(self): from java.util import ArrayList from java.lang import String class GoofyListMapThing (ArrayList): - def __init__(self): self.silly = "Nothing" - + def __setitem__(self, key, element): self.silly = "spam" - + def __getitem__(self, key): self.silly = "eggs" - + glmt = GoofyListMapThing() glmt['my-key'] = String('el1') self.assertEquals(glmt.silly, "spam") glmt['my-key'] self.assertEquals(glmt.silly, "eggs") - + def test_main(): - test.test_support.run_unittest(ListTest) + test.test_support.run_unittest(ListTestCase) + if __name__ == "__main__": test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-15 14:01:28
|
Revision: 5764 http://jython.svn.sourceforge.net/jython/?rev=5764&view=rev Author: fwierzbicki Date: 2008-12-15 14:01:24 +0000 (Mon, 15 Dec 2008) Log Message: ----------- Reverting test_list_jy.py since tags should almost never be updated. Modified Paths: -------------- tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py Modified: tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py =================================================================== --- tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py 2008-12-15 13:55:49 UTC (rev 5763) +++ tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py 2008-12-15 14:01:24 UTC (rev 5764) @@ -3,37 +3,15 @@ class ListTest(unittest.TestCase): - def test_recursive_list_slices(self): - x = [1,2,3,4,5] - x[1:] = x + def test_recursive_list_slices(self): + x = [1,2,3,4,5] + x[1:] = x - self.assertEquals(x, [1, 1, 2, 3, 4, 5], - "Recursive assignment to list slices failed") + self.assertEquals(x, [1, 1, 2, 3, 4, 5], + "Recursive assignment to list slices failed") - #From http://bugs.jython.org/issue600790 - def test_setget_override(self): - from java.util import ArrayList - from java.lang import String - - class GoofyListMapThing (ArrayList): - - def __init__(self): - self.silly = "Nothing" - - def __setitem__(self, key, element): - self.silly = "spam" - - def __getitem__(self, key): - self.silly = "eggs" - - glmt = GoofyListMapThing() - glmt['my-key'] = String('el1') - self.assertEquals(glmt.silly, "spam") - glmt['my-key'] - self.assertEquals(glmt.silly, "eggs") - def test_main(): - test.test_support.run_unittest(ListTest) + test.test_support.run_unittest(ListTest) if __name__ == "__main__": - test_main() + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-15 13:55:59
|
Revision: 5763 http://jython.svn.sourceforge.net/jython/?rev=5763&view=rev Author: fwierzbicki Date: 2008-12-15 13:55:49 +0000 (Mon, 15 Dec 2008) Log Message: ----------- Test for http://bugs.jython.org/issue600790 added. Most likely this bug was fixed by Charlie Groves when java-type-newstyle branch was merged. Modified Paths: -------------- trunk/jython/Lib/test/test_list_jy.py Modified: trunk/jython/Lib/test/test_list_jy.py =================================================================== --- trunk/jython/Lib/test/test_list_jy.py 2008-12-14 23:58:41 UTC (rev 5762) +++ trunk/jython/Lib/test/test_list_jy.py 2008-12-15 13:55:49 UTC (rev 5763) @@ -1,30 +1,39 @@ import unittest import test.test_support -class ListTestCase(unittest.TestCase): - +class ListTest(unittest.TestCase): + def test_recursive_list_slices(self): x = [1,2,3,4,5] x[1:] = x + self.assertEquals(x, [1, 1, 2, 3, 4, 5], - "Recursive assignment to list slices failed") + "Recursive assignment to list slices failed") - def test_subclass_richcmp(self): - # http://bugs.jython.org/issue1115 - class Foo(list): - def __init__(self, dotstring): - list.__init__(self, map(int, dotstring.split("."))) - bar1 = Foo('1.2.3') - bar2 = Foo('1.2.4') - self.assert_(bar1 < bar2) - self.assert_(bar1 <= bar2) - self.assert_(bar2 > bar1) - self.assert_(bar2 >= bar1) + #From http://bugs.jython.org/issue600790 + def test_setget_override(self): + from java.util import ArrayList + from java.lang import String + class GoofyListMapThing (ArrayList): + def __init__(self): + self.silly = "Nothing" + + def __setitem__(self, key, element): + self.silly = "spam" + + def __getitem__(self, key): + self.silly = "eggs" + + glmt = GoofyListMapThing() + glmt['my-key'] = String('el1') + self.assertEquals(glmt.silly, "spam") + glmt['my-key'] + self.assertEquals(glmt.silly, "eggs") + def test_main(): - test.test_support.run_unittest(ListTestCase) + test.test_support.run_unittest(ListTest) - if __name__ == "__main__": test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-14 23:58:45
|
Revision: 5762 http://jython.svn.sourceforge.net/jython/?rev=5762&view=rev Author: pjenvey Date: 2008-12-14 23:58:41 +0000 (Sun, 14 Dec 2008) Log Message: ----------- o fix broken os.utime on 64 bit POSIX platforms, w/ jna-posix revision 92037116ce84 o fix grp/pwd to handle the new jna-posix Modified Paths: -------------- trunk/jython/Lib/grp.py trunk/jython/Lib/pwd.py trunk/jython/extlibs/jna-posix.jar Modified: trunk/jython/Lib/grp.py =================================================================== --- trunk/jython/Lib/grp.py 2008-12-14 23:57:35 UTC (rev 5761) +++ trunk/jython/Lib/grp.py 2008-12-14 23:58:41 UTC (rev 5762) @@ -18,7 +18,6 @@ __all__ = ['getgrgid', 'getgrnam', 'getgrall'] from os import _name, _posix -from java.lang import NullPointerException if _name == 'nt': raise ImportError, 'grp module not supported on Windows' @@ -44,28 +43,31 @@ except ValueError: raise AttributeError + def getgrgid(uid): """ getgrgid(id) -> tuple Return the group database entry for the given numeric group ID. If id is not valid, raise KeyError. """ - try: - return struct_group(_posix.getgrgid(uid)) - except NullPointerException: - raise KeyError, uid + entry = _posix.getgrgid(uid) + if not entry: + raise KeyError(uid) + return struct_group(entry) + def getgrnam(name): """ getgrnam(name) -> tuple Return the group database entry for the given group name. If name is not valid, raise KeyError. """ - try: - return struct_group(_posix.getgrnam(name)) - except NullPointerException: - raise KeyError, name + entry = _posix.getgrnam(name) + if not entry: + raise KeyError(name) + return struct_group(entry) + def getgrall(): """ getgrall() -> list of tuples @@ -73,8 +75,9 @@ in arbitrary order. """ groups = [] - try: - while True: - groups.append(struct_group(_posix.getgrent())) - except NullPointerException: - return groups + while True: + group = _posix.getgrent() + if not group: + break + groups.append(struct_group(group)) + return groups Modified: trunk/jython/Lib/pwd.py =================================================================== --- trunk/jython/Lib/pwd.py 2008-12-14 23:57:35 UTC (rev 5761) +++ trunk/jython/Lib/pwd.py 2008-12-14 23:58:41 UTC (rev 5762) @@ -11,7 +11,6 @@ __all__ = ['getpwuid', 'getpwnam', 'getpwall'] from os import _name, _posix -from java.lang import NullPointerException if _name == 'nt': raise ImportError, 'pwd module not supported on Windows' @@ -37,6 +36,7 @@ except ValueError: raise AttributeError + def getpwuid(uid): """ getpwuid(uid) -> (pw_name,pw_passwd,pw_uid, @@ -44,11 +44,12 @@ Return the password database entry for the given numeric user ID. See pwd.__doc__ for more on password database entries. """ - try: - return struct_passwd(_posix.getpwuid(uid)) - except NullPointerException: - raise KeyError, uid + entry = _posix.getpwuid(uid) + if not entry: + raise KeyError(uid) + return struct_passwd(entry) + def getpwnam(name): """ getpwnam(name) -> (pw_name,pw_passwd,pw_uid, @@ -56,11 +57,12 @@ Return the password database entry for the given user name. See pwd.__doc__ for more on password database entries. """ - try: - return struct_passwd(_posix.getpwnam(name)) - except NullPointerException: - raise KeyError, name + entry = _posix.getpwnam(name) + if not entry: + raise KeyError(name) + return struct_passwd(entry) + def getpwall(): """ getpwall() -> list_of_entries @@ -69,8 +71,9 @@ See pwd.__doc__ for more on password database entries. """ entries = [] - try: - while True: - entries.append(struct_passwd(_posix.getpwent())) - except NullPointerException: - return entries + while True: + entry = _posix.getpwent() + if not entry: + break + entries.append(struct_passwd(entry)) + return entries Modified: trunk/jython/extlibs/jna-posix.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-14 23:57:41
|
Revision: 5761 http://jython.svn.sourceforge.net/jython/?rev=5761&view=rev Author: pjenvey Date: 2008-12-14 23:57:35 +0000 (Sun, 14 Dec 2008) Log Message: ----------- coerce the POSIXHandler's error message back to a str Modified Paths: -------------- trunk/jython/Lib/os.py Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2008-12-14 18:29:43 UTC (rev 5760) +++ trunk/jython/Lib/os.py 2008-12-14 23:57:35 UTC (rev 5761) @@ -101,8 +101,8 @@ def error(self, error, msg): err = getattr(errno, error.name(), None) if err is None: - raise OSError('%s: %s' % (error, msg)) - raise OSError(err, strerror(err), msg) + raise OSError('%s: %s' % (error, asPyString(msg))) + raise OSError(err, strerror(err), asPyString(msg)) def unimplementedError(self, method_name): raise NotImplementedError(method_name) def warn(self, warning_id, msg, rest): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-14 18:29:46
|
Revision: 5760 http://jython.svn.sourceforge.net/jython/?rev=5760&view=rev Author: fwierzbicki Date: 2008-12-14 18:29:43 +0000 (Sun, 14 Dec 2008) Log Message: ----------- Test for http://bugs.jython.org/issue600790 added. Most likely this bug was fixed by Charlie Groves when java-type-newstyle branch was merged. Modified Paths: -------------- tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py Modified: tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py =================================================================== --- tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py 2008-12-14 18:01:02 UTC (rev 5759) +++ tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py 2008-12-14 18:29:43 UTC (rev 5760) @@ -10,6 +10,28 @@ self.assertEquals(x, [1, 1, 2, 3, 4, 5], "Recursive assignment to list slices failed") + #From http://bugs.jython.org/issue600790 + def test_setget_override(self): + from java.util import ArrayList + from java.lang import String + + class GoofyListMapThing (ArrayList): + + def __init__(self): + self.silly = "Nothing" + + def __setitem__(self, key, element): + self.silly = "spam" + + def __getitem__(self, key): + self.silly = "eggs" + + glmt = GoofyListMapThing() + glmt['my-key'] = String('el1') + self.assertEquals(glmt.silly, "spam") + glmt['my-key'] + self.assertEquals(glmt.silly, "eggs") + def test_main(): test.test_support.run_unittest(ListTest) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-14 18:01:05
|
Revision: 5759 http://jython.svn.sourceforge.net/jython/?rev=5759&view=rev Author: fwierzbicki Date: 2008-12-14 18:01:02 +0000 (Sun, 14 Dec 2008) Log Message: ----------- small reformat. Modified Paths: -------------- tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py Modified: tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py =================================================================== --- tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py 2008-12-14 02:04:52 UTC (rev 5758) +++ tags/Release_2_5beta0/jython/Lib/test/test_list_jy.py 2008-12-14 18:01:02 UTC (rev 5759) @@ -3,15 +3,15 @@ class ListTest(unittest.TestCase): - def test_recursive_list_slices(self): - x = [1,2,3,4,5] - x[1:] = x + def test_recursive_list_slices(self): + x = [1,2,3,4,5] + x[1:] = x - self.assertEquals(x, [1, 1, 2, 3, 4, 5], - "Recursive assignment to list slices failed") + self.assertEquals(x, [1, 1, 2, 3, 4, 5], + "Recursive assignment to list slices failed") def test_main(): - test.test_support.run_unittest(ListTest) + test.test_support.run_unittest(ListTest) if __name__ == "__main__": - test_main() + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-14 02:04:57
|
Revision: 5758 http://jython.svn.sourceforge.net/jython/?rev=5758&view=rev Author: pjenvey Date: 2008-12-14 02:04:52 +0000 (Sun, 14 Dec 2008) Log Message: ----------- fix the new __future__s not working in the REPL Modified Paths: -------------- trunk/jython/src/org/python/compiler/Future.java Modified: trunk/jython/src/org/python/compiler/Future.java =================================================================== --- trunk/jython/src/org/python/compiler/Future.java 2008-12-14 01:47:15 UTC (rev 5757) +++ trunk/jython/src/org/python/compiler/Future.java 2008-12-14 02:04:52 UTC (rev 5758) @@ -68,6 +68,8 @@ { if (cflags != null) { division = cflags.division; + with_statement = cflags.with_statement; + absolute_import = cflags.absolute_import; } int beg = 0; List<stmt> suite = null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-12-14 01:49:34
|
Revision: 5757 http://jython.svn.sourceforge.net/jython/?rev=5757&view=rev Author: pjenvey Date: 2008-12-14 01:47:15 +0000 (Sun, 14 Dec 2008) Log Message: ----------- merge changes from: http://svn.python.org/projects/python/branches/release25-maint/Lib/decimal.py -c 67699 Modified Paths: -------------- trunk/jython/Lib/decimal.py Modified: trunk/jython/Lib/decimal.py =================================================================== --- trunk/jython/Lib/decimal.py 2008-12-13 22:44:55 UTC (rev 5756) +++ trunk/jython/Lib/decimal.py 2008-12-14 01:47:15 UTC (rev 5757) @@ -2430,10 +2430,10 @@ sn = self._isnan() on = other._isnan() if sn or on: - if on == 1 and sn != 2: - return self._fix_nan(context) - if sn == 1 and on != 2: - return other._fix_nan(context) + if on == 1 and sn == 0: + return self._fix(context) + if sn == 1 and on == 0: + return other._fix(context) return self._check_nans(other, context) c = self.__cmp__(other) @@ -2472,10 +2472,10 @@ sn = self._isnan() on = other._isnan() if sn or on: - if on == 1 and sn != 2: - return self._fix_nan(context) - if sn == 1 and on != 2: - return other._fix_nan(context) + if on == 1 and sn == 0: + return self._fix(context) + if sn == 1 and on == 0: + return other._fix(context) return self._check_nans(other, context) c = self.__cmp__(other) @@ -3043,10 +3043,10 @@ sn = self._isnan() on = other._isnan() if sn or on: - if on == 1 and sn != 2: - return self._fix_nan(context) - if sn == 1 and on != 2: - return other._fix_nan(context) + if on == 1 and sn == 0: + return self._fix(context) + if sn == 1 and on == 0: + return other._fix(context) return self._check_nans(other, context) c = self.copy_abs().__cmp__(other.copy_abs()) @@ -3073,10 +3073,10 @@ sn = self._isnan() on = other._isnan() if sn or on: - if on == 1 and sn != 2: - return self._fix_nan(context) - if sn == 1 and on != 2: - return other._fix_nan(context) + if on == 1 and sn == 0: + return self._fix(context) + if sn == 1 and on == 0: + return other._fix(context) return self._check_nans(other, context) c = self.copy_abs().__cmp__(other.copy_abs()) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-13 22:44:58
|
Revision: 5756 http://jython.svn.sourceforge.net/jython/?rev=5756&view=rev Author: fwierzbicki Date: 2008-12-13 22:44:55 +0000 (Sat, 13 Dec 2008) Log Message: ----------- uncomment call to setline which will now activate ASM code that will create a LineNumberTable in .class output. This will show line numbers in JVM generated stack traces. Modified Paths: -------------- trunk/jython/src/org/python/compiler/CodeCompiler.java Modified: trunk/jython/src/org/python/compiler/CodeCompiler.java =================================================================== --- trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-12-13 16:08:36 UTC (rev 5755) +++ trunk/jython/src/org/python/compiler/CodeCompiler.java 2008-12-13 22:44:55 UTC (rev 5756) @@ -175,7 +175,7 @@ public void setline(int line) throws Exception { if (module.linenumbers) { - //FJW code.setline(line); + code.setline(line); loadFrame(); code.iconst(line); code.invokevirtual("org/python/core/PyFrame", "setline", "(I)V"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-12-13 16:08:39
|
Revision: 5755 http://jython.svn.sourceforge.net/jython/?rev=5755&view=rev Author: otmarhumbel Date: 2008-12-13 16:08:36 +0000 (Sat, 13 Dec 2008) Log Message: ----------- use GraphicsEnvironment.isHeadless() to detect gui availability fixes issue #1658599 Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/Installation.java Modified: trunk/installer/src/java/org/python/util/install/Installation.java =================================================================== --- trunk/installer/src/java/org/python/util/install/Installation.java 2008-12-13 14:27:58 UTC (rev 5754) +++ trunk/installer/src/java/org/python/util/install/Installation.java 2008-12-13 16:08:36 UTC (rev 5755) @@ -91,9 +91,7 @@ protected static boolean isValidJava(JavaVersionInfo javaVersionInfo) { String specificationVersion = javaVersionInfo.getSpecificationVersion(); - if (Installation.isVerbose()) { - ConsoleInstaller.message("specification version: '" + specificationVersion + "'"); - } + verboseOutput("specification version: '" + specificationVersion + "'"); // major.minor.micro // according to http://java.sun.com/j2se/1.5.0/docs/guide/versioning/spec/versioning2.html int major = 0; @@ -175,10 +173,8 @@ command[2] = System.getProperty("java.class.path"); command[3] = JavaVersionTester.class.getName(); command[4] = tempFile.getAbsolutePath(); - if (isVerbose()) { - ConsoleInstaller.message("executing: " + command[0] + " " + command[1] - + " " + command[2] + " " + command[3] + " " + command[4]); - } + verboseOutput("executing: " + command[0] + " " + command[1] + " " + command[2] + + " " + command[3] + " " + command[4]); ChildProcess childProcess = new ChildProcess(command, 10000); // 10 seconds childProcess.setDebug(Installation.isVerbose()); int errorCode = childProcess.run(); @@ -278,28 +274,24 @@ } public static boolean isGuiAllowed() { - boolean verbose = isVerbose(); - if (verbose) { - ConsoleInstaller.message("checking gui availability"); - } + verboseOutput("checking gui availability"); if (Boolean.getBoolean(HEADLESS_PROPERTY_NAME)) { + verboseOutput(HEADLESS_PROPERTY_NAME + " is true"); return false; - } - try { - if (verbose) { - ConsoleInstaller.message("trying to get the graphics environment"); - } - GraphicsEnvironment.getLocalGraphicsEnvironment(); - if (verbose) { - ConsoleInstaller.message("got the graphics environment!"); - } - return true; - } catch (Throwable t) { - if (verbose) { - ConsoleInstaller.message("got the following exception:"); - t.printStackTrace(); - } + } else if (GraphicsEnvironment.isHeadless()) { + verboseOutput("GraphicsEnvironment is headless"); return false; + } else { + try { + verboseOutput("trying to get the GraphicsEnvironment"); + GraphicsEnvironment.getLocalGraphicsEnvironment(); + verboseOutput("got the GraphicsEnvironment!"); + return true; + } catch (Throwable t) { + verboseOutput("got the following exception:"); + verboseOutput(t); + return false; + } } } @@ -326,11 +318,8 @@ private static void internalMain(String[] args, Autotest autotest, Tunnel tunnel) { try { setVerbose(InstallerCommandLine.hasVerboseOptionInArgs(args)); - boolean verbose = isVerbose(); - if (verbose) { - dumpSystemProperties(); - ConsoleInstaller.message("reading jar info"); - } + dumpSystemProperties(); + verboseOutput("reading jar info"); JarInfo jarInfo = new JarInfo(); InstallerCommandLine commandLine = new InstallerCommandLine(jarInfo); if (!commandLine.setArgs(args) || commandLine.hasHelpOption()) { @@ -338,9 +327,7 @@ System.exit(1); } else { if (commandLine.hasAutotestOption()) { - if (verbose) { - ConsoleInstaller.message("running autotests"); - } + verboseOutput("running autotests"); _isAutotesting = true; InstallationDriver autotestDriver = new InstallationDriver(commandLine); autotestDriver.drive(); // ! reentrant into internalMain() @@ -349,9 +336,7 @@ System.exit(0); } if (!useGui(commandLine)) { - if (verbose) { - ConsoleInstaller.message("using the console installer"); - } + verboseOutput("using the console installer"); ConsoleInstaller consoleInstaller = new ConsoleInstaller(commandLine, jarInfo); consoleInstaller.setTunnel(tunnel); consoleInstaller.install(); @@ -359,9 +344,7 @@ System.exit(0); } } else { - if (verbose) { - ConsoleInstaller.message("using the gui installer"); - } + verboseOutput("using the gui installer"); new FrameInstaller(commandLine, jarInfo, autotest); } } @@ -375,21 +358,35 @@ } private static void dumpSystemProperties() throws IOException { - @SuppressWarnings("unchecked") - Enumeration<String> names = (Enumeration<String>)System.getProperties().propertyNames(); - StringBuilder contents = new StringBuilder(400); - contents.append("Properties at the beginning of the Jython installation:\n\n"); - while (names.hasMoreElements()) { - String name = names.nextElement(); - String value = System.getProperty(name, ""); - contents.append(name); - contents.append('='); - contents.append(value); - contents.append("\n"); + if (isVerbose()) { + @SuppressWarnings("unchecked") + Enumeration<String> names = (Enumeration<String>)System.getProperties().propertyNames(); + StringBuilder contents = new StringBuilder(400); + contents.append("Properties at the beginning of the Jython installation:\n\n"); + while (names.hasMoreElements()) { + String name = names.nextElement(); + String value = System.getProperty(name, ""); + contents.append(name); + contents.append('='); + contents.append(value); + contents.append("\n"); + } + File output = File.createTempFile("System", ".properties"); + FileHelper.write(output, contents.toString()); + ConsoleInstaller.message("system properties dumped to " + output.getAbsolutePath()); } - File output = File.createTempFile("System", ".properties"); - FileHelper.write(output, contents.toString()); - ConsoleInstaller.message("system properties dumped to " + output.getAbsolutePath()); } + + private static void verboseOutput(String message) { + if (isVerbose()) { + ConsoleInstaller.message(message); + } + } + + private static void verboseOutput(Throwable t) { + if (isVerbose()) { + t.printStackTrace(); + } + } } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-12-13 14:28:08
|
Revision: 5754 http://jython.svn.sourceforge.net/jython/?rev=5754&view=rev Author: otmarhumbel Date: 2008-12-13 14:27:58 +0000 (Sat, 13 Dec 2008) Log Message: ----------- fixed verbosity Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/Installation.java Modified: trunk/installer/src/java/org/python/util/install/Installation.java =================================================================== --- trunk/installer/src/java/org/python/util/install/Installation.java 2008-12-13 14:27:18 UTC (rev 5753) +++ trunk/installer/src/java/org/python/util/install/Installation.java 2008-12-13 14:27:58 UTC (rev 5754) @@ -50,6 +50,10 @@ protected static boolean isVerbose() { return _verbose; } + + protected static void setVerbose(boolean verbose) { + _verbose = verbose; + } protected static boolean isAutotesting() { return _isAutotesting; @@ -321,8 +325,9 @@ */ private static void internalMain(String[] args, Autotest autotest, Tunnel tunnel) { try { - boolean earlyVerbose = InstallerCommandLine.hasVerboseOptionInArgs(args); - if (earlyVerbose) { + setVerbose(InstallerCommandLine.hasVerboseOptionInArgs(args)); + boolean verbose = isVerbose(); + if (verbose) { dumpSystemProperties(); ConsoleInstaller.message("reading jar info"); } @@ -332,9 +337,8 @@ commandLine.printHelp(); System.exit(1); } else { - _verbose = commandLine.hasVerboseOption(); if (commandLine.hasAutotestOption()) { - if (isVerbose()) { + if (verbose) { ConsoleInstaller.message("running autotests"); } _isAutotesting = true; @@ -345,7 +349,7 @@ System.exit(0); } if (!useGui(commandLine)) { - if (isVerbose()) { + if (verbose) { ConsoleInstaller.message("using the console installer"); } ConsoleInstaller consoleInstaller = new ConsoleInstaller(commandLine, jarInfo); @@ -355,7 +359,7 @@ System.exit(0); } } else { - if (isVerbose()) { + if (verbose) { ConsoleInstaller.message("using the gui installer"); } new FrameInstaller(commandLine, jarInfo, autotest); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-12-13 14:27:25
|
Revision: 5753 http://jython.svn.sourceforge.net/jython/?rev=5753&view=rev Author: otmarhumbel Date: 2008-12-13 14:27:18 +0000 (Sat, 13 Dec 2008) Log Message: ----------- allow switching to a different java version for verification, e.g: -A -j /System/Library/Frameworks/JavaVM.framework/Versions/1.6.0/Home Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java Modified: trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java 2008-12-13 07:33:55 UTC (rev 5752) +++ trunk/installer/src/java/org/python/util/install/driver/NormalVerifier.java 2008-12-13 14:27:18 UTC (rev 5753) @@ -214,7 +214,7 @@ StringTokenizer tokenizer = new StringTokenizer(error, "\n"); while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); - if (line.startsWith("*sys-package-mgr*")) { + if (isExpectedError(line)) { feedback(line); } else { throw new DriverException(error); @@ -222,20 +222,29 @@ } } + private boolean isExpectedError(String line) { + boolean expected = false; + if (line.startsWith("*sys-package-mgr*")) { + expected = true; + } else if (line.indexOf("32 bit") >= 0 && line.indexOf("64 bit") >= 0) { + // OS X incompatibility message when using -A -j java1.6.0 from java1.5.0 + expected = true; + } + return expected; + } + private void verifyOutput(String output) throws DriverException { boolean started = false; StringTokenizer tokenizer = new StringTokenizer(output, "\n"); while (tokenizer.hasMoreTokens()) { String line = tokenizer.nextToken(); - if (line.startsWith("[ChildProcess]") || line.startsWith(VERIFYING)) { + if (isExpectedOutput(line)) { feedback(line); - } else { if (line.startsWith(JYTHON_UP)) { started = true; - feedback(line); - } else { - throw new DriverException(output); } + } else { + throw new DriverException(output); } } if (!started) { @@ -243,6 +252,16 @@ } } + private boolean isExpectedOutput(String line) { + boolean expected = false; + if (line.startsWith("[ChildProcess]") || line.startsWith(VERIFYING)) { + expected = true; + } else if (line.startsWith(JYTHON_UP)) { + expected = true; + } + return expected; + } + private String getTestScript() { StringBuilder b = new StringBuilder(80); b.append("import sys\n"); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-12-13 07:34:01
|
Revision: 5752 http://jython.svn.sourceforge.net/jython/?rev=5752&view=rev Author: cgroves Date: 2008-12-13 07:33:55 +0000 (Sat, 13 Dec 2008) Log Message: ----------- Move test087 into test_java_integration, and test088 and test090 are tested by test_java_integration and test_imp_jy respectively Modified Paths: -------------- trunk/jython/Lib/test/test_java_integration.py Removed Paths: ------------- trunk/jython/bugtests/classes/test090j.java trunk/jython/bugtests/test087.py trunk/jython/bugtests/test087m.py trunk/jython/bugtests/test088.py trunk/jython/bugtests/test088p/ trunk/jython/bugtests/test090.py Modified: trunk/jython/Lib/test/test_java_integration.py =================================================================== --- trunk/jython/Lib/test/test_java_integration.py 2008-12-12 15:46:58 UTC (rev 5751) +++ trunk/jython/Lib/test/test_java_integration.py 2008-12-13 07:33:55 UTC (rev 5752) @@ -99,6 +99,16 @@ return 'name' self.assertEquals('name', String.valueOf(A())) + def test_multiple_inheritance_prohibited(self): + try: + class MultiJava(Dimension, Color): + pass + self.fail("Shouldn't be able to subclass more than one concrete java class") + except TypeError: + pass + + + class SysIntegrationTest(unittest.TestCase): def test_stdout_outputstream(self): out = FileOutputStream(test_support.TESTFN) Deleted: trunk/jython/bugtests/classes/test090j.java =================================================================== --- trunk/jython/bugtests/classes/test090j.java 2008-12-12 15:46:58 UTC (rev 5751) +++ trunk/jython/bugtests/classes/test090j.java 2008-12-13 07:33:55 UTC (rev 5752) @@ -1,16 +0,0 @@ - -public class test090j { - public test090j() { - } - public int barTimesTwo(Bar bar) { - return (2*bar.n); - } - public static class Bar { - public Bar() { - } - public Bar(int n) { - this.n = n; - } - public int n; - } -} \ No newline at end of file Deleted: trunk/jython/bugtests/test087.py =================================================================== --- trunk/jython/bugtests/test087.py 2008-12-12 15:46:58 UTC (rev 5751) +++ trunk/jython/bugtests/test087.py 2008-12-13 07:33:55 UTC (rev 5752) @@ -1,12 +0,0 @@ -""" -Test multiple inheritance of 2 java classes -""" - -import support - -try: - import test087m -except TypeError, e: - support.compare(e, "multiple inheritance") -else: - raise support.TestError("multiple inheritance should fail") Deleted: trunk/jython/bugtests/test087m.py =================================================================== --- trunk/jython/bugtests/test087m.py 2008-12-12 15:46:58 UTC (rev 5751) +++ trunk/jython/bugtests/test087m.py 2008-12-13 07:33:55 UTC (rev 5752) @@ -1,10 +0,0 @@ -""" -Test multiple inheritance of 2 java classes -""" - -import support - -import java -class T(java.awt.Panel, java.awt.event.MouseAdapter): - def __init__(self): - pass Deleted: trunk/jython/bugtests/test088.py =================================================================== --- trunk/jython/bugtests/test088.py 2008-12-12 15:46:58 UTC (rev 5751) +++ trunk/jython/bugtests/test088.py 2008-12-13 07:33:55 UTC (rev 5752) @@ -1,10 +0,0 @@ -""" -Check namespace of code running in a module __init__.py -""" - -import support - -import test088p - -r = test088p.foobase.doit() -support.compare(r, "Done") Deleted: trunk/jython/bugtests/test090.py =================================================================== --- trunk/jython/bugtests/test090.py 2008-12-12 15:46:58 UTC (rev 5751) +++ trunk/jython/bugtests/test090.py 2008-12-13 07:33:55 UTC (rev 5752) @@ -1,16 +0,0 @@ -""" -Access to innerclasses -""" - -import support - -support.compileJava("classes/test090j.java") - -import test090j - -foo = test090j() -bar = test090j.Bar() -bar.n = 10 -r = foo.barTimesTwo(bar) - -support.compare(r, "20") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: Alan K. <jyt...@xh...> - 2008-12-12 16:04:55
|
Hi Frank, I should have kept ye all more up to date. I've got most of the outstanding issues with modjy and 2.5b0 resolved, except for the failing import test cases. I finally have more free time; contract finished today, off on a sun vacation tomorrow, where I plan to spend time on modjy and jython stuff in general. I hope to have it all resolved soon. I suppose I should be working on this new branch? Al. On Fri, Dec 12, 2008 at 3:38 PM, <fwi...@us...> wrote: > Revision: 5750 > http://jython.svn.sourceforge.net/jython/?rev=5750&view=rev > Author: fwierzbicki > Date: 2008-12-12 15:38:47 +0000 (Fri, 12 Dec 2008) > > Log Message: > ----------- > Branch to look at tighter integration of modjy. > > Added Paths: > ----------- > branches/modjy/ > > > This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. > > ------------------------------------------------------------------------------ > SF.Net email is Sponsored by MIX09, March 18-20, 2009 in Las Vegas, Nevada. > The future of the web can't happen without you. Join us at MIX09 to help > pave the way to the Next Web now. Learn more and register at > http://ad.doubleclick.net/clk;208669438;13503038;i?http://2009.visitmix.com/ > _______________________________________________ > Jython-checkins mailing list > Jyt...@li... > https://lists.sourceforge.net/lists/listinfo/jython-checkins > |
From: <fwi...@us...> - 2008-12-12 15:47:03
|
Revision: 5751 http://jython.svn.sourceforge.net/jython/?rev=5751&view=rev Author: fwierzbicki Date: 2008-12-12 15:46:58 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Dropping modjy code directly into Lib. Needed to move the code formerly in modjy.py into __init__.py in order to have a toplevel modjy/ dir (current modjy goes directly into a root namespace). Dropping com/xhaus/modjy/ModjyServlet.java into Jython's src dir, keeping com/xhaus/modjy packaging as requested by Alan Kennedy, the author of modjy. Added Paths: ----------- branches/modjy/Lib/modjy/ branches/modjy/Lib/modjy/__init__.py branches/modjy/Lib/modjy/modjy_exceptions.py branches/modjy/Lib/modjy/modjy_impl.py branches/modjy/Lib/modjy/modjy_log.py branches/modjy/Lib/modjy/modjy_params.py branches/modjy/Lib/modjy/modjy_publish.py branches/modjy/Lib/modjy/modjy_response.py branches/modjy/Lib/modjy/modjy_write.py branches/modjy/Lib/modjy/modjy_wsgi.py branches/modjy/src/com/xhaus/ branches/modjy/src/com/xhaus/modjy/ branches/modjy/src/com/xhaus/modjy/ModjyJServlet.java Added: branches/modjy/Lib/modjy/__init__.py =================================================================== --- branches/modjy/Lib/modjy/__init__.py (rev 0) +++ branches/modjy/Lib/modjy/__init__.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,119 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +__all__ = ['modjy', 'modjy_exceptions', 'modjy_impl', 'modjy_log', 'modjy_params', 'modjy_publish', 'modjy_response', 'modjy_write', 'modjy_wsgi',] + +import jarray +import synchronize +import sys +import types + +sys.add_package("javax.servlet") +sys.add_package("javax.servlet.http") +sys.add_package("org.python.core") + +from modjy_exceptions import * +from modjy_log import * +from modjy_params import modjy_param_mgr, modjy_servlet_params +from modjy_wsgi import modjy_wsgi +from modjy_response import start_response_object +from modjy_impl import modjy_impl +from modjy_publish import modjy_publisher + +from javax.servlet.http import HttpServlet + +class modjy_servlet(HttpServlet, modjy_publisher, modjy_wsgi, modjy_impl): + + def __init__(self): + HttpServlet.__init__(self) + + def do_param(self, name, value): + if name[:3] == 'log': + getattr(self.log, "set_%s" % name)(value) + else: + self.params[name] = value + + def get_params(self): + for pname in self.servlet_context.getInitParameterNames(): + self.do_param(pname, self.servlet_context.getInitParameter(pname)) + for pname in self.servlet.getInitParameterNames(): + self.do_param(pname, self.servlet.getInitParameter(pname)) + + def init(self, delegator): + self.servlet = delegator + self.servlet_context = self.servlet.getServletContext() + self.servlet_config = self.servlet.getServletConfig() + self.log = modjy_logger(self.servlet_context) + self.params = modjy_param_mgr(modjy_servlet_params) + self.get_params() + self.init_impl() + self.init_publisher() + import modjy_exceptions + self.exc_handler = getattr(modjy_exceptions, '%s_handler' % self.params['exc_handler'])() + + def service (self, req, resp): + wsgi_environ = {} + try: + self.dispatch_to_application(req, resp, wsgi_environ) + except ModjyException, mx: + self.log.error("Exception servicing request: %s" % str(mx)) + typ, value, tb = sys.exc_info()[:] + self.exc_handler.handle(req, resp, wsgi_environ, mx, (typ, value, tb) ) + + def get_j2ee_ns(self, req, resp): + return { + 'servlet': self.servlet, + 'servlet_context': self.servlet_context, + 'servlet_config': self.servlet_config, + 'request': req, + 'response': resp, + } + + def dispatch_to_application(self, req, resp, environ): + app_callable = self.get_app_object(req, environ) + self.set_wsgi_environment(req, resp, environ, self.params, self.get_j2ee_ns(req, resp)) + response_callable = start_response_object(req, resp) + try: + app_return = self.call_application(app_callable, environ, response_callable) + if app_return is None: + raise ReturnNotIterable("Application returned None: must return an iterable") + self.deal_with_app_return(environ, response_callable, app_return) + except ModjyException, mx: + self.raise_exc(mx.__class__, str(mx)) + except Exception, x: + self.raise_exc(ApplicationException, str(x)) + + def call_application(self, app_callable, environ, response_callable): + if self.params['multithread']: + return app_callable.__call__(environ, response_callable) + else: + return synchronize.apply_synchronized( \ + app_callable, \ + app_callable, \ + (environ, response_callable)) + + def expand_relative_path(self, path): + if path.startswith("$"): + return self.servlet.getServletContext().getRealPath(path[1:]) + return path + + def raise_exc(self, exc_class, message): + self.log.error(message) + raise exc_class(message) Added: branches/modjy/Lib/modjy/modjy_exceptions.py =================================================================== --- branches/modjy/Lib/modjy/modjy_exceptions.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_exceptions.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,91 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import sys +import StringIO +import traceback + +from java.lang import IllegalStateException +from java.io import IOException +from javax.servlet import ServletException + +class ModjyException(Exception): pass + +class ModjyIOException(ModjyException): pass + +class ConfigException(ModjyException): pass +class BadParameter(ConfigException): pass +class ApplicationNotFound(ConfigException): pass +class NoCallable(ConfigException): pass + +class RequestException(ModjyException): pass + +class ApplicationException(ModjyException): pass +class StartResponseNotCalled(ApplicationException): pass +class StartResponseCalledTwice(ApplicationException): pass +class ResponseCommitted(ApplicationException): pass +class HopByHopHeaderSet(ApplicationException): pass +class WrongLength(ApplicationException): pass +class BadArgument(ApplicationException): pass +class ReturnNotIterable(ApplicationException): pass +class NonStringOutput(ApplicationException): pass + +class exception_handler: + + def handle(self, req, resp, environ, exc, exc_info): + pass + + def get_status_and_message(self, req, resp, exc): + return resp.SC_INTERNAL_SERVER_ERROR, "Server configuration error" + +# +# Special exception handler for testing +# + +class testing_handler(exception_handler): + + def handle(self, req, resp, environ, exc, exc_info): + typ, value, tb = exc_info + err_msg = StringIO.StringIO() + err_msg.write("%s: %s\n" % (typ, value,) ) + err_msg.write(">Environment\n") + for k in environ.keys(): + err_msg.write("%s=%s\n" % (k, repr(environ[k])) ) + err_msg.write("<Environment\n") + err_msg.write(">TraceBack\n") + for line in traceback.format_exception(typ, value, tb): + err_msg.write(line) + err_msg.write("<TraceBack\n") + try: + status, message = self.get_status_and_message(req, resp, exc) + resp.setStatus(status) + resp.setContentLength(len(err_msg.getvalue())) + resp.getOutputStream().write(err_msg.getvalue()) + except IllegalStateException, ise: + raise exc # Let the container deal with it + +# +# Standard exception handler +# + +class standard_handler(exception_handler): + + def handle(self, req, resp, environ, exc, exc_info): + raise exc Added: branches/modjy/Lib/modjy/modjy_impl.py =================================================================== --- branches/modjy/Lib/modjy/modjy_impl.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_impl.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,101 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import types +import sys + +from modjy_exceptions import * + +class modjy_impl: + + def deal_with_app_return(self, environ, start_response_callable, app_return): + self.log.debug("Processing app return type: %s" % str(type(app_return))) + if isinstance(app_return, types.StringTypes): + raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) + if type(app_return) is types.FileType: + pass # TBD: What to do here? can't call fileno() + if hasattr(app_return, '__len__') and callable(app_return.__len__): + expected_pieces = app_return.__len__() + else: + expected_pieces = -1 + try: + try: + ix = 0 + for next_piece in app_return: + if not isinstance(next_piece, types.StringType): + raise NonStringOutput("Application returned iterable containing non-strings: %s" % str(type(next_piece))) + if ix == 0: + # The application may have called start_response in the first iteration + if not start_response_callable.called: + raise StartResponseNotCalled("Start_response callable was never called.") + if not start_response_callable.content_length \ + and expected_pieces == 1 \ + and start_response_callable.write_callable.num_writes == 0: + # Take the length of the first piece + start_response_callable.set_content_length(len(next_piece)) + start_response_callable.write_callable(next_piece) + ix += 1 + if ix == expected_pieces: + break + if expected_pieces != -1 and ix != expected_pieces: + raise WrongLength("Iterator len() was wrong. Expected %d pieces: got %d" % (expected_pieces, ix) ) + except AttributeError, ax: + if str(ax) == "__getitem__": + raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) + else: + raise ax + except TypeError, tx: + raise ReturnNotIterable("Application returned object that was not an iterable: %s" % str(type(app_return))) + except ModjyException, mx: + raise mx + except Exception, x: + raise ApplicationException(x) + finally: + if hasattr(app_return, 'close') and callable(app_return.close): + app_return.close() + + def init_impl(self): + self.do_j_env_params() + + def add_packages(self, package_list): + packages = [p.strip() for p in package_list.split(';')] + for p in packages: + self.log.info("Adding java package %s to jython" % p) + sys.add_package(p) + + def add_classdirs(self, classdir_list): + classdirs = [cd.strip() for cd in classdir_list.split(';')] + for cd in classdirs: + self.log.info("Adding directory %s to jython class file search path" % cd) + sys.add_classdir(cd) + + def add_extdirs(self, extdir_list): + extdirs = [ed.strip() for ed in extdir_list.split(';')] + for ed in extdirs: + self.log.info("Adding directory %s for .jars and .zips search path" % ed) + sys.add_extdir(self.expand_relative_path(ed)) + + def do_j_env_params(self): + if self.params['packages']: + self.add_packages(self.params['packages']) + if self.params['classdirs']: + self.add_classdirs(self.params['classdirs']) + if self.params['extdirs']: + self.add_extdirs(self.params['extdirs']) Added: branches/modjy/Lib/modjy/modjy_log.py =================================================================== --- branches/modjy/Lib/modjy/modjy_log.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_log.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,80 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import java + +import sys + +DEBUG = 'debug' +INFO = 'info' +WARN = 'warn' +ERROR = 'error' +FATAL = 'fatal' + +levels_dict = {} +ix = 0 +for level in [DEBUG, INFO, WARN, ERROR, FATAL, ]: + levels_dict[level]=ix + ix += 1 + +class modjy_logger: + + def __init__(self, context): + self.log_ctx = context + self.format_str = "%(lvl)s:\t%(msg)s" + self.log_level = levels_dict[DEBUG] + + def _log(self, level, level_str, msg, exc): + if level >= self.log_level: + msg = self.format_str % {'lvl': level_str, 'msg': msg, } + if exc: +# java.lang.System.err.println(msg, exc) + self.log_ctx.log(msg, exc) + else: +# java.lang.System.err.println(msg) + self.log_ctx.log(msg) + + def debug(self, msg, exc=None): + self._log(0, DEBUG, msg, exc) + + def info(self, msg, exc=None): + self._log(1, INFO, msg, exc) + + def warn(self, msg, exc=None): + self._log(2, WARN, msg, exc) + + def error(self, msg, exc=None): + self._log(3, ERROR, msg, exc) + + def fatal(self, msg, exc=None): + self._log(4, FATAL, msg, exc) + + def set_log_level(self, level_string): + try: + self.level = levels_dict[level_string] + except KeyError: + raise BadParameter("Invalid log level: '%s'" % level_string) + + def set_log_format(self, format_string): + # BUG! Format string never actually used in this function. + try: + self._log(debug, "This is a log formatting test", None) + except KeyError: + raise BadParameter("Bad format string: '%s'" % format_string) Added: branches/modjy/Lib/modjy/modjy_params.py =================================================================== --- branches/modjy/Lib/modjy/modjy_params.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_params.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,84 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +from UserDict import UserDict + +BOOLEAN = ('boolean', int) +INTEGER = ('integer', int) +FLOAT = ('float', float) +STRING = ('string', None) + +modjy_servlet_params = { + + 'multithread': (BOOLEAN, 1), + 'cache_callables': (BOOLEAN, 1), + 'reload_on_mod': (BOOLEAN, 0), + + 'app_import_name': (STRING, None), + + 'app_directory': (STRING, None), + 'app_filename': (STRING, 'application.py'), + 'app_callable_name': (STRING, 'handler'), + 'callable_query_name': (STRING, None), + + 'exc_handler': (STRING, 'standard'), + + 'log_level': (STRING, 'info'), + + 'packages': (STRING, None), + 'classdirs': (STRING, None), + 'extdirs': (STRING, None), + + 'initial_env': (STRING, None), +} + +class modjy_param_mgr(UserDict): + + def __init__(self, param_types): + UserDict.__init__(self) + self.param_types = param_types + for pname in self.param_types.keys(): + typ, default = self.param_types[pname] + self.__setitem__(pname, default) + + def __getitem__(self, name): + return self._get_defaulted_value(name) + + def __setitem__(self, name, value): + self.data[name] = self._convert_value(name, value) + + def _convert_value(self, name, value): + if self.param_types.has_key(name): + typ, default = self.param_types[name] + typ_str, typ_func = typ + if typ_func: + try: + return typ_func(value) + except ValueError: + raise BadParameter("Illegal value for %s parameter '%s': %s" % (typ_str, name, value) ) + return value + + def _get_defaulted_value(self, name): + if self.data.has_key(name): + return self.data[name] + if self.param_types.has_key(name): + typ, default = self.param_types[name] + return default + raise KeyError(name) Added: branches/modjy/Lib/modjy/modjy_publish.py =================================================================== --- branches/modjy/Lib/modjy/modjy_publish.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_publish.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,142 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import sys +import synchronize + +from java.io import File + +from modjy_exceptions import * + +class modjy_publisher: + + def init_publisher(self): + self.cache = None + if self.params['app_directory']: + self.app_directory = self.expand_relative_path(self.params['app_directory']) + else: + self.app_directory = self.servlet_context.getRealPath('/') + self.params['app_directory'] = self.app_directory + if not self.app_directory in sys.path: + sys.path.append(self.app_directory) + + def map_uri(self, req, environ): + script_name = "%s%s" % (req.getContextPath(), req.getServletPath()) + path_info = req.getPathInfo() or "" + source_uri = '%s%s%s' % (self.app_directory, File.separator, self.params['app_filename']) + callable_name = self.params['app_callable_name'] + if self.params['callable_query_name']: + query_string = req.getQueryString() + if query_string and '=' in query_string: + for name_val in query_string.split('&'): + name, value = name_val.split('=') + if name == self.params['callable_query_name']: + callable_name = value + environ["SCRIPT_NAME"] = script_name + environ["PATH_INFO"] = path_info + environ["PATH_TRANSLATED"] = File(self.app_directory, path_info).getPath() + return source_uri, callable_name + + def get_app_object(self, req, environ): + if self.params['app_import_name'] is not None: + return self.get_app_object_importable(self.params['app_import_name']) + else: + if self.cache is None: + self.cache = {} + return self.get_app_object_old_style(req, environ) + + get_app_object = synchronize.make_synchronized(get_app_object) + + def get_app_object_importable(self, importable_name): + self.log.debug("Attempting to import application callable '%s'\n" % (importable_name, )) + # Under the importable mechanism, the cache contains a single object + if self.cache is None: + application, instantiable, method_name = self.load_importable(importable_name.strip()) + if instantiable and self.params['cache_callables']: + application = application() + self.cache = application, instantiable, method_name + application, instantiable, method_name = self.cache + self.log.debug("Application is " + str(application)) + if instantiable and not self.params['cache_callables']: + application = application() + self.log.debug("Instantiated application is " + str(application)) + if method_name is not None: + application = getattr(application, method_name) + self.log.debug("Application method is " + str(application)) + return application + + def load_importable(self, name): + try: + instantiable = False ; method_name = None + names = name.split('.') ; names.reverse() + imported = __import__(names.pop()) + while names: + n = names.pop() + if n.endswith("()"): + n = n[:-2] ; instantiable = True + self.log.debug("importable '%s' is instantiable." % n) + if len(names) > 1: + names.reverse() + message = "Failed to import '%s': '%s' is not a valid method name" % (name, ".".join(names)) + self.log.error(message) + self.raise_exc(ApplicationNotFound, message) + elif len(names) == 1: + method_name = names.pop() + else: + method_name = None + imported = getattr(imported, n) + self.log.debug("Imported '%s' from '%s'\n" % (n, str(imported))) + return imported, instantiable, method_name + except (ImportError, AttributeError), aix: + self.log.fatal("Import error import application callable '%s': %s\n" % (name, str(aix))) + self.raise_exc(ApplicationNotFound, "Failed to import app callable '%s': %s" % (name, str(aix))) + + def get_app_object_old_style(self, req, environ): + source_uri, callable_name = self.map_uri(req, environ) + source_filename = source_uri + if not self.params['cache_callables']: + self.log.debug("Caching of callables disabled") + return self.load_object(source_filename, callable_name) + if not self.cache.has_key( (source_filename, callable_name) ): + self.log.debug("Callable object not in cache: %s#%s" % (source_filename, callable_name) ) + return self.load_object(source_filename, callable_name) + app_callable, last_mod = self.cache.get( (source_filename, callable_name) ) + self.log.debug("Callable object was in cache: %s#%s" % (source_filename, callable_name) ) + if self.params['reload_on_mod']: + f = File(source_filename) + if f.lastModified() > last_mod: + self.log.info("Source file '%s' has been modified: reloading" % source_filename) + return self.load_object(source_filename, callable_name) + return app_callable + + def load_object(self, path, callable_name): + try: + app_ns = {} ; execfile(path, app_ns) + app_callable = app_ns[callable_name] + f = File(path) + self.cache[ (path, callable_name) ] = (app_callable, f.lastModified()) + return app_callable + except IOError, ioe: + self.raise_exc(ApplicationNotFound, "Application filename not found: %s" % path) + except KeyError, k: + self.raise_exc(NoCallable, "No callable named '%s' in %s" % (callable_name, path)) + except Exception, x: + self.raise_exc(NoCallable, "Error loading jython callable '%s': %s" % (callable_name, str(x)) ) + Added: branches/modjy/Lib/modjy/modjy_response.py =================================================================== --- branches/modjy/Lib/modjy/modjy_response.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_response.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,113 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import types + +from java.lang import System + +from modjy_exceptions import * +from modjy_write import write_object + +# From: http://www.w3.org/Protocols/rfc2616/rfc2616-sec13.html#sec13.5.1 + +hop_by_hop_headers = { + 'connection': None, + 'keep-alive': None, + 'proxy-authenticate': None, + 'proxy-authorization': None, + 'te': None, + 'trailers': None, + 'transfer-encoding': None, + 'upgrade': None, +} + +class start_response_object: + + def __init__(self, req, resp): + self.http_req = req + self.http_resp = resp + self.write_callable = None + self.called = 0 + self.content_length = None + + # I'm doing the parameters this way to facilitate porting back to java + def __call__(self, *args, **keywords): + if len(args) < 2 or len(args) > 3: + raise BadArgument("Start response callback requires either two or three arguments: got %s" % str(args)) + if len(args) == 3: + exc_info = args[2] + try: + try: + self.http_resp.reset() + except IllegalStateException, isx: + raise exc_info[0], exc_info[1], exc_info[2] + finally: + exc_info = None + else: + if self.called > 0: + raise StartResponseCalledTwice("Start response callback may only be called once, without exception information.") + status_str = args[0] + headers_list = args[1] + if not isinstance(status_str, types.StringType): + raise BadArgument("Start response callback requires string as first argument") + if not isinstance(headers_list, types.ListType): + raise BadArgument("Start response callback requires list as second argument") + try: + status_code, status_message_str = status_str.split(" ", 1) + self.http_resp.setStatus(int(status_code)) + except ValueError: + raise BadArgument("Status string must be of the form '<int> <string>'") + self.make_write_object() + try: + for header_name, header_value in headers_list: + header_name_lower = header_name.lower() + if hop_by_hop_headers.has_key(header_name_lower): + raise HopByHopHeaderSet("Under WSGI, it is illegal to set hop-by-hop headers, i.e. '%s'" % header_name) + if header_name_lower == "content-length": + try: + self.set_content_length(int(header_value)) + except ValueError, v: + raise BadArgument("Content-Length header value must be a string containing an integer, not '%s'" % header_value) + else: + final_value = header_value.encode('latin-1') + # Here would be the place to check for control characters, whitespace, etc + self.http_resp.addHeader(header_name, final_value) + except (AttributeError, TypeError), t: + raise BadArgument("Start response callback headers must contain a list of (<string>,<string>) tuples") + except UnicodeError, u: + raise BadArgument("Encoding error: header values may only contain latin-1 characters, not '%s'" % repr(header_value)) + except ValueError, v: + raise BadArgument("Headers list must contain 2-tuples") + self.called += 1 + return self.write_callable + + def set_content_length(self, length): + if self.write_callable.num_writes == 0: + self.content_length = length + self.http_resp.setContentLength(length) + else: + raise ResponseCommitted("Cannot set content-length: response is already commited.") + + def make_write_object(self): + try: + self.write_callable = write_object(self.http_resp.getOutputStream()) + except IOException, iox: + raise IOError(iox) + return self.write_callable Added: branches/modjy/Lib/modjy/modjy_write.py =================================================================== --- branches/modjy/Lib/modjy/modjy_write.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_write.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,43 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +import types + +from modjy_exceptions import * + +class write_object: + + def __init__(self, ostream): + self.ostream = ostream + self.num_writes = 0 + + def __call__(self, *args, **keywords): + if len(args) != 1 or type(args[0]) is not types.StringType: + raise NonStringOutput("Invocation of write callable requires exactly one string argument") + try: + self.ostream.write(args[0]) # Jython implicitly converts the (binary) string to a byte array + # WSGI requires that all output be flushed before returning to the application + # According to the java docs: " The flush method of OutputStream does nothing." + # Still, leave it in place for now: it's in the right place should this + # code ever be ported to another platform. + self.ostream.flush() + self.num_writes += 1 + except Exception, x: + raise ModjyIOException(x) Added: branches/modjy/Lib/modjy/modjy_wsgi.py =================================================================== --- branches/modjy/Lib/modjy/modjy_wsgi.py (rev 0) +++ branches/modjy/Lib/modjy/modjy_wsgi.py 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,143 @@ +### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://modjy.xhaus.com/LICENSE.txt +# +### + +from java.lang import System +from org.python.core import PyFile + +from modjy_exceptions import * + +server_name = "modjy" +server_param_prefix = "%s.param" % server_name +j2ee_ns_prefix = "j2ee" + +class modjy_wsgi: + + # + # WSGI constants + # + + empty_pystring = "" + wsgi_version = (1,0) + + # + # Container-specific constants + # + + modjy_version = (0, 22, 3) + + def set_string_envvar(self, dict, name, value, default_value): + if value == default_value: + dict[name] = self.empty_pystring + else: + dict[name] = value + + def set_string_envvar_optional(self, dict, name, value, default_value): + if value != default_value: + dict[name] = str(value) + + def set_int_envvar(self, dict, name, value, default_value): + if value == default_value: + dict[name] = self.empty_pystring + else: + dict[name] = str(value) + + def set_container_specific_wsgi_vars(self, req, resp, dict, params): + dict["%s.version" % server_name] = self.modjy_version + for pname in params.keys(): + dict["%s.%s" % (server_param_prefix, pname)] = params[pname] + + def set_j2ee_specific_wsgi_vars(self, dict, j2ee_ns): + for p in j2ee_ns.keys(): + dict["%s.%s" % (j2ee_ns_prefix, p)] = j2ee_ns[p] + + def set_required_cgi_environ (self, req, resp, dict): + self.set_string_envvar(dict, "REQUEST_METHOD", req.getMethod(), None) + self.set_string_envvar(dict, "QUERY_STRING", req.getQueryString(), None) + self.set_string_envvar(dict, "CONTENT_TYPE", req.getContentType(), None) + self.set_int_envvar(dict, "CONTENT_LENGTH", req.getContentLength(), -1) + self.set_string_envvar(dict, "SERVER_NAME", req.getLocalName(), None) + self.set_int_envvar(dict, "SERVER_PORT", req.getLocalPort(), 0) + + def set_other_cgi_environ (self, req, resp, dict): + if req.isSecure(): + self.set_string_envvar(dict, "HTTPS", 'on', None) + else: + self.set_string_envvar(dict, "HTTPS", 'off', None) + self.set_string_envvar(dict, "SERVER_PROTOCOL", req.getProtocol(), None) + self.set_string_envvar(dict, "REMOTE_HOST", req.getRemoteHost(), None) + self.set_string_envvar(dict, "REMOTE_ADDR", req.getRemoteAddr(), None) + self.set_int_envvar(dict, "REMOTE_PORT", req.getRemotePort(), -1) + self.set_string_envvar_optional(dict, "AUTH_TYPE", req.getAuthType(), None) + self.set_string_envvar_optional(dict, "REMOTE_USER", req.getRemoteUser(), None) + + def set_http_header_environ(self, req, resp, dict): + for curr_header_name in req.getHeaderNames(): + values = None + for next_value in req.getHeaders(curr_header_name): + if values is None: + values = next_value + else: + if isinstance(values, types.ListType): + values.append(next_value) + else: + values = [values] + dict["HTTP_%s" % curr_header_name.replace('-', '_').upper()] = values + + def set_required_wsgi_vars(self, req, resp, dict): + dict["wsgi.version"] = self.wsgi_version + dict["wsgi.url_scheme"] = req.getScheme() + dict["wsgi.multithread"] = \ + int(dict["%s.cache_callables" % server_param_prefix]) \ + and \ + int(dict["%s.multithread" % server_param_prefix]) + dict["wsgi.multiprocess"] = self.wsgi_multiprocess = 0 + dict["wsgi.run_once"] = not(dict["%s.cache_callables" % server_param_prefix]) + + def set_wsgi_streams(self, req, resp, dict): + try: + dict["wsgi.input"] = PyFile(req.getInputStream()) + dict["wsgi.errors"] = PyFile(System.err) + except IOException, iox: + raise ModjyIOException(iox) + + def set_wsgi_classes(self, req, resp, dict): + # dict["wsgi.file_wrapper"] = modjy_file_wrapper + pass + + def set_user_specified_environment(self, req, resp, wsgi_environ, params): + if not params.has_key('initial_env') or not params['initial_env']: + return + user_env_string = params['initial_env'] + for l in user_env_string.split('\n'): + l = l.strip() + if l: + name, value = l.split(':', 1) + wsgi_environ[name.strip()] = value.strip() + + def set_wsgi_environment(self, req, resp, wsgi_environ, params, j2ee_ns): + self.set_container_specific_wsgi_vars(req, resp, wsgi_environ, params) + self.set_j2ee_specific_wsgi_vars(wsgi_environ, j2ee_ns) + self.set_required_cgi_environ(req, resp, wsgi_environ) + self.set_other_cgi_environ(req, resp, wsgi_environ) + self.set_http_header_environ(req, resp, wsgi_environ) + self.set_required_wsgi_vars(req, resp, wsgi_environ) + self.set_wsgi_streams(req, resp, wsgi_environ) + self.set_wsgi_classes(req, resp, wsgi_environ) + self.set_user_specified_environment(req, resp, wsgi_environ, params) Added: branches/modjy/src/com/xhaus/modjy/ModjyJServlet.java =================================================================== --- branches/modjy/src/com/xhaus/modjy/ModjyJServlet.java (rev 0) +++ branches/modjy/src/com/xhaus/modjy/ModjyJServlet.java 2008-12-12 15:46:58 UTC (rev 5751) @@ -0,0 +1,217 @@ +/*### +# +# Copyright 2004-2008 Alan Kennedy. +# +# You may contact the copyright holder at this uri: +# +# http://www.xhaus.com/contact/modjy +# +# The licence under which this code is released is the Apache License v2.0. +# +# The terms and conditions of this license are listed in a file contained +# in the distribution that also contained this file, under the name +# LICENSE.txt. +# +# You may also read a copy of the license at the following web address. +# +# http://www.xhaus.com/modjy/LICENSE.txt +# +###*/ + +package com.xhaus.modjy; + +import java.io.*; +import java.util.*; +import javax.servlet.*; +import javax.servlet.http.*; +import org.python.core.*; +import org.python.util.*; + +public class ModjyJServlet extends HttpServlet +{ + + protected final static String MODJY_PYTHON_CLASSNAME = "modjy_servlet"; + protected final static String LIB_PYTHON = "/WEB-INF/lib-python"; + protected final static String PTH_FILE_EXTENSION = ".pth"; + + protected PythonInterpreter interp; + protected HttpServlet modjyServlet; + + /** + * Read configuration + * 1. Both context and servlet parameters are included in the set, + * so that the definition of some parameters (e.g python.*) can be shared + * between multiple WSGI servlets. + * 2. servlet params take precedence over context parameters + */ + + protected Properties readConfiguration ( ) + { + Properties props = new Properties(); + // Context parameters + ServletContext context = getServletContext(); + Enumeration e = context.getInitParameterNames(); + while (e.hasMoreElements()) + { + String name = (String) e.nextElement(); + props.put(name, context.getInitParameter(name)); + } + // Servlet parameters override context parameters + e = getInitParameterNames(); + while (e.hasMoreElements()) + { + String name = (String) e.nextElement(); + props.put(name, getInitParameter(name)); + } + return props; + } + + /** + * Initialise the modjy servlet. + * 1. Read the configuration + * 2. Initialise the jython runtime + * 3. Setup, in relation to the J2EE servlet environment + * 4. Create the jython-implemented servlet + * 5. Initialise the jython-implemented servlet + */ + + public void init ( ) + throws ServletException + { + try + { + Properties props = readConfiguration(); + PythonInterpreter.initialize(System.getProperties(), props, new String[0]); + interp = new PythonInterpreter(null, new PySystemState()); + String modjyJarLocation = setupEnvironment(props, Py.getSystemState()); + try + { interp.exec("from modjy import "+MODJY_PYTHON_CLASSNAME); } + catch (PyException ix) + { throw new ServletException("Unable to import '"+MODJY_PYTHON_CLASSNAME+"' from "+modjyJarLocation+ + ": do you maybe need to set the 'modjy_jar.location' parameter?");} + PyObject pyServlet = ((PyClass)interp.get(MODJY_PYTHON_CLASSNAME)).__call__(); + Object temp = pyServlet.__tojava__(HttpServlet.class); + if (temp == Py.NoConversion) + throw new ServletException("Corrupted modjy file: cannot find definition of '"+MODJY_PYTHON_CLASSNAME+"' class"); + modjyServlet = (HttpServlet) temp; + modjyServlet.init(this); + } + catch (PyException pyx) + { + throw new ServletException("Exception creating modjy servlet: " + pyx.toString(), pyx); + } + } + + /** + * Actually service the incoming request. + * Simply delegate to the jython servlet. + * + * @param request - The incoming HttpServletRequest + * @param response - The outgoing HttpServletResponse + */ + + public void service ( HttpServletRequest req, HttpServletResponse resp ) + throws ServletException, IOException + { + modjyServlet.service(req, resp); + } + + /** + * Setup the modjy environment, i.e. + * 1. Find the location of the modjy.jar file and add it to sys.path + * 2. Process the WEB-INF/lib-python directory, if it exists + * + * @param props The properties from which config options are found + * @param systemState The PySystemState corresponding to the interpreter servicing requests + * @returns A String giving the path to the modjy.jar file (which is used only for error reporting) + */ + + protected String setupEnvironment(Properties props, PySystemState systemState) + { + String modjyJarLocation = locateModjyJar(props); + systemState.path.append(new PyString(modjyJarLocation)); + processPythonLib(systemState); + return modjyJarLocation; + } + + /** + * Find out the location of "modjy.jar", so that it can + * be added to the sys.path and thus imported + * + * @param The properties from which config options are found + * @returns A String giving the path to the modjy.jar file + */ + + protected String locateModjyJar ( Properties props ) + { + // Give priority to modjy_jar.location + if (props.get("modjy_jar.location") != null) + return (String)props.get("modjy_jar.location"); + // Then try to find it in WEB-INF/lib + String location = getServletContext().getRealPath("/WEB-INF/lib/modjy.jar"); + if (location != null) + { + File f = new File(location); + if (f.exists()) + return location; + } + // Try finding the archive that this class was loaded from + try + { return this.getClass().getProtectionDomain().getCodeSource().getLocation().getFile(); } + catch (Exception x) + { return null;} + } + + /** + * Do all processing in relation to the lib-python subdirectory of WEB-INF + * + * @param systemState - The PySystemState whose path should be updated + */ + + protected void processPythonLib(PySystemState systemState) + { + // Add the lib-python directory to sys.path + String pythonLibPath = getServletContext().getRealPath(LIB_PYTHON); + if (pythonLibPath == null) + return; + File pythonLib = new File(pythonLibPath); + if (!pythonLib.exists()) + return; + systemState.path.append(new PyString(pythonLibPath)); + // Now check for .pth files in lib-python and process each one + String[] libPythonContents = pythonLib.list(); + for (int ix = 0 ; ix < libPythonContents.length ; ix++) + if (libPythonContents[ix].endsWith(PTH_FILE_EXTENSION)) + processPthFile(systemState, pythonLibPath, libPythonContents[ix]); + } + + /** + * Process an individual file .pth file in the lib-python directory + * + * @param systemState - The PySystemState whose path should be updated + * @param pythonLibPath - The actual path to the lib-python directory + * @param pthFilename - The PySystemState whose path should be updated + */ + + protected void processPthFile(PySystemState systemState, String pythonLibPath, String pthFilename) + { + try + { + LineNumberReader lineReader = new LineNumberReader(new FileReader(new File(pythonLibPath, pthFilename))); + String line; + while ((line = lineReader.readLine()) != null) + { + line = line.trim(); + if (line.startsWith("#")) + continue; + File archiveFile = new File(pythonLibPath, line); + String archiveRealpath = archiveFile.getAbsolutePath(); + systemState.path.append(new PyString(archiveRealpath)); + } + } + catch (IOException iox) + { + System.err.println("IOException: " + iox.toString()); + } + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-12 15:38:52
|
Revision: 5750 http://jython.svn.sourceforge.net/jython/?rev=5750&view=rev Author: fwierzbicki Date: 2008-12-12 15:38:47 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Branch to look at tighter integration of modjy. Added Paths: ----------- branches/modjy/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-12 15:26:56
|
Revision: 5749 http://jython.svn.sourceforge.net/jython/?rev=5749&view=rev Author: fwierzbicki Date: 2008-12-12 15:26:50 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Delete astwrite branch, it is fully merged with trunk and no longer useful. Removed Paths: ------------- branches/astwrite/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-12-12 15:15:43
|
Revision: 5748 http://jython.svn.sourceforge.net/jython/?rev=5748&view=rev Author: fwierzbicki Date: 2008-12-12 15:15:38 +0000 (Fri, 12 Dec 2008) Log Message: ----------- Removed merge tracking for "svnmerge" for https://jython.svn.sourceforge.net/svnroot/jython/branches/astwrite Property Changed: ---------------- trunk/jython/ Property changes on: trunk/jython ___________________________________________________________________ Deleted: svnmerge-integrated - /branches/astwrite:1-5692 This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |