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: <pj...@us...> - 2008-08-06 18:45:55
|
Revision: 5096 http://jython.svn.sourceforge.net/jython/?rev=5096&view=rev Author: pjenvey Date: 2008-08-06 18:45:50 +0000 (Wed, 06 Aug 2008) Log Message: ----------- fix zipimport not handling mismatched APIVersion, and imp.load_module not handling it either for packages Modified Paths: -------------- branches/asm/src/org/python/modules/imp.java branches/asm/src/org/python/modules/zipimport/zipimporter.java Modified: branches/asm/src/org/python/modules/imp.java =================================================================== --- branches/asm/src/org/python/modules/imp.java 2008-08-06 18:15:17 UTC (rev 5095) +++ branches/asm/src/org/python/modules/imp.java 2008-08-06 18:45:50 UTC (rev 5096) @@ -212,7 +212,7 @@ m.__dict__.__setitem__("__path__", new PyList(new PyObject[] { filename })); m.__dict__.__setitem__("__file__", filename); - ModuleInfo mi = findFromSource(name, filename.toString(), true, false); + ModuleInfo mi = findFromSource(name, filename.toString(), true, true); type = mi.type; file = mi.file; filename = new PyString(mi.filename); Modified: branches/asm/src/org/python/modules/zipimport/zipimporter.java =================================================================== --- branches/asm/src/org/python/modules/zipimport/zipimporter.java 2008-08-06 18:15:17 UTC (rev 5095) +++ branches/asm/src/org/python/modules/zipimport/zipimporter.java 2008-08-06 18:45:50 UTC (rev 5096) @@ -417,11 +417,13 @@ } zipBundle.close(); + if (codeBytes == null) { + // bad magic number or non-matching mtime in byte code, try next + continue; + } + imp.cacheCompiledSource(pathToEntry, null, codeBytes); PyCode code = BytecodeLoader.makeCode(fullname + "$py", codeBytes, pathToEntry); - if (code == null) { - continue; - } return new ModuleCodeData(code, ispackage, pathToEntry); } return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 18:15:21
|
Revision: 5095 http://jython.svn.sourceforge.net/jython/?rev=5095&view=rev Author: fwierzbicki Date: 2008-08-06 18:15:17 +0000 (Wed, 06 Aug 2008) Log Message: ----------- improved jarjar conditional -- but made build.xml slightly more impenetrable. Sigh. Modified Paths: -------------- branches/asm/build.xml Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-08-06 17:54:07 UTC (rev 5094) +++ branches/asm/build.xml 2008-08-06 18:15:17 UTC (rev 5095) @@ -319,6 +319,8 @@ want to comment this out, as a clean is really only needed if you change the tokens defined in Python.g (and cleans make the build slow) --> <antcall target="clean"/> + <!-- force jarjar build --> + <property name="jarjar.needed" value="true" /> </target> <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> @@ -508,7 +510,7 @@ includesfile="${jython.base.dir}/CoreExposed.includes"/> </target> - <target name="jarjar" depends="init,needed-check" unless="jarjar.notneeded,antlr.notneeded"> + <target name="jarjar" depends="init,needed-check" if="jarjar.needed" unless="jarjar.notneeded"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="extlibs/jarjar-0.7.jar"/> <jarjar destfile="${output.dir}/jarjar.jar"> <zipfileset src="extlibs/antlr-runtime-3.1b2.jar"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 17:54:11
|
Revision: 5094 http://jython.svn.sourceforge.net/jython/?rev=5094&view=rev Author: fwierzbicki Date: 2008-08-06 17:54:07 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Changed grammars to allow most keywords to be used as attributes for Java compatibility. Also added some tests. Removed a couple of tests that use keywords as function names as this is no longer permitted. Allowing keywords to be used as arbitrary NAMEs causes very weird grammar issues. For example for x, in ((1,),(2,)): matched "x, in" as a tuple. Now the permitted use is limited to things like foo.in() Modified Paths: -------------- branches/asm/Lib/test/test_grammar_jy.py branches/asm/Lib/test/test_java_integration.py branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/Lib/test/test_grammar_jy.py =================================================================== --- branches/asm/Lib/test/test_grammar_jy.py 2008-08-06 13:05:15 UTC (rev 5093) +++ branches/asm/Lib/test/test_grammar_jy.py 2008-08-06 17:54:07 UTC (rev 5094) @@ -1,27 +1,10 @@ -"""Tests whether Python keywords that are *not* Java keywords can be used - as method names (needed for Java integration -- for example, if a Java - method is named "print" and we want to use it from Jython). - -Made for Jython. +""" Extra grammar tests for Jython. """ import test_support import unittest -class Keywords(object): - def exec(self): - exec "2+2" - return "success" - - def as(self): - import unittest as eggs - return "success" - class GrammarTest(unittest.TestCase): - def testKeywords(self): - kws = Keywords() - self.assertEquals("success", kws.exec()) - self.assertEquals("success", kws.as()) def testStringPrefixes(self): self.assertEquals(u"spam",U"spam") Modified: branches/asm/Lib/test/test_java_integration.py =================================================================== --- branches/asm/Lib/test/test_java_integration.py 2008-08-06 13:05:15 UTC (rev 5093) +++ branches/asm/Lib/test/test_java_integration.py 2008-08-06 17:54:07 UTC (rev 5094) @@ -172,14 +172,51 @@ class ReservedNamesTest(unittest.TestCase): "Access to java names which are al reserved words" - def test_system_in(self): + def test_in(self): s = System.in self.assert_("java.io.BufferedInputStream" in str(s)) - def test_runtime_exec(self): + def test_exec(self): e = Runtime.getRuntime().exec self.assert_(re.search("method .*exec", str(e)) is not None) + def test_class(self): + b = Byte(10) + self.assert_("java.lang.Byte" in str(b.class)) + + def test_print(self): + #XXX should find a better print test. + System.out.print("") + + #TODO: + #and + #as + #assert + #break + #continue + #def + #del + #elif + #else + #except + #finally + #from + #for + #global + #if + #import + #is + #lambda + #pass + #print + #raise + #return + #try + #while + #with + #yield + + class ImportTest(unittest.TestCase): def test_bad_input_exception(self): Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-06 13:05:15 UTC (rev 5093) +++ branches/asm/grammar/Python.g 2008-08-06 17:54:07 UTC (rev 5094) @@ -82,9 +82,6 @@ Interactive; Expression; NameTok; - ExecTok; - InTok; - ClassTok; Test; Msg; Level; @@ -506,10 +503,44 @@ : NAME (DOT^ attr)* ; +//attr is here for Java compatibility. A Java foo.getIf() can be called from Jython as foo.if +// so we need to support any keyword as an attribute. + attr : NAME + | AND + | AS + | ASSERT + | BREAK + | CLASS + | CONTINUE + | DEF + | DELETE + | ELIF + | EXCEPT + | EXEC + | FINALLY + | FROM + | FOR + | GLOBAL + | IF + | IMPORT | IN + | IS + | LAMBDA + | NOT + | OR + | ORELSE + | PASS + | PRINT + | RAISE + | RETURN + | TRY + | WHILE + | WITH + | YIELD ; + //decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE decorator: AT dotted_attr ( (LPAREN arglist? RPAREN) -> ^(AT dotted_attr ^(Call ^(Args arglist)?)) @@ -758,16 +789,13 @@ ; //import_as_name: NAME [('as' | NAME) NAME] -import_as_name : name=NAME (keyAS asname=NAME)? +import_as_name : name=NAME (AS asname=NAME)? -> ^(Alias $name ^(Asname $asname)?) ; -//XXX: when does CPython Grammar match "dotted_name NAME NAME"? This may be a big -// problem because of the keyAS rule, which matches NAME (needed to allow -// 'as' to be a method name for Java integration). - +//XXX: when does CPython Grammar match "dotted_name NAME NAME"? //dotted_as_name: dotted_name [('as' | NAME) NAME] -dotted_as_name : dotted_name (keyAS asname=NAME)? +dotted_as_name : dotted_name (AS asname=NAME)? -> ^(Alias dotted_name ^(Asname NAME)?) ; @@ -784,8 +812,8 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? - -> ^(ExecTok[$keyEXEC.start] expr ^(Globals $t1)? ^(Locals $t2)?) +exec_stmt : EXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? + -> ^(EXEC expr ^(Globals $t1)? ^(Locals $t2)?) ; //assert_stmt: 'assert' test [',' test] @@ -842,14 +870,14 @@ ; //with_var: ('as' | NAME) expr -with_var: (keyAS | NAME) expr[expr_contextType.Load] +with_var: (AS | NAME) expr[expr_contextType.Load] ; //except_clause: 'except' [test [',' test]] -except_clause : 'except' (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? COLON suite +except_clause : EXCEPT (t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? COLON suite //Note: passing the 'except' keyword on so we can pass the same offset // as CPython. - -> ^(ExceptHandler 'except' ^(Type $t1)? ^(Value $t2)? ^(Body suite)) + -> ^(EXCEPT ^(Type $t1)? ^(Value $t2)? ^(Body suite)) ; //suite: simple_stmt | NEWLINE INDENT stmt+ DEDENT @@ -895,8 +923,8 @@ | NOTEQUAL | IN | NOT IN -> NotIn - | 'is' - | 'is' NOT -> IsNot + | IS + | IS NOT -> IsNot ; //expr: xor_expr ('|' xor_expr)* @@ -1040,8 +1068,8 @@ ; //classdef: 'class' NAME ['(' [testlist] ')'] ':' suite -classdef: keyCLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite - -> ^(ClassTok[$keyCLASS.start] NAME ^(Bases testlist)? ^(Body suite)) +classdef: CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite + -> ^(CLASS NAME ^(Bases testlist)? ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) @@ -1119,56 +1147,34 @@ //XXX: //testlist1: test (',' test)* -//These are all Python keywords that are not Java keywords -//This means that Jython needs to support these as NAMEs -//unlike CPython. For now I have only done this for 'as' -//and 'exec'. A chat with Leo Soto on #jython has made me -//realize I may need to do this for *all* keywords, since -//a Java foo.getIf() can be called from Jython as foo.if - -//keyAND : {input.LT(1).getText().equals("and")}? NAME ; -keyAS : {input.LT(1).getText().equals("as")}? NAME ; -//keyDEF : {input.LT(1).getText().equals("def")}? NAME ; -//keyDEL : {input.LT(1).getText().equals("del")}? NAME ; -//keyELIF : {input.LT(1).getText().equals("elif")}? NAME ; -//keyEXCEPT : {input.LT(1).getText().equals("except")}? NAME ; -keyEXEC : {input.LT(1).getText().equals("exec")}? NAME ; -//keyFROM : {input.LT(1).getText().equals("from")}? NAME ; -//keyGLOBAL : {input.LT(1).getText().equals("global")}? NAME ; -keyCLASS : {input.LT(1).getText().equals("class")}? NAME ; -//keyIS : {input.LT(1).getText().equals("is")}? NAME ; -//keyLAMBDA : {input.LT(1).getText().equals("lambda")}? NAME ; -//keyNOT : {input.LT(1).getText().equals("not")}? NAME ; -//keyOR : {input.LT(1).getText().equals("or")}? NAME ; -//keyPASS : {input.LT(1).getText().equals("pass")}? NAME ; -//keyPRINT : {input.LT(1).getText().equals("print")}? NAME ; -//keyRAISE : {input.LT(1).getText().equals("raise")}? NAME ; -//keyWITH : {input.LT(1).getText().equals("with")}? NAME ; -//keyYIELD : {input.LT(1).getText().equals("yield")}? NAME ; - -DEF : 'def' ; -PRINT : 'print' ; +AS : 'as' ; +ASSERT : 'assert' ; BREAK : 'break' ; +CLASS : 'class' ; CONTINUE : 'continue' ; -RETURN : 'return' ; -RAISE : 'raise' ; -PASS : 'pass' ; -IMPORT : 'import' ; +DEF : 'def' ; +DELETE : 'del' ; +ELIF : 'elif' ; +EXCEPT : 'except' ; +EXEC : 'exec' ; +FINALLY : 'finally' ; FROM : 'from' ; FOR : 'for' ; +GLOBAL : 'global' ; +IF : 'if' ; +IMPORT : 'import' ; +IN : 'in' ; +IS : 'is' ; +LAMBDA : 'lambda' ; ORELSE : 'else' ; -ELIF : 'elif' ; -IF : 'if' ; +PASS : 'pass' ; +PRINT : 'print' ; +RAISE : 'raise' ; +RETURN : 'return' ; +TRY : 'try' ; WHILE : 'while' ; WITH : 'with' ; -LAMBDA : 'lambda' ; -GLOBAL : 'global' ; YIELD : 'yield' ; -ASSERT : 'assert' ; -FINALLY : 'finally' ; -DELETE : 'del' ; -TRY : 'try' ; -IN : 'in' ; LPAREN : '(' {implicitLineJoiningLevel++;} ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-06 13:05:15 UTC (rev 5093) +++ branches/asm/grammar/PythonWalker.g 2008-08-06 17:54:07 UTC (rev 5094) @@ -420,10 +420,43 @@ } ; +//attr is here for Java compatibility. A Java foo.getIf() can be called from Jython as foo.if +// so we need to support any keyword as an attribute. attr : NAME + | AND + | AS + | ASSERT + | BREAK + | CLASS + | CONTINUE + | DEF + | DELETE + | ELIF + | EXCEPT + | EXEC + | FINALLY + | FROM + | FOR + | GLOBAL + | IF + | IMPORT | IN + | IS + | LAMBDA + | NOT + | OR + | ORELSE + | PASS + | PRINT + | RAISE + | RETURN + | TRY + | WHILE + | WITH + | YIELD ; + stmts returns [List stypes] scope { List statements; @@ -752,7 +785,7 @@ //Using NAME instead of 'exec' for Java integration exec_stmt - : ^(ExecTok exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { + : ^(EXEC exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { exprType g = null; if ($Globals != null) { g = $globals.etype; @@ -761,7 +794,7 @@ if ($Locals != null) { loc = $locals.etype; } - $stmts::statements.add(new Exec($ExecTok, $exec.etype, g, loc)); + $stmts::statements.add(new Exec($EXEC, $exec.etype, g, loc)); } ; @@ -854,7 +887,7 @@ ; except_clause[List handlers] - : ^(ExceptHandler 'except' (^(Type type=test[expr_contextType.Load]))? (^(Value name=test[expr_contextType.Store]))? ^(Body stmts)) { + : ^(EXCEPT (^(Type type=test[expr_contextType.Load]))? (^(Value name=test[expr_contextType.Store]))? ^(Body stmts)) { stmtType[] b; if ($stmts.start != null) { b = (stmtType[])$stmts.stypes.toArray(new stmtType[$stmts.stypes.size()]); @@ -867,7 +900,7 @@ if ($Value != null) { n = $name.etype; } - handlers.add(new excepthandlerType($ExceptHandler, t, n, b, $ExceptHandler.getLine(), $ExceptHandler.getCharPositionInLine())); + handlers.add(new excepthandlerType($EXCEPT, t, n, b, $EXCEPT.getLine(), $EXCEPT.getCharPositionInLine())); } ; @@ -880,7 +913,7 @@ //using NAME because of Java integration for 'as' with_var returns [exprType etype] - : NAME test[expr_contextType.Store] { + : (AS | NAME) test[expr_contextType.Store] { $etype = $test.etype; } ; @@ -1046,7 +1079,7 @@ | NOTEQUAL {$op = cmpopType.NotEq;} | IN {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} - | 'is' {$op = cmpopType.Is;} + | IS {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} ; @@ -1269,14 +1302,14 @@ ; classdef - : ^(ClassTok classname=NAME (^(Bases bases))? ^(Body stmts)) { + : ^(CLASS classname=NAME (^(Bases bases))? ^(Body stmts)) { List b; if ($Bases != null) { b = $bases.names; } else { b = new ArrayList(); } - $stmts::statements.add(makeClassDef($ClassTok, $classname, b, $stmts.stypes)); + $stmts::statements.add(makeClassDef($CLASS, $classname, b, $stmts.stypes)); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 13:05:18
|
Revision: 5093 http://jython.svn.sourceforge.net/jython/?rev=5093&view=rev Author: fwierzbicki Date: 2008-08-06 13:05:15 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Support "in" as an attribute for Java compatibility, but not as a NAME since this is overkill and causes errors (for example: for x, in ((1,),(2,)): parses "x, in" as a tuple (x,in) if "in" is treated like a name. bad. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-06 12:08:16 UTC (rev 5092) +++ branches/asm/grammar/Python.g 2008-08-06 13:05:15 UTC (rev 5093) @@ -503,9 +503,13 @@ //not in CPython's Grammar file dotted_attr - : NAME (DOT^ NAME)* + : NAME (DOT^ attr)* ; +attr + : NAME + | IN + ; //decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE decorator: AT dotted_attr ( (LPAREN arglist? RPAREN) -> ^(AT dotted_attr ^(Call ^(Args arglist)?)) @@ -771,7 +775,7 @@ dotted_as_names : dotted_as_name (COMMA! dotted_as_name)* ; //dotted_name: NAME ('.' NAME)* -dotted_name : NAME (DOT NAME)* +dotted_name : NAME (DOT attr)* ; //global_stmt: 'global' NAME (',' NAME)* @@ -780,7 +784,7 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr[expr_contextType.Load] (keyIN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? +exec_stmt : keyEXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? -> ^(ExecTok[$keyEXEC.start] expr ^(Globals $t1)? ^(Locals $t2)?) ; @@ -815,8 +819,8 @@ ; //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -for_stmt : FOR exprlist[expr_contextType.Store] keyIN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? - -> ^(FOR ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Body $s1) ^(ORELSE $s2)?) +for_stmt : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? + -> ^(FOR ^(Target exprlist) ^(IN testlist) ^(Body $s1) ^(ORELSE $s2)?) ; //try_stmt: ('try' ':' suite @@ -889,8 +893,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | keyIN -> InTok[$keyIN.start] - | NOT keyIN -> NotIn + | IN + | NOT IN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -989,7 +993,7 @@ //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME trailer : LPAREN (arglist)? RPAREN -> ^(Call ^(Args arglist)?) | LBRACK subscriptlist RBRACK -> ^(SubscriptList subscriptlist) - | DOT^ NAME {debug("motched DOT^ NAME");} + | DOT^ attr {debug("motched DOT^ NAME");} ; //subscriptlist: subscript (',' subscript)* [','] @@ -1083,8 +1087,8 @@ ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] -list_for : FOR exprlist[expr_contextType.Load] keyIN testlist[expr_contextType.Load] (list_iter)? - -> ^(ListFor ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Ifs list_iter)?) +list_for : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter)? + -> ^(ListFor ^(Target exprlist) ^(IN testlist) ^(Ifs list_iter)?) ; //list_if: 'if' test [list_iter] @@ -1098,8 +1102,8 @@ ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_for: FOR exprlist[expr_contextType.Load] keyIN or_test[expr_contextType.Load] gen_iter? - -> ^(GenFor ^(Target exprlist) ^(InTok[$keyIN.start] or_test) ^(Ifs gen_iter)?) +gen_for: FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter? + -> ^(GenFor ^(Target exprlist) ^(IN or_test) ^(Ifs gen_iter)?) ; //gen_if: 'if' old_test [gen_iter] @@ -1131,7 +1135,6 @@ keyEXEC : {input.LT(1).getText().equals("exec")}? NAME ; //keyFROM : {input.LT(1).getText().equals("from")}? NAME ; //keyGLOBAL : {input.LT(1).getText().equals("global")}? NAME ; -keyIN : {input.LT(1).getText().equals("in")}? NAME ; keyCLASS : {input.LT(1).getText().equals("class")}? NAME ; //keyIS : {input.LT(1).getText().equals("is")}? NAME ; //keyLAMBDA : {input.LT(1).getText().equals("lambda")}? NAME ; @@ -1165,6 +1168,7 @@ FINALLY : 'finally' ; DELETE : 'del' ; TRY : 'try' ; +IN : 'in' ; LPAREN : '(' {implicitLineJoiningLevel++;} ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-06 12:08:16 UTC (rev 5092) +++ branches/asm/grammar/PythonWalker.g 2008-08-06 13:05:15 UTC (rev 5093) @@ -410,9 +410,9 @@ ; dotted_attr returns [exprType etype, PythonTree marker] - : NAME { - $etype = new Name($NAME, $NAME.text, expr_contextType.Load); - $marker = $NAME; + : attr { + $etype = new Name($attr.start, $attr.text, expr_contextType.Load); + $marker = $attr.start; debug("matched NAME in dotted_attr");} | ^(DOT n1=dotted_attr n2=dotted_attr) { $etype = new Attribute($n1.marker, $n1.etype, $n2.text, expr_contextType.Load); @@ -420,6 +420,10 @@ } ; +attr + : NAME + | IN + ; stmts returns [List stypes] scope { List statements; @@ -723,9 +727,9 @@ ; dot_name [StringBuffer buf] - : DOT NAME { + : DOT attr { buf.append("."); - buf.append($NAME.text); + buf.append($attr.text); debug("matched dot_name " + buf); } ; @@ -817,7 +821,7 @@ ; for_stmt - : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { + : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { List o = null; if ($ORELSE != null) { o = $orelse.stypes; @@ -1040,7 +1044,7 @@ | LESSEQUAL {$op = cmpopType.LtE;} | ALT_NOTEQUAL {$op = cmpopType.NotEq;} | NOTEQUAL {$op = cmpopType.NotEq;} - | InTok {$op = cmpopType.In;} + | IN {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} | 'is' {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} @@ -1109,9 +1113,9 @@ $etype = new Name($NAME, $NAME.text, ctype); $marker = $NAME; } - | ^(DOT NAME test[expr_contextType.Load]) { - debug("matched DOT in atom: " + $test.etype + "###" + $NAME.text); - $etype = new Attribute($test.marker, $test.etype, $NAME.text, ctype); + | ^(DOT attr test[expr_contextType.Load]) { + debug("matched DOT in atom: " + $test.etype + "###" + $attr.text); + $etype = new Attribute($test.marker, $test.etype, $attr.text, ctype); $marker = $test.marker; } | ^(SubscriptList subscriptlist test[expr_contextType.Load]) { @@ -1365,7 +1369,7 @@ list_for [List gens] : - ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { + ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { debug("matched list_for"); exprType[] e; if ($Ifs != null && $list_iter.etype != null) { @@ -1391,7 +1395,7 @@ ; gen_for [List gens] - : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { + : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(IN iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { debug("matched gen_for"); exprType[] e; if ($Ifs != null && $gen_iter.etype != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 12:08:19
|
Revision: 5092 http://jython.svn.sourceforge.net/jython/?rev=5092&view=rev Author: fwierzbicki Date: 2008-08-06 12:08:16 +0000 (Wed, 06 Aug 2008) Log Message: ----------- trigger jarjar if grammar changes (since clean is triggered). Modified Paths: -------------- branches/asm/build.xml Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-08-06 11:59:35 UTC (rev 5091) +++ branches/asm/build.xml 2008-08-06 12:08:16 UTC (rev 5092) @@ -508,7 +508,7 @@ includesfile="${jython.base.dir}/CoreExposed.includes"/> </target> - <target name="jarjar" depends="init,needed-check" unless="jarjar.notneeded"> + <target name="jarjar" depends="init,needed-check" unless="jarjar.notneeded,antlr.notneeded"> <taskdef name="jarjar" classname="com.tonicsystems.jarjar.JarJarTask" classpath="extlibs/jarjar-0.7.jar"/> <jarjar destfile="${output.dir}/jarjar.jar"> <zipfileset src="extlibs/antlr-runtime-3.1b2.jar"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 11:59:38
|
Revision: 5091 http://jython.svn.sourceforge.net/jython/?rev=5091&view=rev Author: fwierzbicki Date: 2008-08-06 11:59:35 +0000 (Wed, 06 Aug 2008) Log Message: ----------- call clean if grammars change. Really only needed when *tokens* change, but token changes break things so subtly, and so few work on the grammars anyway, that this is the way to go I think. Modified Paths: -------------- branches/asm/build.xml Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-08-06 02:48:46 UTC (rev 5090) +++ branches/asm/build.xml 2008-08-06 11:59:35 UTC (rev 5091) @@ -313,8 +313,18 @@ </delete> </target> + <target name="clean-if-antlr-needed" unless="antlr.notneeded"> + <!-- this seems to be the only way I could get a clean when there has been a + change to grammar files. If you are working on the grammars you might + want to comment this out, as a clean is really only needed if you change + the tokens defined in Python.g (and cleans make the build slow) --> + <antcall target="clean"/> + </target> + + <target name ="prepare-output" depends="init,needed-check,clean-if-antlr-needed,make-output-dirs"/> + <!-- create output directories --> - <target name ="prepare-output" depends="init"> + <target name ="make-output-dirs" depends="init"> <mkdir dir="${compile.dir}" /> <mkdir dir="${jarjar.dir}" /> <mkdir dir="${gensrc.dir}/org/python/antlr" /> @@ -415,7 +425,7 @@ lazy="${templates.lazy}"/> </target> - <target name="antlr_gen" depends="init,needed-check,prepare-output" unless="antlr.notneeded"> + <target name="antlr_gen" depends="prepare-output" unless="antlr.notneeded"> <java classname="org.antlr.Tool" failonerror="true" fork="true" dir="${jython.base.dir}"> <arg value="-fo"/> <arg path="${work.dir}/build/gensrc/org/python/antlr"/> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-06 02:48:50
|
Revision: 5090 http://jython.svn.sourceforge.net/jython/?rev=5090&view=rev Author: pjenvey Date: 2008-08-06 02:48:46 +0000 (Wed, 06 Aug 2008) Log Message: ----------- PEP 305 (csv module) patches from Paul Drummond, Dave Kuhlman (thanks!) fixes #1650802 Modified Paths: -------------- branches/asm/CPythonLib.includes branches/asm/CoreExposed.includes branches/asm/src/org/python/modules/Setup.java branches/asm/src/templates/mappings Added Paths: ----------- branches/asm/src/org/python/modules/_csv/ branches/asm/src/org/python/modules/_csv/PyDialect.java branches/asm/src/org/python/modules/_csv/PyDialectDerived.java branches/asm/src/org/python/modules/_csv/PyReader.java branches/asm/src/org/python/modules/_csv/PyWriter.java branches/asm/src/org/python/modules/_csv/QuoteStyle.java branches/asm/src/org/python/modules/_csv/_csv.java branches/asm/src/templates/dialect.derived Modified: branches/asm/CPythonLib.includes =================================================================== --- branches/asm/CPythonLib.includes 2008-08-06 02:27:45 UTC (rev 5089) +++ branches/asm/CPythonLib.includes 2008-08-06 02:48:46 UTC (rev 5090) @@ -43,6 +43,7 @@ copy.py copy_reg.py Cookie.py +csv.py difflib.py dircache.py dircmp.py Modified: branches/asm/CoreExposed.includes =================================================================== --- branches/asm/CoreExposed.includes 2008-08-06 02:27:45 UTC (rev 5089) +++ branches/asm/CoreExposed.includes 2008-08-06 02:48:46 UTC (rev 5090) @@ -36,6 +36,9 @@ org/python/core/PyUnicode.class org/python/core/PyXRange.class org/python/modules/_codecs$EncodingMap.class +org/python/modules/_csv/PyDialect.class +org/python/modules/_csv/PyReader.class +org/python/modules/_csv/PyWriter.class org/python/modules/_functools/PyPartial.class org/python/modules/_weakref/CallableProxyType.class org/python/modules/_weakref/ReferenceType.class Modified: branches/asm/src/org/python/modules/Setup.java =================================================================== --- branches/asm/src/org/python/modules/Setup.java 2008-08-06 02:27:45 UTC (rev 5089) +++ branches/asm/src/org/python/modules/Setup.java 2008-08-06 02:48:46 UTC (rev 5090) @@ -53,6 +53,7 @@ "collections:org.python.modules.collections.Collections", "gc", "_hashlib", - "_functools:org.python.modules._functools._functools" + "_functools:org.python.modules._functools._functools", + "_csv:org.python.modules._csv._csv" }; } Added: branches/asm/src/org/python/modules/_csv/PyDialect.java =================================================================== --- branches/asm/src/org/python/modules/_csv/PyDialect.java (rev 0) +++ branches/asm/src/org/python/modules/_csv/PyDialect.java 2008-08-06 02:48:46 UTC (rev 5090) @@ -0,0 +1,217 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._csv; + +import org.python.core.ArgParser; +import org.python.core.Py; +import org.python.core.PyBaseString; +import org.python.core.PyInteger; +import org.python.core.PyNewWrapper; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.expose.ExposedDelete; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedNew; +import org.python.expose.ExposedSet; +import org.python.expose.ExposedType; + +/** + * The Python CSV Dialect type. + */ +@ExposedType(name = "_csv.Dialect") +public class PyDialect extends PyObject { + + public static final PyType TYPE = PyType.fromClass(PyDialect.class); + + public PyString __doc__ = Py.newString( + "CSV dialect\n" + + "\n" + + "The Dialect type records CSV parsing and generation options.\n"); + + /** Whether " is represented by "". */ + @ExposedGet + public boolean doublequote; + + /** Field separator. */ + @ExposedGet + public char delimiter; + + /** Quote character. */ + public char quotechar; + + /** Escape character. */ + public char escapechar; + + /** Ignore spaces following delimiter? */ + @ExposedGet + public boolean skipinitialspace; + + /** String to write between records. */ + @ExposedGet + public String lineterminator; + + /** Style of quoting to write. */ + public QuoteStyle quoting; + + /** Whether an exception is raised on bad CSV. */ + @ExposedGet + public boolean strict; + + public PyDialect() { + super(TYPE); + } + + public PyDialect(PyType subType) { + super(subType); + } + + @ExposedNew + final static PyObject Dialect___new__(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + ArgParser ap = new ArgParser("__new__", args, keywords, + new String[] {"dialect", "delimiter", "doublequote", + "escapechar", "lineterminator", "quotechar", + "quoting", "skipinitialspace", "strict"}); + PyObject dialect = ap.getPyObject(0, null); + PyObject delimiter = ap.getPyObject(1, null); + PyObject doublequote = ap.getPyObject(2, null); + PyObject escapechar = ap.getPyObject(3, null); + PyObject lineterminator = ap.getPyObject(4, null); + PyObject quotechar = ap.getPyObject(5, null); + PyObject quoting = ap.getPyObject(6, null); + PyObject skipinitialspace = ap.getPyObject(7, null); + PyObject strict = ap.getPyObject(8, null); + + if (dialect instanceof PyString) { + dialect = _csv.get_dialect_from_registry(dialect); + } + + // Can we reuse this instance? + if (dialect instanceof PyDialect && delimiter == null && doublequote == null + && escapechar == null && lineterminator == null && quotechar == null && quoting == null + && skipinitialspace == null && strict == null) { + return dialect; + } + + if (dialect != null) { + delimiter = delimiter != null ? delimiter : dialect.__findattr__("delimiter"); + doublequote = doublequote != null + ? doublequote : dialect.__findattr__("doublequote"); + escapechar = escapechar != null ? escapechar : dialect.__findattr__("escapechar"); + lineterminator = lineterminator != null + ? lineterminator : dialect.__findattr__("lineterminator"); + quotechar = quotechar != null ? quotechar : dialect.__findattr__("quotechar"); + quoting = quoting != null ? quoting : dialect.__findattr__("quoting"); + skipinitialspace = skipinitialspace != null + ? skipinitialspace : dialect.__findattr__("skipinitialspace"); + strict = strict != null ? strict : dialect.__findattr__("strict"); + } + + PyDialect self; + if (new_.for_type == subtype) { + self = new PyDialect(); + } else { + self = new PyDialectDerived(subtype); + } + + // check types and convert to Java values + int quotingOrdinal; + self.delimiter = toChar("delimiter", delimiter, ','); + self.doublequote = toBool("doublequote", doublequote, true); + self.escapechar = toChar("escapechar", escapechar, '\0'); + self.lineterminator = toStr("lineterminator", lineterminator, "\r\n"); + self.quotechar = toChar("quotechar", quotechar, '"'); + quotingOrdinal = toInt("quoting", quoting, QuoteStyle.QUOTE_MINIMAL.ordinal()); + self.skipinitialspace = toBool("skipinitialspace", skipinitialspace, false); + self.strict = toBool("strict", strict, false); + + // validate options + self.quoting = QuoteStyle.fromOrdinal(quotingOrdinal); + if (self.quoting == null) { + throw Py.TypeError("bad \"quoting\" value"); + } + if (self.delimiter == '\0') { + throw Py.TypeError("delimiter must be set"); + } + if (quotechar == Py.None && quoting == null) { + self.quoting = QuoteStyle.QUOTE_NONE; + } + if (self.quoting != QuoteStyle.QUOTE_NONE && self.quotechar == '\0') { + throw Py.TypeError("quotechar must be set if quoting enabled"); + } + if (self.lineterminator == null) { + throw Py.TypeError("lineterminator must be set"); + } + + return self; + } + + private static boolean toBool(String name, PyObject src, boolean dflt) { + return src == null ? dflt : src.__nonzero__(); + } + + private static char toChar(String name, PyObject src, char dflt) { + if (src == null) { + return dflt; + } + boolean isStr = Py.isInstance(src, PyString.TYPE); + if (src == Py.None || isStr && src.__len__() == 0) { + return '\0'; + } else if (!isStr || src.__len__() != 1) { + throw Py.TypeError(String.format("\"%s\" must be an 1-character string", name)); + } + return src.toString().charAt(0); + } + + private static int toInt(String name, PyObject src, int dflt) { + if (src == null) { + return dflt; + } + if (!(src instanceof PyInteger)) { + throw Py.TypeError(String.format("\"%s\" must be an integer", name)); + } + return src.asInt(); + } + + private static String toStr(String name, PyObject src, String dflt) { + if (src == null) { + return dflt; + } + if (src == Py.None) { + return null; + } + if (!(src instanceof PyBaseString)) { + throw Py.TypeError(String.format("\"%s\" must be an string", name)); + } + return src.toString(); + } + + @ExposedGet(name = "escapechar") + public PyObject getEscapechar() { + return escapechar == '\0' ? Py.None : Py.newString(escapechar); + } + + @ExposedGet(name = "quotechar") + public PyObject getQuotechar() { + return quotechar == '\0' ? Py.None : Py.newString(quotechar); + } + + @ExposedGet(name = "quoting") + public PyObject getQuoting() { + return Py.newInteger(quoting.ordinal()); + } + + // XXX: setQuoting and delQuoting are to make test_csv pass (currently we incorrectly + // throw TypeErrors for get/set AttributeError failures) + @ExposedSet(name = "quoting") + public void setQuoting(PyObject obj) { + throw Py.AttributeError(String.format("attribute '%s' of '%s' objects is not writable", + "quoting", getType().fastGetName())); + } + + @ExposedDelete(name = "quoting") + public void delQuoting() { + throw Py.AttributeError(String.format("attribute '%s' of '%s' objects is not writable", + "quoting", getType().fastGetName())); + } +} Added: branches/asm/src/org/python/modules/_csv/PyDialectDerived.java =================================================================== --- branches/asm/src/org/python/modules/_csv/PyDialectDerived.java (rev 0) +++ branches/asm/src/org/python/modules/_csv/PyDialectDerived.java 2008-08-06 02:48:46 UTC (rev 5090) @@ -0,0 +1,1104 @@ +/* Generated file, do not modify. See jython/src/templates/gderived.py. */ +package org.python.modules._csv; + +import org.python.core.*; + +public class PyDialectDerived extends PyDialect implements Slotted { + + public PyObject getSlot(int index) { + return slots[index]; + } + + public void setSlot(int index,PyObject value) { + slots[index]=value; + } + + private PyObject[]slots; + + public PyDialectDerived(PyType subtype) { + super(subtype); + slots=new PyObject[subtype.getNumSlots()]; + } + + public PyString __str__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__str__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__str__(); + } + + public PyString __repr__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__repr__(); + } + + public PyString __hex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__hex__(); + } + + public PyString __oct__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__oct__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyString) + return(PyString)res; + throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); + } + return super.__oct__(); + } + + public PyFloat __float__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__float__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyFloat) + return(PyFloat)res; + throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); + } + return super.__float__(); + } + + public PyComplex __complex__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__complex__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyComplex) + return(PyComplex)res; + throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); + } + return super.__complex__(); + } + + public PyObject __pos__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pos__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__pos__(); + } + + public PyObject __neg__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__neg__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__neg__(); + } + + public PyObject __abs__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__abs__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__abs__(); + } + + public PyObject __invert__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__invert__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__invert__(); + } + + public PyObject __reduce__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__reduce__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + return super.__reduce__(); + } + + public PyObject __add__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__add__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__add__(other); + } + + public PyObject __radd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__radd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__radd__(other); + } + + public PyObject __sub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__sub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__sub__(other); + } + + public PyObject __rsub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rsub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rsub__(other); + } + + public PyObject __mul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mul__(other); + } + + public PyObject __rmul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmul__(other); + } + + public PyObject __div__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__div__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__div__(other); + } + + public PyObject __rdiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdiv__(other); + } + + public PyObject __floordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__floordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__floordiv__(other); + } + + public PyObject __rfloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rfloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rfloordiv__(other); + } + + public PyObject __truediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__truediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__truediv__(other); + } + + public PyObject __rtruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rtruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rtruediv__(other); + } + + public PyObject __mod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__mod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__mod__(other); + } + + public PyObject __rmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rmod__(other); + } + + public PyObject __divmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__divmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__divmod__(other); + } + + public PyObject __rdivmod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rdivmod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rdivmod__(other); + } + + public PyObject __rpow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rpow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rpow__(other); + } + + public PyObject __lshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lshift__(other); + } + + public PyObject __rlshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rlshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rlshift__(other); + } + + public PyObject __rshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rshift__(other); + } + + public PyObject __rrshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rrshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rrshift__(other); + } + + public PyObject __and__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__and__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__and__(other); + } + + public PyObject __rand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rand__(other); + } + + public PyObject __or__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__or__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__or__(other); + } + + public PyObject __ror__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ror__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ror__(other); + } + + public PyObject __xor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__xor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__xor__(other); + } + + public PyObject __rxor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__rxor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__rxor__(other); + } + + public PyObject __lt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__lt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__lt__(other); + } + + public PyObject __le__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__le__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__le__(other); + } + + public PyObject __gt__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__gt__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__gt__(other); + } + + public PyObject __ge__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ge__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ge__(other); + } + + public PyObject __eq__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__eq__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__eq__(other); + } + + public PyObject __ne__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ne__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ne__(other); + } + + public PyObject __iadd__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iadd__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iadd__(other); + } + + public PyObject __isub__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__isub__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__isub__(other); + } + + public PyObject __imul__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imul__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imul__(other); + } + + public PyObject __idiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__idiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__idiv__(other); + } + + public PyObject __ifloordiv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ifloordiv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ifloordiv__(other); + } + + public PyObject __itruediv__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__itruediv__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__itruediv__(other); + } + + public PyObject __imod__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__imod__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__imod__(other); + } + + public PyObject __ipow__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ipow__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ipow__(other); + } + + public PyObject __ilshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ilshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ilshift__(other); + } + + public PyObject __irshift__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__irshift__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__irshift__(other); + } + + public PyObject __iand__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iand__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__iand__(other); + } + + public PyObject __ior__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ior__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ior__(other); + } + + public PyObject __ixor__(PyObject other) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__ixor__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__ixor__(other); + } + + public PyObject __int__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__int__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) + return(PyObject)res; + throw Py.TypeError("__int__"+" should return an integer"); + } + return super.__int__(); + } + + public PyObject __long__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__long__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyLong||res instanceof PyInteger) + return res; + throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); + } + return super.__long__(); + } + + public int hashCode() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__hash__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) { + return((PyInteger)res).getValue(); + } else + if (res instanceof PyLong) { + return((PyLong)res).getValue().intValue(); + } + throw Py.TypeError("__hash__ should return a int"); + } + if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { + throw Py.TypeError("unhashable type"); + } + return super.hashCode(); + } + + public PyUnicode __unicode__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__unicode__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyUnicode) + return(PyUnicode)res; + if (res instanceof PyString) + return new PyUnicode((PyString)res); + throw Py.TypeError("__unicode__"+" should return a "+"unicode"); + } + return super.__unicode__(); + } + + public int __cmp__(PyObject other) { + PyType self_type=getType(); + PyType[]where_type=new PyType[1]; + PyObject impl=self_type.lookup_where("__cmp__",where_type); + // Full Compatibility with CPython __cmp__: + // If the derived type don't override __cmp__, the + // *internal* super().__cmp__ should be called, not the + // exposed one. The difference is that the exposed __cmp__ + // throws a TypeError if the argument is an instance of the same type. + if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { + return super.__cmp__(other); + } + PyObject res=impl.__get__(this,self_type).__call__(other); + if (res instanceof PyInteger) { + int v=((PyInteger)res).getValue(); + return v<0?-1:v>0?1:0; + } + throw Py.TypeError("__cmp__ should return a int"); + } + + public boolean __nonzero__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__nonzero__"); + if (impl==null) { + impl=self_type.lookup("__len__"); + if (impl==null) + return super.__nonzero__(); + } + return impl.__get__(this,self_type).__call__().__nonzero__(); + } + + public boolean __contains__(PyObject o) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__contains__"); + if (impl==null) + return super.__contains__(o); + return impl.__get__(this,self_type).__call__(o).__nonzero__(); + } + + public int __len__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__len__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger) + return((PyInteger)res).getValue(); + throw Py.TypeError("__len__ should return a int"); + } + return super.__len__(); + } + + public PyObject __iter__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__iter__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(); + impl=self_type.lookup("__getitem__"); + if (impl==null) + return super.__iter__(); + return new PySequenceIter(this); + } + + public PyObject __iternext__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("next"); + if (impl!=null) { + try { + return impl.__get__(this,self_type).__call__(); + } catch (PyException exc) { + if (Py.matchException(exc,Py.StopIteration)) + return null; + throw exc; + } + } + return super.__iternext__(); // ??? + } + + public PyObject __finditem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(key); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + + public PyObject __getitem__(PyObject key) { + // Same as __finditem__, without swallowing LookupErrors. This allows + // __getitem__ implementations written in Python to raise custom + // exceptions (such as subclasses of KeyError). + // + // We are forced to duplicate the code, instead of defining __finditem__ + // in terms of __getitem__. That's because PyObject defines __getitem__ + // in terms of __finditem__. Therefore, we would end with an infinite + // loop when self_type.lookup("__getitem__") returns null: + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ + // + // By duplicating the (short) lookup and call code, we are safe, because + // the call chains will be: + // + // __finditem__ -> super.__finditem__ + // + // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ + + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(key); + return super.__getitem__(key); + } + + public void __setitem__(PyObject key,PyObject value) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key,value); + return; + } + super.__setitem__(key,value); + } + + public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? + if (step!=null) { + return __getitem__(new PySlice(start,stop,step)); + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + return impl.__get__(this,self_type).__call__(indices[0],indices[1]); + } + return super.__getslice__(start,stop,step); + } + + public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { + if (step!=null) { + __setitem__(new PySlice(start,stop,step),value); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1],value); + return; + } + super.__setslice__(start,stop,step,value); + } + + public void __delslice__(PyObject start,PyObject stop,PyObject step) { + if (step!=null) { + __delitem__(new PySlice(start,stop,step)); + return; + } + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delslice__"); + if (impl!=null) { + PyObject[]indices=PySlice.indices2(this,start,stop); + impl.__get__(this,self_type).__call__(indices[0],indices[1]); + return; + } + super.__delslice__(start,stop,step); + } + + public void __delitem__(PyObject key) { // ??? + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delitem__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(key); + return; + } + super.__delitem__(key); + } + + public PyObject __call__(PyObject args[],String keywords[]) { + ThreadState ts=Py.getThreadState(); + if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) + throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); + try { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__call__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(args,keywords); + return super.__call__(args,keywords); + } finally { + --ts.recursion_depth; + } + } + + public PyObject __findattr__(String name) { + PyType self_type=getType(); + PyObject getattribute=self_type.lookup("__getattribute__"); + PyString py_name=null; + try { + if (getattribute!=null) { + return getattribute.__get__(this,self_type).__call__(py_name=PyString.fromInterned(name)); + } else { + return super.__findattr__(name); + } + } catch (PyException e) { + if (Py.matchException(e,Py.AttributeError)) { + PyObject getattr=self_type.lookup("__getattr__"); + if (getattr!=null) + try { + return getattr.__get__(this,self_type).__call__(py_name!=null?py_name:PyString.fromInterned(name)); + } catch (PyException e1) { + if (!Py.matchException(e1,Py.AttributeError)) + throw e1; + } + return null; + } + throw e; + } + } + + public void __setattr__(String name,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__setattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); + return; + } + super.__setattr__(name,value); + } + + public void __delattr__(String name) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delattr__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); + return; + } + super.__delattr__(name); + } + + public PyObject __get__(PyObject obj,PyObject type) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__get__"); + if (impl!=null) { + if (obj==null) + obj=Py.None; + if (type==null) + type=Py.None; + return impl.__get__(this,self_type).__call__(obj,type); + } + return super.__get__(obj,type); + } + + public void __set__(PyObject obj,PyObject value) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__set__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj,value); + return; + } + super.__set__(obj,value); + } + + public void __delete__(PyObject obj) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__delete__"); + if (impl!=null) { + impl.__get__(this,self_type).__call__(obj); + return; + } + super.__delete__(obj); + } + + public PyObject __pow__(PyObject other,PyObject modulo) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__pow__"); + if (impl!=null) { + PyObject res; + if (modulo==null) { + res=impl.__get__(this,self_type).__call__(other); + } else { + res=impl.__get__(this,self_type).__call__(other,modulo); + } + if (res==Py.NotImplemented) + return null; + return res; + } + return super.__pow__(other,modulo); + } + + public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { + PyType self_type=getType(); + if (self_type.isSubType(type)) { + PyObject impl=self_type.lookup("__init__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(args,keywords); + if (res!=Py.None) { + throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); + } + } + } + } + + public PyObject __index__() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__index__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (res instanceof PyInteger||res instanceof PyLong) { + return res; + } + throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); + } + return super.__index__(); + } + + public Object __tojava__(Class c) { + // If we are not being asked by the "default" conversion to java, then + // we can provide this as the result, as long as it is a instance of the + // specified class. Without this, derived.__tojava__(PyObject.class) + // would broke. (And that's not pure speculation: PyReflectedFunction's + // ReflectedArgs asks for things like that). + if ((c!=Object.class)&&(c.isInstance(this))) { + return this; + } + // Otherwise, we call the derived __tojava__, if it exists: + PyType self_type=getType(); + PyObject impl=self_type.lookup("__tojava__"); + if (impl!=null) + return impl.__get__(this,self_type).__call__(Py.java2py(c)).__tojava__(Object.class); + return super.__tojava__(c); + } + + public String toString() { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__repr__"); + if (impl!=null) { + PyObject res=impl.__get__(this,self_type).__call__(); + if (!(res instanceof PyString)) + throw Py.TypeError("__repr__ returned non-string (type "+res.getType().fastGetName()+")"); + return((PyString)res).toString(); + } + return super.toString(); + } + +} Added: branches/asm/src/org/python/modules/_csv/PyReader.java =================================================================== --- branches/asm/src/org/python/modules/_csv/PyReader.java (rev 0) +++ branches/asm/src/org/python/modules/_csv/PyReader.java 2008-08-06 02:48:46 UTC (rev 5090) @@ -0,0 +1,271 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._csv; + +import org.python.core.Py; +import org.python.core.PyIterator; +import org.python.core.PyList; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedType; + +/** + * CSV file reader. + * + * Analogous to CPython's _csv.c::ReaderObj struct. + */ +@ExposedType(name = "_csv.reader") +public class PyReader extends PyIterator { + + public static final PyType TYPE = PyType.fromClass(PyReader.class); + + public PyString __doc__ = Py.newString( + "CSV reader\n" + + "\n" + + "Reader objects are responsible for reading and parsing tabular data\n" + + "in CSV format.\n"); + + /** Parsing Dialect. */ + @ExposedGet + public PyDialect dialect; + + /** The current line number. */ + @ExposedGet + public int line_num = 0; + + /** The underlying input iterator. */ + private PyObject input_iter; + + /** Current CSV parse state. */ + private ParserState state = ParserState.START_RECORD; + + /** Field list for current record. */ + private PyList fields = new PyList(); + + /** Current field builder in here. */ + private StringBuffer field = new StringBuffer(INITIAL_BUILDER_CAPACITY); + + /** Whether the field should be treated as numeric. */ + private boolean numeric_field = false; + + /** Initial capacity of the field StringBuilder. */ + private static final int INITIAL_BUILDER_CAPACITY = 4096; + + public PyReader(PyObject input_iter, PyDialect dialect) { + this.input_iter = input_iter; + this.dialect = dialect; + } + + public PyObject __iternext__() { + PyObject lineobj; + PyObject fields; + String line; + char c; + int linelen; + + parse_reset(); + do { + lineobj = input_iter.__iternext__(); + if (lineobj == null) { + // End of input OR exception + if (field.length() != 0) { + throw _csv.Error("newline inside string"); + } else { + return null; + } + } + + line_num++; + line = lineobj.toString(); + linelen = line.length(); + + for (int i = 0; i < linelen; i++) { + c = line.charAt(i); + if (c == '\0') { + throw _csv.Error("line contains NULL byte"); + } + parse_process_char(c); + } + parse_process_char('\0'); + } while (state != ParserState.START_RECORD); + + fields = this.fields; + this.fields = new PyList(); + + return fields; + } + + private void parse_process_char(char c) { + switch (state) { + case START_RECORD: + // start of record + if (c == '\0') { + // empty line - return [] + break; + } else if (c == '\n' || c == '\r') { + state = ParserState.EAT_CRNL; + break; + } + // normal character - handle as START_FIELD + state = ParserState.START_FIELD; + // *** fallthru *** + case START_FIELD: + // expecting field + if (c == '\n' || c == '\r' || c == '\0') { + // save empty field - return [fields] + parse_save_field(); + state = c == '\0' ? ParserState.START_RECORD : ParserState.EAT_CRNL; + } else if (c == dialect.quotechar && dialect.quoting != QuoteStyle.QUOTE_NONE) { + // start quoted field + state = ParserState.IN_QUOTED_FIELD; + } else if (c == dialect.escapechar) { + // possible escaped character + state = ParserState.ESCAPED_CHAR; + } else if (c == ' ' && dialect.skipinitialspace) { + // ignore space at start of field + ; + } else if (c == dialect.delimiter) { + // save empty field + parse_save_field(); + } else { + // begin new unquoted field + if (dialect.quoting == QuoteStyle.QUOTE_NONNUMERIC) { + numeric_field = true; + } + parse_add_char(c); + state = ParserState.IN_FIELD; + } + break; + + case ESCAPED_CHAR: + if (c == '\0') { + c = '\n'; + } + parse_add_char(c); + state = ParserState.IN_FIELD; + break; + + case IN_FIELD: + // in unquoted field + if (c == '\n' || c == '\r' || c == '\0') { + // end of line - return [fields] + parse_save_field(); + state = c == '\0' ? ParserState.START_RECORD : ParserState.EAT_CRNL; + } else if (c == dialect.escapechar) { + // possible escaped character + state = ParserState.ESCAPED_CHAR; + } else if (c == dialect.delimiter) { + // save field - wait for new field + parse_save_field(); + state = ParserState.START_FIELD; + } else { + // normal character - save in field + parse_add_char(c); + } + break; + + case IN_QUOTED_FIELD: + // in quoted field + if (c == '\0') { + ; + } else if (c == dialect.escapechar) { + // Possible escape character + state = ParserState.ESCAPE_IN_QUOTED_FIELD; + } else if (c == dialect.quotechar && dialect.quoting != QuoteStyle.QUOTE_NONE) { + if (dialect.doublequote) { + // doublequote; " represented by "" + state = ParserState.QUOTE_IN_QUOTED_FIELD; + } else { + // end of quote part of field + state = ParserState.IN_FIELD; + } + } else { + // normal character - save in field + parse_add_char(c); + } + break; + + case ESCAPE_IN_QUOTED_FIELD: + if (c == '\0') { + c = '\n'; + } + parse_add_char(c); + state = ParserState.IN_QUOTED_FIELD; + break; + + case QUOTE_IN_QUOTED_FIELD: + // doublequote - seen a quote in an quoted field + if (dialect.quoting != QuoteStyle.QUOTE_NONE && c == dialect.quotechar) { + // save "" as " + parse_add_char(c); + state = ParserState.IN_QUOTED_FIELD; + } else if (c == dialect.delimiter) { + // save field - wait for new field + parse_save_field(); + state = ParserState.START_FIELD; + } else if (c == '\n' || c == '\r' || c == '\0') { + // end of line - return [fields] + parse_save_field(); + state = c == '\0' ? ParserState.START_RECORD : ParserState.EAT_CRNL; + } else if (!dialect.strict) { + parse_add_char(c); + state = ParserState.IN_FIELD; + } else { + // illegal + throw _csv.Error(String.format("'%c' expected after '%c'", + dialect.delimiter, dialect.quotechar)); + } + break; + + case EAT_CRNL: + if (c == '\n' || c == '\r') { + ; + } else if (c == '\0') { + state = ParserState.START_RECORD; + } else { + String err = "new-line character seen in unquoted field - do you need to " + + "open the file in universal-newline mode?"; + throw _csv.Error(err); + } + break; + } + } + + private void parse_reset() { + fields = new PyList(); + state = ParserState.START_RECORD; + numeric_field = false; + } + + private void parse_save_field() { + PyObject field; + + field = new PyString(this.field.toString()); + if (numeric_field) { + numeric_field = false; + field = field.__float__(); + } + fields.append(field); + + // XXX: fastest way to clear StringBuffer? + this.field = new StringBuffer(INITIAL_BUILDER_CAPACITY); + } + + private void parse_add_char(char c) { + int field_len = field.length(); + if (field_len >= _csv.field_limit) { + throw _csv.Error(String.format("field larger than field limit (%d)", + _csv.field_limit)); + } + field.append(c); + } + + /** + * State of the CSV reader. + */ + private enum ParserState { + START_RECORD, START_FIELD, ESCAPED_CHAR, IN_FIELD, IN_QUOTED_FIELD, ESCAPE_IN_QUOTED_FIELD, + QUOTE_IN_QUOTED_FIELD, EAT_CRNL; + } +} Added: branches/asm/src/org/python/modules/_csv/PyWriter.java =================================================================== --- branches/asm/src/org/python/modules/_csv/PyWriter.java (rev 0) +++ branches/asm/src/org/python/modules/_csv/PyWriter.java 2008-08-06 02:48:46 UTC (rev 5090) @@ -0,0 +1,267 @@ +/* Copyright (c) Jython Developers */ +package org.python.modules._csv; + +import org.python.core.Py; +import org.python.core.PyException; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyType; +import org.python.expose.ExposedType; +import org.python.expose.ExposedMethod; +import org.python.expose.ExposedGet; + +/** + * CSV file writer. + * + * Analogous to CPython's _csv.c::WriterObj str... [truncated message content] |
From: <fwi...@us...> - 2008-08-06 02:27:52
|
Revision: 5089 http://jython.svn.sourceforge.net/jython/?rev=5089&view=rev Author: fwierzbicki Date: 2008-08-06 02:27:45 +0000 (Wed, 06 Aug 2008) Log Message: ----------- Extra comment as a reminder about keywords. Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-06 02:19:54 UTC (rev 5088) +++ branches/asm/grammar/Python.g 2008-08-06 02:27:45 UTC (rev 5089) @@ -1118,7 +1118,9 @@ //These are all Python keywords that are not Java keywords //This means that Jython needs to support these as NAMEs //unlike CPython. For now I have only done this for 'as' -//and 'exec'. +//and 'exec'. A chat with Leo Soto on #jython has made me +//realize I may need to do this for *all* keywords, since +//a Java foo.getIf() can be called from Jython as foo.if //keyAND : {input.LT(1).getText().equals("and")}? NAME ; keyAS : {input.LT(1).getText().equals("as")}? NAME ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-06 02:19:56
|
Revision: 5088 http://jython.svn.sourceforge.net/jython/?rev=5088&view=rev Author: fwierzbicki Date: 2008-08-06 02:19:54 +0000 (Wed, 06 Aug 2008) Log Message: ----------- fix for Java integration ("in" and "class" can now be used as non-keywords). Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-05 23:46:30 UTC (rev 5087) +++ branches/asm/grammar/Python.g 2008-08-06 02:19:54 UTC (rev 5088) @@ -82,6 +82,9 @@ Interactive; Expression; NameTok; + ExecTok; + InTok; + ClassTok; Test; Msg; Level; @@ -777,8 +780,8 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? - -> ^(keyEXEC expr ^(Globals $t1)? ^(Locals $t2)?) +exec_stmt : keyEXEC expr[expr_contextType.Load] (keyIN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? + -> ^(ExecTok[$keyEXEC.start] expr ^(Globals $t1)? ^(Locals $t2)?) ; //assert_stmt: 'assert' test [',' test] @@ -812,8 +815,8 @@ ; //for_stmt: 'for' exprlist 'in' testlist ':' suite ['else' ':' suite] -for_stmt : FOR exprlist[expr_contextType.Store] IN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? - -> ^(FOR ^(Target exprlist) ^(IN testlist) ^(Body $s1) ^(ORELSE $s2)?) +for_stmt : FOR exprlist[expr_contextType.Store] keyIN testlist[expr_contextType.Load] COLON s1=suite (ORELSE COLON s2=suite)? + -> ^(FOR ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Body $s1) ^(ORELSE $s2)?) ; //try_stmt: ('try' ':' suite @@ -886,8 +889,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | IN - | NOT IN -> NotIn + | keyIN -> InTok[$keyIN.start] + | NOT keyIN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -1033,8 +1036,8 @@ ; //classdef: 'class' NAME ['(' [testlist] ')'] ':' suite -classdef: CLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite - -> ^(CLASS NAME ^(Bases testlist)? ^(Body suite)) +classdef: keyCLASS NAME (LPAREN testlist[expr_contextType.Load]? RPAREN)? COLON suite + -> ^(ClassTok[$keyCLASS.start] NAME ^(Bases testlist)? ^(Body suite)) ; //arglist: (argument ',')* (argument [',']| '*' test [',' '**' test] | '**' test) @@ -1080,8 +1083,8 @@ ; //list_for: 'for' exprlist 'in' testlist_safe [list_iter] -list_for : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter)? - -> ^(ListFor ^(Target exprlist) ^(IN testlist) ^(Ifs list_iter)?) +list_for : FOR exprlist[expr_contextType.Load] keyIN testlist[expr_contextType.Load] (list_iter)? + -> ^(ListFor ^(Target exprlist) ^(InTok[$keyIN.start] testlist) ^(Ifs list_iter)?) ; //list_if: 'if' test [list_iter] @@ -1095,8 +1098,8 @@ ; //gen_for: 'for' exprlist 'in' or_test [gen_iter] -gen_for: FOR exprlist[expr_contextType.Load] IN or_test[expr_contextType.Load] gen_iter? - -> ^(GenFor ^(Target exprlist) ^(IN or_test) ^(Ifs gen_iter)?) +gen_for: FOR exprlist[expr_contextType.Load] keyIN or_test[expr_contextType.Load] gen_iter? + -> ^(GenFor ^(Target exprlist) ^(InTok[$keyIN.start] or_test) ^(Ifs gen_iter)?) ; //gen_if: 'if' old_test [gen_iter] @@ -1118,7 +1121,7 @@ //and 'exec'. //keyAND : {input.LT(1).getText().equals("and")}? NAME ; -keyAS : {input.LT(1).getText().equals("as")}? NAME ; +keyAS : {input.LT(1).getText().equals("as")}? NAME ; //keyDEF : {input.LT(1).getText().equals("def")}? NAME ; //keyDEL : {input.LT(1).getText().equals("del")}? NAME ; //keyELIF : {input.LT(1).getText().equals("elif")}? NAME ; @@ -1126,7 +1129,8 @@ keyEXEC : {input.LT(1).getText().equals("exec")}? NAME ; //keyFROM : {input.LT(1).getText().equals("from")}? NAME ; //keyGLOBAL : {input.LT(1).getText().equals("global")}? NAME ; -keyIN : {input.LT(1).getText().equals("in")}? NAME ; +keyIN : {input.LT(1).getText().equals("in")}? NAME ; +keyCLASS : {input.LT(1).getText().equals("class")}? NAME ; //keyIS : {input.LT(1).getText().equals("is")}? NAME ; //keyLAMBDA : {input.LT(1).getText().equals("lambda")}? NAME ; //keyNOT : {input.LT(1).getText().equals("not")}? NAME ; @@ -1138,7 +1142,6 @@ //keyYIELD : {input.LT(1).getText().equals("yield")}? NAME ; DEF : 'def' ; -CLASS : 'class' ; PRINT : 'print' ; BREAK : 'break' ; CONTINUE : 'continue' ; @@ -1150,7 +1153,6 @@ FOR : 'for' ; ORELSE : 'else' ; ELIF : 'elif' ; -IN : 'in' ; IF : 'if' ; WHILE : 'while' ; WITH : 'with' ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-05 23:46:30 UTC (rev 5087) +++ branches/asm/grammar/PythonWalker.g 2008-08-06 02:19:54 UTC (rev 5088) @@ -748,7 +748,7 @@ //Using NAME instead of 'exec' for Java integration exec_stmt - : ^(NAME exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { + : ^(ExecTok exec=test[expr_contextType.Load] (^(Globals globals=test[expr_contextType.Load]))? (^(Locals locals=test[expr_contextType.Load]))?) { exprType g = null; if ($Globals != null) { g = $globals.etype; @@ -757,7 +757,7 @@ if ($Locals != null) { loc = $locals.etype; } - $stmts::statements.add(new Exec($NAME, $exec.etype, g, loc)); + $stmts::statements.add(new Exec($ExecTok, $exec.etype, g, loc)); } ; @@ -817,7 +817,7 @@ ; for_stmt - : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { + : ^(FOR ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) ^(Body body=stmts) (^(ORELSE orelse=stmts))?) { List o = null; if ($ORELSE != null) { o = $orelse.stypes; @@ -1040,7 +1040,7 @@ | LESSEQUAL {$op = cmpopType.LtE;} | ALT_NOTEQUAL {$op = cmpopType.NotEq;} | NOTEQUAL {$op = cmpopType.NotEq;} - | IN {$op = cmpopType.In;} + | InTok {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} | 'is' {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} @@ -1265,14 +1265,14 @@ ; classdef - : ^(CLASS classname=NAME (^(Bases bases))? ^(Body stmts)) { + : ^(ClassTok classname=NAME (^(Bases bases))? ^(Body stmts)) { List b; if ($Bases != null) { b = $bases.names; } else { b = new ArrayList(); } - $stmts::statements.add(makeClassDef($CLASS, $classname, b, $stmts.stypes)); + $stmts::statements.add(makeClassDef($ClassTok, $classname, b, $stmts.stypes)); } ; @@ -1365,7 +1365,7 @@ list_for [List gens] : - ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(IN iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { + ^(ListFor ^(Target targ=test[expr_contextType.Store]) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs list_iter[gens]))?) { debug("matched list_for"); exprType[] e; if ($Ifs != null && $list_iter.etype != null) { @@ -1391,7 +1391,7 @@ ; gen_for [List gens] - : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(IN iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { + : ^(GenFor ^(Target targ=test[expr_contextType.Store]+) ^(InTok iter=test[expr_contextType.Load]) (^(Ifs gen_iter[gens]))?) { debug("matched gen_for"); exprType[] e; if ($Ifs != null && $gen_iter.etype != null) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 23:46:35
|
Revision: 5087 http://jython.svn.sourceforge.net/jython/?rev=5087&view=rev Author: fwierzbicki Date: 2008-08-05 23:46:30 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Finish out "IN" as a token. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-05 23:44:49 UTC (rev 5086) +++ branches/asm/grammar/Python.g 2008-08-05 23:46:30 UTC (rev 5087) @@ -777,7 +777,7 @@ ; //exec_stmt: 'exec' expr ['in' test [',' test]] -exec_stmt : keyEXEC expr[expr_contextType.Load] ('in' t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? +exec_stmt : keyEXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? -> ^(keyEXEC expr ^(Globals $t1)? ^(Locals $t2)?) ; @@ -886,8 +886,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | 'in' - | NOT 'in' -> NotIn + | IN + | NOT IN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -1126,7 +1126,7 @@ keyEXEC : {input.LT(1).getText().equals("exec")}? NAME ; //keyFROM : {input.LT(1).getText().equals("from")}? NAME ; //keyGLOBAL : {input.LT(1).getText().equals("global")}? NAME ; -//keyIN : {input.LT(1).getText().equals("in")}? NAME ; +keyIN : {input.LT(1).getText().equals("in")}? NAME ; //keyIS : {input.LT(1).getText().equals("is")}? NAME ; //keyLAMBDA : {input.LT(1).getText().equals("lambda")}? NAME ; //keyNOT : {input.LT(1).getText().equals("not")}? NAME ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-05 23:44:49 UTC (rev 5086) +++ branches/asm/grammar/PythonWalker.g 2008-08-05 23:46:30 UTC (rev 5087) @@ -1040,7 +1040,7 @@ | LESSEQUAL {$op = cmpopType.LtE;} | ALT_NOTEQUAL {$op = cmpopType.NotEq;} | NOTEQUAL {$op = cmpopType.NotEq;} - | 'in' {$op = cmpopType.In;} + | IN {$op = cmpopType.In;} | NotIn {$op = cmpopType.NotIn;} | 'is' {$op = cmpopType.Is;} | IsNot {$op = cmpopType.IsNot;} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 23:44:52
|
Revision: 5086 http://jython.svn.sourceforge.net/jython/?rev=5086&view=rev Author: fwierzbicki Date: 2008-08-05 23:44:49 +0000 (Tue, 05 Aug 2008) Log Message: ----------- 2 new passing tests. Modified Paths: -------------- branches/asm/Lib/test/regrtest.py Modified: branches/asm/Lib/test/regrtest.py =================================================================== --- branches/asm/Lib/test/regrtest.py 2008-08-05 22:51:03 UTC (rev 5085) +++ branches/asm/Lib/test/regrtest.py 2008-08-05 23:44:49 UTC (rev 5086) @@ -1479,13 +1479,11 @@ test_codecmaps_tw test_copy test_dis - test_descrtut test_eof test_frozen test_gc test_iterlen test_marshal - test_pkgimport test_profilehooks test_pyclbr test_quopri This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 22:51:05
|
Revision: 5085 http://jython.svn.sourceforge.net/jython/?rev=5085&view=rev Author: fwierzbicki Date: 2008-08-05 22:51:03 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Fix test_pkgimport for Jython. Now deleting $py.class files on Jython, and using __builtin__ instead of the CPython implementatin specific __buitlins__. Modified Paths: -------------- branches/asm/Lib/test/test_pkgimport.py Modified: branches/asm/Lib/test/test_pkgimport.py =================================================================== --- branches/asm/Lib/test/test_pkgimport.py 2008-08-05 22:45:16 UTC (rev 5084) +++ branches/asm/Lib/test/test_pkgimport.py 2008-08-05 22:51:03 UTC (rev 5085) @@ -1,6 +1,6 @@ import os, sys, string, random, tempfile, unittest -from test.test_support import run_unittest +from test.test_support import run_unittest, is_jython class TestImport(unittest.TestCase): @@ -35,10 +35,16 @@ self.remove_modules() def rewrite_file(self, contents): - for extension in "co": - compiled_path = self.module_path + extension + if is_jython: + compiled_path = self.module_path.replace(".", "$") + ".class" if os.path.exists(compiled_path): os.remove(compiled_path) + else: + for extension in "co": + compiled_path = self.module_path + extension + if os.path.exists(compiled_path): + os.remove(compiled_path) + f = open(self.module_path, 'w') f.write(contents) f.close() @@ -56,8 +62,9 @@ not hasattr(sys.modules[self.package_name], 'foo')) # ...make up a variable name that isn't bound in __builtins__ + import __builtin__ var = 'a' - while var in dir(__builtins__): + while var in dir(__builtin__): var += random.choose(string.letters) # ...make a module that just contains that This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 22:45:20
|
Revision: 5084 http://jython.svn.sourceforge.net/jython/?rev=5084&view=rev Author: fwierzbicki Date: 2008-08-05 22:45:16 +0000 (Tue, 05 Aug 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_pkgimport.py@51333 Added Paths: ----------- branches/asm/Lib/test/test_pkgimport.py Added: branches/asm/Lib/test/test_pkgimport.py =================================================================== --- branches/asm/Lib/test/test_pkgimport.py (rev 0) +++ branches/asm/Lib/test/test_pkgimport.py 2008-08-05 22:45:16 UTC (rev 5084) @@ -0,0 +1,82 @@ +import os, sys, string, random, tempfile, unittest + +from test.test_support import run_unittest + +class TestImport(unittest.TestCase): + + def __init__(self, *args, **kw): + self.package_name = 'PACKAGE_' + while sys.modules.has_key(self.package_name): + self.package_name += random.choose(string.letters) + self.module_name = self.package_name + '.foo' + unittest.TestCase.__init__(self, *args, **kw) + + def remove_modules(self): + for module_name in (self.package_name, self.module_name): + if sys.modules.has_key(module_name): + del sys.modules[module_name] + + def setUp(self): + self.test_dir = tempfile.mkdtemp() + sys.path.append(self.test_dir) + self.package_dir = os.path.join(self.test_dir, + self.package_name) + os.mkdir(self.package_dir) + open(os.path.join(self.package_dir, '__init__'+os.extsep+'py'), 'w') + self.module_path = os.path.join(self.package_dir, 'foo'+os.extsep+'py') + + def tearDown(self): + for file in os.listdir(self.package_dir): + os.remove(os.path.join(self.package_dir, file)) + os.rmdir(self.package_dir) + os.rmdir(self.test_dir) + self.assertNotEqual(sys.path.count(self.test_dir), 0) + sys.path.remove(self.test_dir) + self.remove_modules() + + def rewrite_file(self, contents): + for extension in "co": + compiled_path = self.module_path + extension + if os.path.exists(compiled_path): + os.remove(compiled_path) + f = open(self.module_path, 'w') + f.write(contents) + f.close() + + def test_package_import__semantics(self): + + # Generate a couple of broken modules to try importing. + + # ...try loading the module when there's a SyntaxError + self.rewrite_file('for') + try: __import__(self.module_name) + except SyntaxError: pass + else: raise RuntimeError, 'Failed to induce SyntaxError' + self.assert_(not sys.modules.has_key(self.module_name) and + not hasattr(sys.modules[self.package_name], 'foo')) + + # ...make up a variable name that isn't bound in __builtins__ + var = 'a' + while var in dir(__builtins__): + var += random.choose(string.letters) + + # ...make a module that just contains that + self.rewrite_file(var) + + try: __import__(self.module_name) + except NameError: pass + else: raise RuntimeError, 'Failed to induce NameError.' + + # ...now change the module so that the NameError doesn't + # happen + self.rewrite_file('%s = 1' % var) + module = __import__(self.module_name).foo + self.assertEqual(getattr(module, var), 1) + + +def test_main(): + run_unittest(TestImport) + + +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-08-05 22:40:23
|
Revision: 5083 http://jython.svn.sourceforge.net/jython/?rev=5083&view=rev Author: fwierzbicki Date: 2008-08-05 22:40:19 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Forgot our convention. Removed Paths: ------------- branches/asm/Lib/test/test_pkgimport.py Deleted: branches/asm/Lib/test/test_pkgimport.py =================================================================== --- branches/asm/Lib/test/test_pkgimport.py 2008-08-05 22:39:04 UTC (rev 5082) +++ branches/asm/Lib/test/test_pkgimport.py 2008-08-05 22:40:19 UTC (rev 5083) @@ -1,89 +0,0 @@ -import os, sys, string, random, tempfile, unittest - -from test.test_support import run_unittest, is_jython - -class TestImport(unittest.TestCase): - - def __init__(self, *args, **kw): - self.package_name = 'PACKAGE_' - while sys.modules.has_key(self.package_name): - self.package_name += random.choose(string.letters) - self.module_name = self.package_name + '.foo' - unittest.TestCase.__init__(self, *args, **kw) - - def remove_modules(self): - for module_name in (self.package_name, self.module_name): - if sys.modules.has_key(module_name): - del sys.modules[module_name] - - def setUp(self): - self.test_dir = tempfile.mkdtemp() - sys.path.append(self.test_dir) - self.package_dir = os.path.join(self.test_dir, - self.package_name) - os.mkdir(self.package_dir) - open(os.path.join(self.package_dir, '__init__'+os.extsep+'py'), 'w') - self.module_path = os.path.join(self.package_dir, 'foo'+os.extsep+'py') - - def tearDown(self): - for file in os.listdir(self.package_dir): - os.remove(os.path.join(self.package_dir, file)) - os.rmdir(self.package_dir) - os.rmdir(self.test_dir) - self.assertNotEqual(sys.path.count(self.test_dir), 0) - sys.path.remove(self.test_dir) - self.remove_modules() - - def rewrite_file(self, contents): - if is_jython: - compiled_path = self.module_path.replace(".", "$") + ".class" - if os.path.exists(compiled_path): - os.remove(compiled_path) - else: - for extension in "co": - compiled_path = self.module_path + extension - if os.path.exists(compiled_path): - os.remove(compiled_path) - - f = open(self.module_path, 'w') - f.write(contents) - f.close() - - def test_package_import__semantics(self): - - # Generate a couple of broken modules to try importing. - - # ...try loading the module when there's a SyntaxError - self.rewrite_file('for') - try: __import__(self.module_name) - except SyntaxError: pass - else: raise RuntimeError, 'Failed to induce SyntaxError' - self.assert_(not sys.modules.has_key(self.module_name) and - not hasattr(sys.modules[self.package_name], 'foo')) - - # ...make up a variable name that isn't bound in __builtins__ - import __builtin__ - var = 'a' - while var in dir(__builtin__): - var += random.choose(string.letters) - - # ...make a module that just contains that - self.rewrite_file(var) - - try: __import__(self.module_name) - except NameError: pass - else: raise RuntimeError, 'Failed to induce NameError.' - - # ...now change the module so that the NameError doesn't - # happen - self.rewrite_file('%s = 1' % var) - module = __import__(self.module_name).foo - self.assertEqual(getattr(module, var), 1) - - -def test_main(): - run_unittest(TestImport) - - -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-08-05 22:39:06
|
Revision: 5082 http://jython.svn.sourceforge.net/jython/?rev=5082&view=rev Author: fwierzbicki Date: 2008-08-05 22:39:04 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Fix test_pkgimport for Jython (was deleting .pyc and .pyo files, now deleted $py.class files on Jython). Added Paths: ----------- branches/asm/Lib/test/test_pkgimport.py Added: branches/asm/Lib/test/test_pkgimport.py =================================================================== --- branches/asm/Lib/test/test_pkgimport.py (rev 0) +++ branches/asm/Lib/test/test_pkgimport.py 2008-08-05 22:39:04 UTC (rev 5082) @@ -0,0 +1,89 @@ +import os, sys, string, random, tempfile, unittest + +from test.test_support import run_unittest, is_jython + +class TestImport(unittest.TestCase): + + def __init__(self, *args, **kw): + self.package_name = 'PACKAGE_' + while sys.modules.has_key(self.package_name): + self.package_name += random.choose(string.letters) + self.module_name = self.package_name + '.foo' + unittest.TestCase.__init__(self, *args, **kw) + + def remove_modules(self): + for module_name in (self.package_name, self.module_name): + if sys.modules.has_key(module_name): + del sys.modules[module_name] + + def setUp(self): + self.test_dir = tempfile.mkdtemp() + sys.path.append(self.test_dir) + self.package_dir = os.path.join(self.test_dir, + self.package_name) + os.mkdir(self.package_dir) + open(os.path.join(self.package_dir, '__init__'+os.extsep+'py'), 'w') + self.module_path = os.path.join(self.package_dir, 'foo'+os.extsep+'py') + + def tearDown(self): + for file in os.listdir(self.package_dir): + os.remove(os.path.join(self.package_dir, file)) + os.rmdir(self.package_dir) + os.rmdir(self.test_dir) + self.assertNotEqual(sys.path.count(self.test_dir), 0) + sys.path.remove(self.test_dir) + self.remove_modules() + + def rewrite_file(self, contents): + if is_jython: + compiled_path = self.module_path.replace(".", "$") + ".class" + if os.path.exists(compiled_path): + os.remove(compiled_path) + else: + for extension in "co": + compiled_path = self.module_path + extension + if os.path.exists(compiled_path): + os.remove(compiled_path) + + f = open(self.module_path, 'w') + f.write(contents) + f.close() + + def test_package_import__semantics(self): + + # Generate a couple of broken modules to try importing. + + # ...try loading the module when there's a SyntaxError + self.rewrite_file('for') + try: __import__(self.module_name) + except SyntaxError: pass + else: raise RuntimeError, 'Failed to induce SyntaxError' + self.assert_(not sys.modules.has_key(self.module_name) and + not hasattr(sys.modules[self.package_name], 'foo')) + + # ...make up a variable name that isn't bound in __builtins__ + import __builtin__ + var = 'a' + while var in dir(__builtin__): + var += random.choose(string.letters) + + # ...make a module that just contains that + self.rewrite_file(var) + + try: __import__(self.module_name) + except NameError: pass + else: raise RuntimeError, 'Failed to induce NameError.' + + # ...now change the module so that the NameError doesn't + # happen + self.rewrite_file('%s = 1' % var) + module = __import__(self.module_name).foo + self.assertEqual(getattr(module, var), 1) + + +def test_main(): + run_unittest(TestImport) + + +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-08-05 20:21:28
|
Revision: 5081 http://jython.svn.sourceforge.net/jython/?rev=5081&view=rev Author: fwierzbicki Date: 2008-08-05 20:21:24 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Commenting out the strange eval parsing errors - I'm working elsewhere at the moment and having test_jy_compile as a coal mine canary will be very helpful. Modified Paths: -------------- branches/asm/Lib/test/test_jy_compile.py Modified: branches/asm/Lib/test/test_jy_compile.py =================================================================== --- branches/asm/Lib/test/test_jy_compile.py 2008-08-05 17:16:19 UTC (rev 5080) +++ branches/asm/Lib/test/test_jy_compile.py 2008-08-05 20:21:24 UTC (rev 5081) @@ -148,10 +148,13 @@ ai("a = 'a\\ ") ai("a = 'a\\\n") - ai("a = 1","eval") - ai("a = (","eval") + #XXX: eval is hopelessly permissive right now -- but the rest of this + # test_jy_compile is really important to me for flagging new bugs - + # so commenting out some of these for now. + ###ai("a = 1","eval") + ###ai("a = (","eval") ai("]","eval") - ai("())","eval") + ###ai("())","eval") ai("[}","eval") ai("9+","eval") ai("lambda z:","eval") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 17:16:24
|
Revision: 5080 http://jython.svn.sourceforge.net/jython/?rev=5080&view=rev Author: fwierzbicki Date: 2008-08-05 17:16:19 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Guard against null text in PySyntaxError. Modified Paths: -------------- branches/asm/src/org/python/core/PySyntaxError.java Modified: branches/asm/src/org/python/core/PySyntaxError.java =================================================================== --- branches/asm/src/org/python/core/PySyntaxError.java 2008-08-05 16:55:18 UTC (rev 5079) +++ branches/asm/src/org/python/core/PySyntaxError.java 2008-08-05 17:16:19 UTC (rev 5080) @@ -20,6 +20,11 @@ String filename) { super(Py.SyntaxError); + //XXX: null text causes Java error, though I bet I'm not supposed to + // get null text. + if (text == null) { + text = ""; + } PyObject[] tmp = new PyObject[] { new PyString(filename), new PyInteger(line), new PyInteger(column), new PyString(text) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-05 16:55:25
|
Revision: 5079 http://jython.svn.sourceforge.net/jython/?rev=5079&view=rev Author: fwierzbicki Date: 2008-08-05 16:55:18 +0000 (Tue, 05 Aug 2008) Log Message: ----------- Reworked lexing of newlines and EOF. Broke up PythonTokenSource into more useful methods. Removed inSingle from Python.g and added it to PythonTokenSource. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/InteractiveParser.java branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-04 21:34:24 UTC (rev 5078) +++ branches/asm/grammar/Python.g 2008-08-05 16:55:18 UTC (rev 5079) @@ -182,9 +182,6 @@ } @members { - //XXX: only used for single_input -- seems kludgy. - public boolean inSingle = false; - boolean debugOn = false; private ErrorHandler errorHandler; @@ -443,8 +440,6 @@ //and the same one in the parser. private ErrorHandler errorHandler; -//XXX: Hopefully we can remove inSingle when we get PyCF_DONT_IMPLY_DEDENT support. -public boolean inSingle = false; int implicitLineJoiningLevel = 0; int startPos=-1; @@ -489,7 +484,7 @@ } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE -single_input : NEWLINE -> ^(Interactive) +single_input : NEWLINE? -> ^(Interactive) | simple_stmt -> ^(Interactive simple_stmt) | compound_stmt NEWLINE -> ^(Interactive compound_stmt) ; @@ -1349,12 +1344,11 @@ * Frank Wierzbicki added: Also ignore FORMFEEDS (\u000C). */ NEWLINE - : {inSingle}? => (('\u000C')?('\r')? '\n' ) - {if (implicitLineJoiningLevel>0 ) - $channel=HIDDEN; - } - | (('\u000C')?('\r')? '\n' )+ - {if ( startPos==0 || implicitLineJoiningLevel>0 ) +@init { + int newlines = 0; +} + : (('\u000C')?('\r')? '\n' {newlines++; } )+ { + if ( startPos==0 || implicitLineJoiningLevel>0 ) $channel=HIDDEN; } ; @@ -1371,30 +1365,42 @@ LEADING_WS @init { int spaces = 0; + int newlines = 0; } : {startPos==0}?=> ( {implicitLineJoiningLevel>0}? ( ' ' | '\t' )+ {$channel=HIDDEN;} | ( ' ' { spaces++; } | '\t' { spaces += 8; spaces -= (spaces \% 8); } )+ - { - // make a string of n spaces where n is column number - 1 - char[] indentation = new char[spaces]; - for (int i=0; i<spaces; i++) { - indentation[i] = ' '; - } - if (input.LA(1) != -1) { - CommonToken c = new CommonToken(LEADING_WS,new String(indentation)); - c.setLine(input.getLine()); - c.setCharPositionInLine(input.getCharPositionInLine()); - emit(c); - } else { - emit(new CommonToken(LEADING_WS,"")); - } - } - // kill trailing newline if present and then ignore - ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* - // {state.token.setChannel(99); } + ( ('\r')? '\n' {newlines++; } + )* { + if (input.LA(1) != -1) { + // make a string of n spaces where n is column number - 1 + char[] indentation = new char[spaces]; + for (int i=0; i<spaces; i++) { + indentation[i] = ' '; + } + CommonToken c = new CommonToken(LEADING_WS,new String(indentation)); + c.setLine(input.getLine()); + c.setCharPositionInLine(input.getCharPositionInLine()); + emit(c); + // kill trailing newline if present and then ignore + if (newlines != 0) { + if (state.token!=null) { + state.token.setChannel(HIDDEN); + } else { + $channel=HIDDEN; + } + } + } else { + // make a string of n newlines + char[] nls = new char[newlines]; + for (int i=0; i<newlines; i++) { + nls[i] = '\n'; + } + emit(new CommonToken(NEWLINE,new String(nls))); + } + } ) ; Modified: branches/asm/src/org/python/antlr/InteractiveParser.java =================================================================== --- branches/asm/src/org/python/antlr/InteractiveParser.java 2008-08-04 21:34:24 UTC (rev 5078) +++ branches/asm/src/org/python/antlr/InteractiveParser.java 2008-08-05 16:55:18 UTC (rev 5079) @@ -41,15 +41,12 @@ modType tree = null; PythonLexer lexer = new PyLexer(new NoCloseReaderStream(bufreader)); lexer.setErrorHandler(errorHandler); - //XXX: Hopefully we can remove inSingle when we get PyCF_DONT_IMPLY_DEDENT support. - lexer.inSingle = true; CommonTokenStream tokens = new CommonTokenStream(lexer); tokens.discardOffChannelTokens(true); - PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); + PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename, true); tokens = new CommonTokenStream(indentedSource); PythonParser parser = new PythonParser(tokens); parser.setErrorHandler(errorHandler); - parser.inSingle = true; parser.setTreeAdaptor(new PythonTreeAdaptor()); try { Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-04 21:34:24 UTC (rev 5078) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-05 16:55:18 UTC (rev 5079) @@ -91,13 +91,20 @@ int lastTokenAddedIndex = -1; String filename; + boolean inSingle; public PythonTokenSource(PythonLexer lexer) { } + public PythonTokenSource(CommonTokenStream stream, String filename) { + this(stream, filename, false); + } + + public PythonTokenSource(CommonTokenStream stream, String filename, boolean single) { this.stream = stream; this.filename = filename; + this.inSingle = single; // "state" of indent level is FIRST_CHAR_POSITION push(FIRST_CHAR_POSITION); } @@ -129,7 +136,7 @@ if (tokens.size() > 0) { Token t = (Token)tokens.firstElement(); tokens.removeElementAt(0); - //System.out.println(t); + //System.out.println(filename + t); return t; } @@ -138,32 +145,36 @@ return nextToken(); } + private void generateNewline(Token t) { + // Imaginary newline before EOF + CommonToken newline = new CommonToken(PythonLexer.NEWLINE, "\n"); + newline.setLine(t.getLine()); + newline.setCharPositionInLine(t.getCharPositionInLine()); + tokens.addElement(newline); + } + protected void insertImaginaryIndentDedentTokens() { Token t = stream.LT(1); stream.consume(); - // if the current token is not a NEWLINE or EOF, it doesn't signal indent/dedent work; just enqueue - if (t.getType() != PythonLexer.NEWLINE && t.getType() != PythonLexer.EOF) { - List hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); - if (hiddenTokens != null) { - tokens.addAll(hiddenTokens); + if (t.getType() == Token.EOF) { + Token prev = stream.LT(-1); + if (!inSingle && (prev == null || prev.getType() != PythonLexer.NEWLINE)) { + generateNewline(t); } - lastTokenAddedIndex = t.getTokenIndex(); - tokens.addElement(t); - return; - } - CommonToken newline; - if (t.getType() == PythonLexer.NEWLINE) { + handleDedents(-1, (CommonToken)t); + enqueue(t); + } else if (t.getType() == PythonLexer.NEWLINE) { // save NEWLINE in the queue //System.out.println("found newline: "+t+" stack is "+stackString()); - newline = (CommonToken)t; List hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); if (hiddenTokens!=null) { tokens.addAll(hiddenTokens); } lastTokenAddedIndex = t.getTokenIndex(); tokens.addElement(t); + Token newline = t; // grab first token of next line t = stream.LT(1); @@ -174,63 +185,85 @@ tokens.addAll(hiddenTokens); } lastTokenAddedIndex = t.getTokenIndex(); - } else { - // Imaginary newline before EOF - newline = new CommonToken(PythonLexer.NEWLINE, "\n"); - newline.setLine(t.getLine()); - newline.setCharPositionInLine(t.getCharPositionInLine()); - //XXX: this is where lsoto had this... - //tokens.addElement(newline); - } - // compute cpos as the char pos of next non-WS token in line - int cpos = t.getCharPositionInLine(); // column dictates indent/dedent - if (t.getType() == Token.EOF) { - cpos = -1; // pretend EOF always happens at left edge - } - else if (t.getType() == PythonLexer.LEADING_WS) { - cpos = t.getText().length(); - } + // compute cpos as the char pos of next non-WS token in line + int cpos = t.getCharPositionInLine(); // column dictates indent/dedent + if (t.getType() == Token.EOF) { + cpos = -1; // pretend EOF always happens at left edge + } + else if (t.getType() == PythonLexer.LEADING_WS) { + Token next = stream.LT(1); + if (next != null && next.getType() == Token.EOF) { + stream.consume(); + return; + } else { + cpos = t.getText().length(); + } + } - //System.out.println("next token is: "+t); + //System.out.println("next token is: "+t); - // compare to last indent level - int lastIndent = peek(); - //System.out.println("cpos, lastIndent = "+cpos+", "+lastIndent); - if (cpos > lastIndent) { // they indented; track and gen INDENT - push(cpos); - //System.out.println("push("+cpos+"): "+stackString()); - Token indent = new CommonToken(PythonParser.INDENT,""); - indent.setCharPositionInLine(t.getCharPositionInLine()); - indent.setLine(t.getLine()); - tokens.addElement(indent); - } - else if (cpos < lastIndent) { // they dedented - // how far back did we dedent? - int prevIndex = findPreviousIndent(cpos, t); - //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex); - // generate DEDENTs for each indent level we backed up over - for (int d = sp - 1; d >= prevIndex; d--) { - CommonToken dedent = new CommonToken(PythonParser.DEDENT,""); - dedent.setCharPositionInLine(t.getCharPositionInLine()); - dedent.setLine(t.getLine()); + // compare to last indent level + int lastIndent = peek(); + //System.out.println("cpos, lastIndent = "+cpos+", "+lastIndent); + if (cpos > lastIndent) { // they indented; track and gen INDENT + handleIndents(cpos, (CommonToken)t); + } + else if (cpos < lastIndent) { // they dedented + handleDedents(cpos, (CommonToken)t); + } - //XXX: this will get messed up by comments. - dedent.setStartIndex(newline.getStartIndex()); - dedent.setStopIndex(newline.getStopIndex()); + if (t.getType() == Token.EOF && inSingle) { + String newlines = newline.getText(); + for(int i=1;i<newlines.length();i++) { + generateNewline(newline); + } + } - tokens.addElement(dedent); + if (t.getType() != PythonLexer.LEADING_WS) { // discard WS + tokens.addElement(t); } - sp = prevIndex; // pop those off indent level + + } else { + enqueue(t); } - //XXX: make sure lsoto's stuff isn't broken by this... - if (t.getType() == PythonLexer.EOF) { - tokens.addElement(newline); + } + + private void enqueue(Token t) { + List hiddenTokens = stream.getTokens(lastTokenAddedIndex + 1,t.getTokenIndex() - 1); + if (hiddenTokens != null) { + tokens.addAll(hiddenTokens); } + lastTokenAddedIndex = t.getTokenIndex(); + tokens.addElement(t); + } - if (t.getType() != PythonLexer.LEADING_WS) { // discard WS - tokens.addElement(t); + private void handleIndents(int cpos, CommonToken t) { + push(cpos); + //System.out.println("push("+cpos+"): "+stackString()); + Token indent = new CommonToken(PythonParser.INDENT,""); + indent.setCharPositionInLine(t.getCharPositionInLine()); + indent.setLine(t.getLine()); + tokens.addElement(indent); + } + + private void handleDedents(int cpos, CommonToken t) { + // how far back did we dedent? + int prevIndex = findPreviousIndent(cpos, t); + //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex); + // generate DEDENTs for each indent level we backed up over + for (int d = sp - 1; d >= prevIndex; d--) { + CommonToken dedent = new CommonToken(PythonParser.DEDENT,""); + dedent.setCharPositionInLine(t.getCharPositionInLine()); + dedent.setLine(t.getLine()); + + //XXX: this will get messed up by comments. + dedent.setStartIndex(t.getStartIndex()); + dedent.setStopIndex(t.getStopIndex()); + + tokens.addElement(dedent); } + sp = prevIndex; // pop those off indent level } // T O K E N S T A C K M E T H O D S This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-08-04 21:34:29
|
Revision: 5078 http://jython.svn.sourceforge.net/jython/?rev=5078&view=rev Author: pjenvey Date: 2008-08-04 21:34:24 +0000 (Mon, 04 Aug 2008) Log Message: ----------- gather more info about the flakey test_hash OutOfMemoryError Added Paths: ----------- branches/asm/Lib/test/test_tuple.py Added: branches/asm/Lib/test/test_tuple.py =================================================================== --- branches/asm/Lib/test/test_tuple.py (rev 0) +++ branches/asm/Lib/test/test_tuple.py 2008-08-04 21:34:24 UTC (rev 5078) @@ -0,0 +1,95 @@ +import unittest +from test import test_support, seq_tests + +class TupleTest(seq_tests.CommonTest): + type2test = tuple + + def test_constructors(self): + super(TupleTest, self).test_len() + # calling built-in types without argument must return empty + self.assertEqual(tuple(), ()) + + def test_truth(self): + super(TupleTest, self).test_truth() + self.assert_(not ()) + self.assert_((42, )) + + def test_len(self): + super(TupleTest, self).test_len() + self.assertEqual(len(()), 0) + self.assertEqual(len((0,)), 1) + self.assertEqual(len((0, 1, 2)), 3) + + def test_iadd(self): + super(TupleTest, self).test_iadd() + u = (0, 1) + u2 = u + u += (2, 3) + self.assert_(u is not u2) + + def test_imul(self): + super(TupleTest, self).test_imul() + u = (0, 1) + u2 = u + u *= 3 + self.assert_(u is not u2) + + def test_tupleresizebug(self): + # Check that a specific bug in _PyTuple_Resize() is squashed. + def f(): + for i in range(1000): + yield i + self.assertEqual(list(tuple(f())), range(1000)) + + def test_hash(self): + from java.lang import OutOfMemoryError + try: + self._test_hash() + except OutOfMemoryError, oome: + oome.printStackTrace() + raise + + def _test_hash(self): + # See SF bug 942952: Weakness in tuple hash + # The hash should: + # be non-commutative + # should spread-out closely spaced values + # should not exhibit cancellation in tuples like (x,(x,y)) + # should be distinct from element hashes: hash(x)!=hash((x,)) + # This test exercises those cases. + # For a pure random hash and N=50, the expected number of occupied + # buckets when tossing 252,600 balls into 2**32 buckets + # is 252,592.6, or about 7.4 expected collisions. The + # standard deviation is 2.73. On a box with 64-bit hash + # codes, no collisions are expected. Here we accept no + # more than 15 collisions. Any worse and the hash function + # is sorely suspect. + + N=50 + base = range(N) + xp = [(i, j) for i in base for j in base] + inps = base + [(i, j) for i in base for j in xp] + \ + [(i, j) for i in xp for j in base] + xp + zip(base) + hashes = map(hash, inps) + unique = set(hashes) + unique_len = len(unique) + collisions = len(inps) - unique_len + #collisions = len(inps) - len(set(map(hash, inps))) + self.assert_(collisions <= 15) + + def test_repr(self): + l0 = tuple() + l2 = (0, 1, 2) + a0 = self.type2test(l0) + a2 = self.type2test(l2) + + self.assertEqual(str(a0), repr(l0)) + self.assertEqual(str(a2), repr(l2)) + self.assertEqual(repr(a0), "()") + self.assertEqual(repr(a2), "(0, 1, 2)") + +def test_main(): + test_support.run_unittest(TupleTest) + +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-08-04 17:57:43
|
Revision: 5077 http://jython.svn.sourceforge.net/jython/?rev=5077&view=rev Author: fwierzbicki Date: 2008-08-04 17:57:34 +0000 (Mon, 04 Aug 2008) Log Message: ----------- In test_decorators.py, test_eval_order cleverly instruments a decorated call so the order of evaluation and calls can be determined. It also checks to see if the decoration works exactly the same when translated to nested function calls. Jython was evaluating the arguments before the function name, the opposite of CPython. This patch makes the order correct for both decorators and normal function calls. Also, PyObject.invoke states in its comments that it is for use from Java and shows the equivalent o.__getattr__(name).__call__(args, keywords) which is how I am constructing a call in the bytecode. I also thought that "Invoke" with a capitalized name was non-ideal, so I changed the name to invokeNoKeywords, which also allowed me to remove a comment that conveyed the same meaning. Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java branches/asm/src/org/python/core/imp.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-04 03:23:57 UTC (rev 5076) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-08-04 17:57:34 UTC (rev 5077) @@ -1385,29 +1385,30 @@ c.freeLocal(strings); } - public Object Invoke(Attribute node, PythonTree[] values) + public Object invokeNoKeywords(Attribute node, PythonTree[] values) throws Exception { String name = getName(node.attr); visit(node.value); code.ldc(name); + code.invokevirtual("org/python/core/PyObject", "__getattr__", "(" + $str + ")" + $pyObj); switch (values.length) { case 0: - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "()" + $pyObj); break; case 1: visit(values[0]); - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + $pyObj + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + ")" + $pyObj); break; case 2: visit(values[0]); visit(values[1]); - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + $pyObj + $pyObj + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObj + $pyObj + ")" + $pyObj); break; default: makeArray(values); - code.invokevirtual("org/python/core/PyObject", "invoke", "(" + $str + $pyObjArr + ")" + $pyObj); + code.invokevirtual("org/python/core/PyObject", "__call__", "(" + $pyObjArr + ")" + $pyObj); break; } return null; @@ -1425,11 +1426,10 @@ values[node.args.length + i] = node.keywords[i].value; } - // Detect a method invocation with no keywords if ((node.keywords == null || node.keywords.length == 0)&& node.starargs == null && node.kwargs == null && node.func instanceof Attribute) { - return Invoke((Attribute) node.func, values); + return invokeNoKeywords((Attribute) node.func, values); } visit(node.func); Modified: branches/asm/src/org/python/core/imp.java =================================================================== --- branches/asm/src/org/python/core/imp.java 2008-08-04 03:23:57 UTC (rev 5076) +++ branches/asm/src/org/python/core/imp.java 2008-08-04 17:57:34 UTC (rev 5077) @@ -22,7 +22,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 14; + public static final int APIVersion = 15; /** A non-empty fromlist for __import__'ing sub-modules. */ private static final PyObject nonEmptyFromlist = new PyTuple(Py.newString("__doc__")); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-08-04 03:23:59
|
Revision: 5076 http://jython.svn.sourceforge.net/jython/?rev=5076&view=rev Author: nriley Date: 2008-08-04 03:23:57 +0000 (Mon, 04 Aug 2008) Log Message: ----------- Truncate files opened with the 'w+' mode; some FileIO cleanup. Re-fixes test_fileno. Modified Paths: -------------- branches/asm/src/org/python/core/io/FileIO.java Modified: branches/asm/src/org/python/core/io/FileIO.java =================================================================== --- branches/asm/src/org/python/core/io/FileIO.java 2008-08-04 02:36:46 UTC (rev 5075) +++ branches/asm/src/org/python/core/io/FileIO.java 2008-08-04 03:23:57 UTC (rev 5076) @@ -31,16 +31,16 @@ /** The underlying file (if known) */ private RandomAccessFile file; - /** true if the file is readable */ - private boolean readable = false; + /** true if the file is opened for reading ('r') */ + private boolean reading = false; - /** true if the file is writable */ - private boolean writable = false; + /** true if the file is opened for writing ('w', 'a', or '+') */ + private boolean writing = false; - /** true if the file is in appending mode */ + /** true if the file is in appending mode ('a') */ private boolean appending = false; - /** true if the file is opened for reading and writing */ + /** true if the file is opened for reading and writing ('+') */ private boolean plus = false; /** @@ -57,10 +57,10 @@ parseMode(mode); File fullPath = new RelativeFile(name); - String rafMode = "r" + (writable ? "w" : ""); + String rafMode = "r" + (writing ? "w" : ""); try { - if (plus && mode.charAt(0) == 'r' && !fullPath.isFile()) { - writable = false; + if (plus && reading && !fullPath.isFile()) { + writing = false; // suppress "permission denied" throw new FileNotFoundException(""); } file = new RandomAccessFile(fullPath, rafMode); @@ -69,7 +69,7 @@ if (fullPath.isDirectory()) { throw Py.IOError(errno.EISDIR, "Is a directory"); } - if ((writable && !fullPath.canWrite()) + if ((writing && !fullPath.canWrite()) || fnfe.getMessage().endsWith("(Permission denied)")) { throw Py.IOError(errno.EACCES, "Permission denied: '" + name + "'"); } @@ -113,25 +113,25 @@ if (plus || rwa) { badMode(); } - readable = rwa = true; + reading = rwa = true; break; case 'w': if (plus || rwa) { badMode(); } - writable = rwa = true; + writing = rwa = true; break; case 'a': if (plus || rwa) { badMode(); } - appending = writable = rwa = true; + appending = writing = rwa = true; break; case '+': if (plus || !rwa) { badMode(); } - readable = writable = plus = true; + writing = plus = true; break; default: throw Py.ValueError("invalid mode: '" + mode + "'"); @@ -153,13 +153,13 @@ } /** - * Set the appropriate file position for writable/appending modes. + * Set the appropriate file position for writing/appending modes. * */ private void initPosition() { if (appending) { seek(0, 2); - } else if (writable && !readable) { + } else if (writing && !reading) { try { fileChannel.truncate(0); } catch (IOException ioe) { @@ -335,9 +335,9 @@ /** {@inheritDoc} */ public Object __tojava__(Class cls) { - if (OutputStream.class.isAssignableFrom(cls) && writable) { + if (OutputStream.class.isAssignableFrom(cls) && writing) { return Channels.newOutputStream(fileChannel); - } else if (InputStream.class.isAssignableFrom(cls) && readable) { + } else if (InputStream.class.isAssignableFrom(cls) && readable()) { return Channels.newInputStream(fileChannel); } return super.__tojava__(cls); @@ -345,12 +345,12 @@ /** {@inheritDoc} */ public boolean readable() { - return readable; + return reading || plus; } /** {@inheritDoc} */ public boolean writable() { - return writable; + return writing; } /** {@inheritDoc} */ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-04 02:36:48
|
Revision: 5075 http://jython.svn.sourceforge.net/jython/?rev=5075&view=rev Author: fwierzbicki Date: 2008-08-04 02:36:46 +0000 (Mon, 04 Aug 2008) Log Message: ----------- Some checks for assignment to None. Modified Paths: -------------- branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-08-04 01:15:48 UTC (rev 5074) +++ branches/asm/grammar/PythonWalker.g 2008-08-04 02:36:46 UTC (rev 5075) @@ -286,6 +286,12 @@ } return new UnaryOp(t, unaryopType.USub, o); } + + private void checkAssign(exprType e) { + if (e instanceof Name && ((Name)e).id.equals("None")) { + throw new ParseException("assignment to None", e); + } + } } @rulecatch { @@ -336,6 +342,7 @@ defparameter[List params, List defaults] : fpdef[expr_contextType.Param, null] (ASSIGN test[expr_contextType.Load])? { + checkAssign($fpdef.etype); params.add($fpdef.etype); if ($ASSIGN != null) { defaults.add($test.etype); @@ -494,6 +501,7 @@ target[List etypes] : ^(Target atom[expr_contextType.Store]) { + checkAssign($atom.etype); etypes.add($atom.etype); } ; @@ -1343,6 +1351,7 @@ keyword[List kws] : ^(Keyword ^(Arg arg=test[expr_contextType.Load]) ^(Value val=test[expr_contextType.Load])) { + checkAssign($arg.etype); kws.add(new keywordType($Keyword, $arg.text, $val.etype)); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-04 01:15:50
|
Revision: 5074 http://jython.svn.sourceforge.net/jython/?rev=5074&view=rev Author: fwierzbicki Date: 2008-08-04 01:15:48 +0000 (Mon, 04 Aug 2008) Log Message: ----------- Fixes to handle parsing with files that have no newline at the end. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonTokenSource.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-03 22:54:14 UTC (rev 5073) +++ branches/asm/grammar/Python.g 2008-08-04 01:15:48 UTC (rev 5074) @@ -1383,10 +1383,14 @@ for (int i=0; i<spaces; i++) { indentation[i] = ' '; } - CommonToken c = new CommonToken(LEADING_WS,new String(indentation)); - c.setLine(input.getLine()); - c.setCharPositionInLine(input.getCharPositionInLine()); - emit(c); + if (input.LA(1) != -1) { + CommonToken c = new CommonToken(LEADING_WS,new String(indentation)); + c.setLine(input.getLine()); + c.setCharPositionInLine(input.getCharPositionInLine()); + emit(c); + } else { + emit(new CommonToken(LEADING_WS,"")); + } } // kill trailing newline if present and then ignore ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-03 22:54:14 UTC (rev 5073) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-04 01:15:48 UTC (rev 5074) @@ -179,8 +179,8 @@ newline = new CommonToken(PythonLexer.NEWLINE, "\n"); newline.setLine(t.getLine()); newline.setCharPositionInLine(t.getCharPositionInLine()); - //XXX: should be moved to after DEDENTS are generated, but doesn't work yet. - tokens.addElement(newline); + //XXX: this is where lsoto had this... + //tokens.addElement(newline); } // compute cpos as the char pos of next non-WS token in line @@ -223,13 +223,10 @@ } sp = prevIndex; // pop those off indent level } - /* - //XXX: I think this is really where this needs to be, but causes more problems than it - // solves at the moment. + //XXX: make sure lsoto's stuff isn't broken by this... if (t.getType() == PythonLexer.EOF) { tokens.addElement(newline); } - */ if (t.getType() != PythonLexer.LEADING_WS) { // discard WS tokens.addElement(t); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-03 22:54:17
|
Revision: 5073 http://jython.svn.sourceforge.net/jython/?rev=5073&view=rev Author: fwierzbicki Date: 2008-08-03 22:54:14 +0000 (Sun, 03 Aug 2008) Log Message: ----------- CommonToken now appears to cover the cases that ClassicToken was left around to cover. Removed all ClassicToken. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonPartialTokenSource.java branches/asm/src/org/python/antlr/PythonTokenSource.java branches/asm/src/org/python/antlr/PythonTree.java branches/asm/src/org/python/antlr/PythonTreeAdaptor.java Removed Paths: ------------- branches/asm/src/org/python/antlr/ImaginaryToken.java Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-03 21:45:49 UTC (rev 5072) +++ branches/asm/grammar/Python.g 2008-08-03 22:54:14 UTC (rev 5073) @@ -1337,7 +1337,7 @@ */ CONTINUED_LINE : '\\' ('\r')? '\n' (' '|'\t')* { $channel=HIDDEN; } - ( nl=NEWLINE {emit(new ClassicToken(NEWLINE,nl.getText()));} + ( nl=NEWLINE {emit(new CommonToken(NEWLINE,nl.getText()));} | ) ; @@ -1383,7 +1383,7 @@ for (int i=0; i<spaces; i++) { indentation[i] = ' '; } - ClassicToken c = new ClassicToken(LEADING_WS,new String(indentation)); + CommonToken c = new CommonToken(LEADING_WS,new String(indentation)); c.setLine(input.getLine()); c.setCharPositionInLine(input.getCharPositionInLine()); emit(c); Deleted: branches/asm/src/org/python/antlr/ImaginaryToken.java =================================================================== --- branches/asm/src/org/python/antlr/ImaginaryToken.java 2008-08-03 21:45:49 UTC (rev 5072) +++ branches/asm/src/org/python/antlr/ImaginaryToken.java 2008-08-03 22:54:14 UTC (rev 5073) @@ -1,29 +0,0 @@ -package org.python.antlr; - -import org.antlr.runtime.ClassicToken; - -public class ImaginaryToken extends ClassicToken { - - protected int start; - protected int stop; - - public ImaginaryToken(int ttype, String text) { - super(ttype, text); - } - - public int getStartIndex() { - return start; - } - - public void setStartIndex(int start) { - this.start = start; - } - - public int getStopIndex() { - return stop; - } - - public void setStopIndex(int stop) { - this.stop = stop; - } -} Modified: branches/asm/src/org/python/antlr/PythonPartialTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonPartialTokenSource.java 2008-08-03 21:45:49 UTC (rev 5072) +++ branches/asm/src/org/python/antlr/PythonPartialTokenSource.java 2008-08-03 22:54:14 UTC (rev 5073) @@ -83,7 +83,7 @@ stream.consume(); if ( t.getType()==Token.EOF ) { atEnd = true; - Token em = new ClassicToken(PythonPartialParser.ENDMARKER,""); + Token em = new CommonToken(PythonPartialParser.ENDMARKER,""); em.setCharPositionInLine(t.getCharPositionInLine()); em.setLine(t.getLine()); tokens.addElement(em); @@ -123,7 +123,7 @@ int cpos = t.getCharPositionInLine(); // column dictates indent/dedent if ( t.getType()==Token.EOF ) { atEnd = true; - Token em = new ClassicToken(PythonPartialParser.ENDMARKER,""); + Token em = new CommonToken(PythonPartialParser.ENDMARKER,""); em.setCharPositionInLine(t.getCharPositionInLine()); em.setLine(t.getLine()); tokens.addElement(em); @@ -142,7 +142,7 @@ if ( cpos > lastIndent ) { // they indented; track and gen INDENT push(cpos); //System.out.println("push("+cpos+"): "+stackString()); - Token indent = new ClassicToken(PythonPartialParser.INDENT,""); + Token indent = new CommonToken(PythonPartialParser.INDENT,""); indent.setCharPositionInLine(t.getCharPositionInLine()); indent.setLine(t.getLine()); tokens.addElement(indent); @@ -155,9 +155,9 @@ for (int d=sp-1; d>=prevIndex; d--) { Token tok; if (atEnd) { - tok = new ClassicToken(PythonPartialParser.ENDMARKER,""); + tok = new CommonToken(PythonPartialParser.ENDMARKER,""); } else { - tok = new ClassicToken(PythonPartialParser.DEDENT,""); + tok = new CommonToken(PythonPartialParser.DEDENT,""); } tok.setCharPositionInLine(t.getCharPositionInLine()); tok.setLine(t.getLine()); Modified: branches/asm/src/org/python/antlr/PythonTokenSource.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-03 21:45:49 UTC (rev 5072) +++ branches/asm/src/org/python/antlr/PythonTokenSource.java 2008-08-03 22:54:14 UTC (rev 5073) @@ -200,7 +200,7 @@ if (cpos > lastIndent) { // they indented; track and gen INDENT push(cpos); //System.out.println("push("+cpos+"): "+stackString()); - Token indent = new ImaginaryToken(PythonParser.INDENT,""); + Token indent = new CommonToken(PythonParser.INDENT,""); indent.setCharPositionInLine(t.getCharPositionInLine()); indent.setLine(t.getLine()); tokens.addElement(indent); @@ -211,7 +211,7 @@ //System.out.println("dedented; prevIndex of cpos="+cpos+" is "+prevIndex); // generate DEDENTs for each indent level we backed up over for (int d = sp - 1; d >= prevIndex; d--) { - ImaginaryToken dedent = new ImaginaryToken(PythonParser.DEDENT,""); + CommonToken dedent = new CommonToken(PythonParser.DEDENT,""); dedent.setCharPositionInLine(t.getCharPositionInLine()); dedent.setLine(t.getLine()); Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-08-03 21:45:49 UTC (rev 5072) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-08-03 22:54:14 UTC (rev 5073) @@ -152,12 +152,7 @@ public int getCharStartIndex() { if (charStartIndex == -1 && token != null) { - if (token instanceof CommonToken) { - return ((CommonToken)token).getStartIndex(); - } - if (token instanceof ImaginaryToken) { - return ((ImaginaryToken)token).getStartIndex(); - } + return ((CommonToken)token).getStartIndex(); } return charStartIndex ; } @@ -178,12 +173,7 @@ public int getCharStopIndex() { if (charStopIndex == -1 && token != null) { - if (token instanceof CommonToken) { - return ((CommonToken)token).getStopIndex() + 1; - } - if (token instanceof ImaginaryToken) { - return ((ImaginaryToken)token).getStopIndex() + 1; - } + return ((CommonToken)token).getStopIndex() + 1; } return charStopIndex; } Modified: branches/asm/src/org/python/antlr/PythonTreeAdaptor.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-08-03 21:45:49 UTC (rev 5072) +++ branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-08-03 22:54:14 UTC (rev 5073) @@ -18,23 +18,11 @@ int stopChar = 0; if (startToken!=null) { start = startToken.getTokenIndex(); - //XXX: instanceof is necessary because of the use of ClassicToken - // for leading whitespace lexing. - if (startToken instanceof CommonToken) { - startChar = ((CommonToken)startToken).getStartIndex(); - } else if (startToken instanceof ImaginaryToken) { - startChar = ((ImaginaryToken)startToken).getStartIndex(); - } + startChar = ((CommonToken)startToken).getStartIndex(); } if (stopToken!=null) { stop = stopToken.getTokenIndex(); - //XXX: instanceof is necessary because of the use of ClassicToken - // for leading whitespace lexing. - if (stopToken instanceof CommonToken) { - stopChar = ((CommonToken)stopToken).getStopIndex() + 1; - } else if (stopToken instanceof ImaginaryToken) { - stopChar = ((ImaginaryToken)stopToken).getStopIndex() + 1; - } + stopChar = ((CommonToken)stopToken).getStopIndex() + 1; } PythonTree pt = (PythonTree)t; pt.setTokenStartIndex(start); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-08-03 21:45:51
|
Revision: 5072 http://jython.svn.sourceforge.net/jython/?rev=5072&view=rev Author: fwierzbicki Date: 2008-08-03 21:45:49 +0000 (Sun, 03 Aug 2008) Log Message: ----------- whitespace Modified Paths: -------------- branches/asm/grammar/Python.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-08-03 20:17:40 UTC (rev 5071) +++ branches/asm/grammar/Python.g 2008-08-03 21:45:49 UTC (rev 5072) @@ -408,9 +408,9 @@ } } - protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) - throws RecognitionException - { + protected Object recoverFromMismatchedToken(IntStream input, int ttype, BitSet follow) + throws RecognitionException + { if (errorHandler.isRecoverable()) { return super.recoverFromMismatchedToken(input, ttype, follow); } @@ -424,7 +424,7 @@ catch (RecognitionException re) { errorHandler.reportError(this, re); errorHandler.recover(this, input,re); - retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); + retval.tree = (PythonTree)adaptor.errorNode(input, retval.start, input.LT(-1), re); } } @@ -452,42 +452,40 @@ this.errorHandler = eh; } - /** - * Taken directly from antlr's Lexer.java -- needs to be re-integrated every time + /** + * Taken directly from antlr's Lexer.java -- needs to be re-integrated every time * we upgrade from Antlr (need to consider a Lexer subclass, though the issue would * remain). - */ - public Token nextToken() { - while (true) { - state.token = null; - state.channel = Token.DEFAULT_CHANNEL; - state.tokenStartCharIndex = input.index(); - state.tokenStartCharPositionInLine = input.getCharPositionInLine(); - state.tokenStartLine = input.getLine(); - state.text = null; - if ( input.LA(1)==CharStream.EOF ) { - return Token.EOF_TOKEN; - } - try { - mTokens(); - if ( state.token==null ) { - emit(); - } - else if ( state.token==Token.SKIP_TOKEN ) { - continue; - } - return state.token; - } - catch (NoViableAltException nva) { - errorHandler.reportError(this, nva); - errorHandler.recover(this, nva); // throw out current char and try again - } - catch (RecognitionException re) { - errorHandler.reportError(this, re); - // match() routine has already called recover() - } - } - } + */ + public Token nextToken() { + while (true) { + state.token = null; + state.channel = Token.DEFAULT_CHANNEL; + state.tokenStartCharIndex = input.index(); + state.tokenStartCharPositionInLine = input.getCharPositionInLine(); + state.tokenStartLine = input.getLine(); + state.text = null; + if ( input.LA(1)==CharStream.EOF ) { + return Token.EOF_TOKEN; + } + try { + mTokens(); + if ( state.token==null ) { + emit(); + } + else if ( state.token==Token.SKIP_TOKEN ) { + continue; + } + return state.token; + } catch (NoViableAltException nva) { + errorHandler.reportError(this, nva); + errorHandler.recover(this, nva); // throw out current char and try again + } catch (RecognitionException re) { + errorHandler.reportError(this, re); + // match() routine has already called recover() + } + } + } } //single_input: NEWLINE | simple_stmt | compound_stmt NEWLINE @@ -1376,20 +1374,20 @@ } : {startPos==0}?=> ( {implicitLineJoiningLevel>0}? ( ' ' | '\t' )+ {$channel=HIDDEN;} - | ( ' ' { spaces++; } - | '\t' { spaces += 8; spaces -= (spaces \% 8); } - )+ + | ( ' ' { spaces++; } + | '\t' { spaces += 8; spaces -= (spaces \% 8); } + )+ { - // make a string of n spaces where n is column number - 1 - char[] indentation = new char[spaces]; - for (int i=0; i<spaces; i++) { - indentation[i] = ' '; + // make a string of n spaces where n is column number - 1 + char[] indentation = new char[spaces]; + for (int i=0; i<spaces; i++) { + indentation[i] = ' '; + } + ClassicToken c = new ClassicToken(LEADING_WS,new String(indentation)); + c.setLine(input.getLine()); + c.setCharPositionInLine(input.getCharPositionInLine()); + emit(c); } - ClassicToken c = new ClassicToken(LEADING_WS,new String(indentation)); - c.setLine(input.getLine()); - c.setCharPositionInLine(input.getCharPositionInLine()); - emit(c); - } // kill trailing newline if present and then ignore ( ('\r')? '\n' {if (state.token!=null) state.token.setChannel(HIDDEN); else $channel=HIDDEN;})* // {state.token.setChannel(99); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |