You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2008-11-12 19:10:59
|
Revision: 5573 http://jython.svn.sourceforge.net/jython/?rev=5573&view=rev Author: fwierzbicki Date: 2008-11-12 19:10:54 +0000 (Wed, 12 Nov 2008) Log Message: ----------- Upgrade to antlr-3.1.1. Modified Paths: -------------- trunk/jython/build.xml Added Paths: ----------- trunk/jython/extlibs/antlr-3.1.1-runtime.jar trunk/jython/extlibs/antlr-3.1.1.jar Removed Paths: ------------- trunk/jython/extlibs/antlr-3.1.jar trunk/jython/extlibs/antlr-runtime-3.1.jar Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2008-11-12 01:31:02 UTC (rev 5572) +++ trunk/jython/build.xml 2008-11-12 19:10:54 UTC (rev 5573) @@ -164,7 +164,7 @@ <pathelement path="${extlibs.dir}/mysql-connector-java-5.1.6.jar" /> <pathelement path="${extlibs.dir}/postgresql-8.3-603.jdbc4.jar" /> <pathelement path="${extlibs.dir}/antlr-2.7.7.jar" /> - <pathelement path="${extlibs.dir}/antlr-3.1.jar" /> + <pathelement path="${extlibs.dir}/antlr-3.1.1.jar" /> <pathelement path="${extlibs.dir}/stringtemplate-3.2.jar" /> </path> @@ -516,7 +516,7 @@ <target name="jarjar" depends="init,needed-check" 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.1.jar"/> + <zipfileset src="extlibs/antlr-3.1.1-runtime.jar"/> <zipfileset src="extlibs/asm-3.1.jar"/> <zipfileset src="extlibs/asm-commons-3.1.jar"/> <zipfileset src="extlibs/asm-util-3.1.jar"/> Added: trunk/jython/extlibs/antlr-3.1.1-runtime.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/antlr-3.1.1-runtime.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Added: trunk/jython/extlibs/antlr-3.1.1.jar =================================================================== (Binary files differ) Property changes on: trunk/jython/extlibs/antlr-3.1.1.jar ___________________________________________________________________ Added: svn:mime-type + application/octet-stream Deleted: trunk/jython/extlibs/antlr-3.1.jar =================================================================== (Binary files differ) Deleted: trunk/jython/extlibs/antlr-runtime-3.1.jar =================================================================== (Binary files differ) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-12 02:22:16
|
Revision: 5572 http://jython.svn.sourceforge.net/jython/?rev=5572&view=rev Author: pjenvey Date: 2008-11-12 01:31:02 +0000 (Wed, 12 Nov 2008) Log Message: ----------- more java integration unicode vs str fixes Modified Paths: -------------- trunk/jython/Lib/ntpath.py trunk/jython/Lib/os.py trunk/jython/Lib/posixpath.py Modified: trunk/jython/Lib/ntpath.py =================================================================== --- trunk/jython/Lib/ntpath.py 2008-11-11 23:25:25 UTC (rev 5571) +++ trunk/jython/Lib/ntpath.py 2008-11-12 01:31:02 UTC (rev 5572) @@ -9,6 +9,7 @@ import os import stat import sys +from org.python.core.Py import newString __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", @@ -493,7 +494,8 @@ if not splitunc(path)[0] and not splitdrive(path)[0]: # cwd lacks a UNC mount point, so it should have a drive # letter (but lacks one): determine it - drive = splitdrive(java.io.File(path).getCanonicalPath())[0] + canon_path = newString(java.io.File(path).getCanonicalPath()) + drive = splitdrive(canon_path)[0] path = join(drive, path) return normpath(path) Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2008-11-11 23:25:25 UTC (rev 5571) +++ trunk/jython/Lib/os.py 2008-11-12 01:31:02 UTC (rev 5572) @@ -237,7 +237,7 @@ Return a string representing the current working directory. """ - return sys.getCurrentWorkingDir() + return asPyString(sys.getCurrentWorkingDir()) def chdir(path): """chdir(path) Modified: trunk/jython/Lib/posixpath.py =================================================================== --- trunk/jython/Lib/posixpath.py 2008-11-11 23:25:25 UTC (rev 5571) +++ trunk/jython/Lib/posixpath.py 2008-11-12 01:31:02 UTC (rev 5572) @@ -14,6 +14,7 @@ import java.io.IOException import os import stat +from org.python.core.Py import newString __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", @@ -218,8 +219,8 @@ if not os._native_posix: def samefile(f1, f2): """Test whether two pathnames reference the same actual file""" - canon1 = java.io.File(_ensure_str(f1)).getCanonicalPath() - canon2 = java.io.File(_ensure_str(f2)).getCanonicalPath() + canon1 = newString(java.io.File(_ensure_str(f1)).getCanonicalPath()) + canon2 = newString(java.io.File(_ensure_str(f2)).getCanonicalPath()) return canon1 == canon2 else: def samefile(f1, f2): @@ -448,7 +449,7 @@ encounter a path we've seen before (meaning that there's a loop). """ try: - return str(java.io.File(abspath(path)).getCanonicalPath()) + return newString(java.io.File(abspath(path)).getCanonicalPath()) except java.io.IOException: return None else: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-11-11 23:25:28
|
Revision: 5571 http://jython.svn.sourceforge.net/jython/?rev=5571&view=rev Author: otmarhumbel Date: 2008-11-11 23:25:25 +0000 (Tue, 11 Nov 2008) Log Message: ----------- detect JYTHON_HOME if called from the /bin directory Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/driver/jython_test.template trunk/jython/src/shell/jython Modified: trunk/installer/src/java/org/python/util/install/driver/jython_test.template =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-11 17:48:27 UTC (rev 5570) +++ trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-11 23:25:25 UTC (rev 5571) @@ -8,15 +8,21 @@ # save old home env vars: _OLD_JAVA_HOME=$JAVA_HOME _OLD_JYTHON_HOME=$JYTHON_HOME +# save current dir +_CURDIR=`pwd` cd "$_INSTALL_DIR/bin" -# auto detection of JYTHON_HOME does not yet work -#echo "{3}: only JAVA_HOME:" -#export JAVA_HOME="$_JAVA_HOME" -#export JYTHON_HOME= -#./jython "$_SCRIPT" +echo "{3}: no home:" +export JAVA_HOME= +export JYTHON_HOME= +./jython "$_SCRIPT" +echo "{3}: only JAVA_HOME:" +export JAVA_HOME="$_JAVA_HOME" +export JYTHON_HOME= +./jython "$_SCRIPT" + echo "{3}: only JYTHON_HOME:" export JAVA_HOME= export JYTHON_HOME="$_INSTALL_DIR" @@ -27,6 +33,14 @@ export JYTHON_HOME="$_INSTALL_DIR" ./jython "$_SCRIPT" +cd ~ + +echo "{3}: no home, calling from another working dir:" +export JAVA_HOME= +export JYTHON_HOME= +"$_INSTALL_DIR/bin/jython" "$_SCRIPT" + # cleanup: +cd "$_CURDIR" export JAVA_HOME=$_OLD_JAVA_HOME export JYTHON_HOME=$_OLD_JYTHON_HOME Modified: trunk/jython/src/shell/jython =================================================================== --- trunk/jython/src/shell/jython 2008-11-11 17:48:27 UTC (rev 5570) +++ trunk/jython/src/shell/jython 2008-11-11 23:25:25 UTC (rev 5571) @@ -44,8 +44,15 @@ fi if [ -z "$JYTHON_HOME" ] ; then - JYTHON_HOME_1=`dirname "$PRG"` # the ./bin dir - JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir + if [ "$PRG" = "./jython" ] ; then + # current dir is /bin dir + JYTHON_HOME_1=`pwd` # the ./bin dir + JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir + else + # current dir is not /bin dir + JYTHON_HOME_1=`dirname "$PRG"` # the ./bin dir + JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir + fi fi if [ -z "$JYTHON_OPTS" ] ; then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-11 17:48:31
|
Revision: 5570 http://jython.svn.sourceforge.net/jython/?rev=5570&view=rev Author: fwierzbicki Date: 2008-11-11 17:48:27 +0000 (Tue, 11 Nov 2008) Log Message: ----------- Tor Norbye found this ancient typo just by pointing NetBeans and the latest nbpython at datetime.py. Maybe there is something to be said for these "IDE"s that I keep hearing about :). Modified Paths: -------------- trunk/jython/Lib/datetime.py Modified: trunk/jython/Lib/datetime.py =================================================================== --- trunk/jython/Lib/datetime.py 2008-11-10 21:12:29 UTC (rev 5569) +++ trunk/jython/Lib/datetime.py 2008-11-11 17:48:27 UTC (rev 5570) @@ -1574,7 +1574,7 @@ # Convert self to UTC, and attach the new time zone object. myoffset = self.utcoffset() if myoffset is None: - raise ValuError("astimezone() requires an aware datetime") + raise ValueError("astimezone() requires an aware datetime") utc = (self - myoffset).replace(tzinfo=tz) # Convert from UTC to tz's local time. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-10 21:12:33
|
Revision: 5569 http://jython.svn.sourceforge.net/jython/?rev=5569&view=rev Author: fwierzbicki Date: 2008-11-10 21:12:29 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Make lineno and col_offset writable. Modified Paths: -------------- trunk/jython/ast/asdl_antlr.py trunk/jython/src/org/python/antlr/ast/Assert.java trunk/jython/src/org/python/antlr/ast/Assign.java trunk/jython/src/org/python/antlr/ast/Attribute.java trunk/jython/src/org/python/antlr/ast/AugAssign.java trunk/jython/src/org/python/antlr/ast/BinOp.java trunk/jython/src/org/python/antlr/ast/BoolOp.java trunk/jython/src/org/python/antlr/ast/Break.java trunk/jython/src/org/python/antlr/ast/Call.java trunk/jython/src/org/python/antlr/ast/ClassDef.java trunk/jython/src/org/python/antlr/ast/Compare.java trunk/jython/src/org/python/antlr/ast/Continue.java trunk/jython/src/org/python/antlr/ast/Delete.java trunk/jython/src/org/python/antlr/ast/Dict.java trunk/jython/src/org/python/antlr/ast/Exec.java trunk/jython/src/org/python/antlr/ast/Expr.java trunk/jython/src/org/python/antlr/ast/For.java trunk/jython/src/org/python/antlr/ast/FunctionDef.java trunk/jython/src/org/python/antlr/ast/GeneratorExp.java trunk/jython/src/org/python/antlr/ast/Global.java trunk/jython/src/org/python/antlr/ast/If.java trunk/jython/src/org/python/antlr/ast/IfExp.java trunk/jython/src/org/python/antlr/ast/Import.java trunk/jython/src/org/python/antlr/ast/ImportFrom.java trunk/jython/src/org/python/antlr/ast/Lambda.java trunk/jython/src/org/python/antlr/ast/List.java trunk/jython/src/org/python/antlr/ast/ListComp.java trunk/jython/src/org/python/antlr/ast/Name.java trunk/jython/src/org/python/antlr/ast/Num.java trunk/jython/src/org/python/antlr/ast/Pass.java trunk/jython/src/org/python/antlr/ast/Print.java trunk/jython/src/org/python/antlr/ast/Raise.java trunk/jython/src/org/python/antlr/ast/Repr.java trunk/jython/src/org/python/antlr/ast/Return.java trunk/jython/src/org/python/antlr/ast/Str.java trunk/jython/src/org/python/antlr/ast/Subscript.java trunk/jython/src/org/python/antlr/ast/TryExcept.java trunk/jython/src/org/python/antlr/ast/TryFinally.java trunk/jython/src/org/python/antlr/ast/Tuple.java trunk/jython/src/org/python/antlr/ast/UnaryOp.java trunk/jython/src/org/python/antlr/ast/While.java trunk/jython/src/org/python/antlr/ast/With.java trunk/jython/src/org/python/antlr/ast/Yield.java Modified: trunk/jython/ast/asdl_antlr.py =================================================================== --- trunk/jython/ast/asdl_antlr.py 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/ast/asdl_antlr.py 2008-11-10 21:12:29 UTC (rev 5569) @@ -258,16 +258,32 @@ if str(name) in ('stmt', 'expr'): # The lineno property + self.emit("private int lineno = -1;", depth + 1) self.emit("public int getLineno() {", depth + 1) + self.emit("if (lineno != -1) {", depth + 2); + self.emit("return lineno;", depth + 3); + self.emit("}", depth + 2) self.emit('return getLine();', depth + 2) self.emit("}", depth + 1) self.emit("", 0) + self.emit("public void setLineno(int num) {", depth + 1) + self.emit("lineno = num;", depth + 2); + self.emit("}", depth + 1) + self.emit("", 0) # The col_offset property + self.emit("private int col_offset = -1;", depth + 1) self.emit("public int getCol_offset() {", depth + 1) + self.emit("if (col_offset != -1) {", depth + 2); + self.emit("return col_offset;", depth + 3); + self.emit("}", depth + 2) self.emit('return getCharPositionInLine();', depth + 2) self.emit("}", depth + 1) self.emit("", 0) + self.emit("public void setCol_offset(int num) {", depth + 1) + self.emit("col_offset = num;", depth + 2); + self.emit("}", depth + 1) + self.emit("", 0) self.emit("}", depth) self.close() Modified: trunk/jython/src/org/python/antlr/ast/Assert.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Assert.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Assert.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -71,12 +71,28 @@ msg.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Assign.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Assign.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Assign.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -91,12 +91,28 @@ value.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Attribute.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Attribute.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Attribute.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -81,12 +81,28 @@ this.ctx = c; } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/AugAssign.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AugAssign.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/AugAssign.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -83,12 +83,28 @@ value.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/BinOp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BinOp.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/BinOp.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -81,12 +81,28 @@ right.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/BoolOp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BoolOp.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/BoolOp.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -85,12 +85,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Break.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Break.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Break.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -40,12 +40,28 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Call.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Call.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Call.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -159,12 +159,28 @@ kwargs.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/ClassDef.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ClassDef.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/ClassDef.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -158,12 +158,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Compare.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Compare.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Compare.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -107,12 +107,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Continue.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Continue.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Continue.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -40,12 +40,28 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Delete.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Delete.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Delete.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -77,12 +77,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Dict.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Dict.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Dict.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -111,12 +111,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Exec.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Exec.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Exec.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -88,12 +88,28 @@ locals.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Expr.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Expr.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Expr.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -57,12 +57,28 @@ value.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/For.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/For.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/For.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -144,12 +144,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/FunctionDef.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/FunctionDef.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -134,12 +134,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GeneratorExp.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/GeneratorExp.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -94,12 +94,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Global.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Global.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Global.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -51,12 +51,28 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/If.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/If.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/If.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -128,12 +128,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/IfExp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfExp.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/IfExp.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -88,12 +88,28 @@ orelse.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Import.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Import.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Import.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -77,12 +77,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportFrom.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/ImportFrom.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -97,12 +97,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Lambda.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Lambda.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Lambda.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -67,12 +67,28 @@ body.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/List.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/List.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/List.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -89,12 +89,28 @@ this.ctx = c; } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/ListComp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ListComp.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/ListComp.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -93,12 +93,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Name.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Name.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Name.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -63,12 +63,28 @@ this.ctx = c; } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Num.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Num.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Num.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -51,12 +51,28 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Pass.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Pass.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Pass.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -40,12 +40,28 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Print.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Print.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Print.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -102,12 +102,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Raise.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Raise.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Raise.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -88,12 +88,28 @@ tback.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Repr.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Repr.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Repr.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -57,12 +57,28 @@ value.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Return.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Return.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Return.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -57,12 +57,28 @@ value.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Str.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Str.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Str.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -51,12 +51,28 @@ public void traverse(VisitorIF visitor) throws Exception { } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Subscript.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Subscript.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Subscript.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -83,12 +83,28 @@ this.ctx = c; } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/TryExcept.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TryExcept.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/TryExcept.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -150,12 +150,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/TryFinally.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TryFinally.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/TryFinally.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -112,12 +112,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Tuple.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Tuple.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Tuple.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -90,12 +90,28 @@ this.ctx = c; } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/UnaryOp.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/UnaryOp.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -65,12 +65,28 @@ operand.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/While.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/While.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/While.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -129,12 +129,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/With.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/With.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/With.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -111,12 +111,28 @@ } } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } Modified: trunk/jython/src/org/python/antlr/ast/Yield.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Yield.java 2008-11-10 15:33:23 UTC (rev 5568) +++ trunk/jython/src/org/python/antlr/ast/Yield.java 2008-11-10 21:12:29 UTC (rev 5569) @@ -57,12 +57,28 @@ value.accept(visitor); } + private int lineno = -1; public int getLineno() { + if (lineno != -1) { + return lineno; + } return getLine(); } + public void setLineno(int num) { + lineno = num; + } + + private int col_offset = -1; public int getCol_offset() { + if (col_offset != -1) { + return col_offset; + } return getCharPositionInLine(); } + public void setCol_offset(int num) { + col_offset = num; + } + } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-10 15:33:28
|
Revision: 5568 http://jython.svn.sourceforge.net/jython/?rev=5568&view=rev Author: fwierzbicki Date: 2008-11-10 15:33:23 +0000 (Mon, 10 Nov 2008) Log Message: ----------- remove dead code. Modified Paths: -------------- trunk/jython/ast/asdl_antlr.py Modified: trunk/jython/ast/asdl_antlr.py =================================================================== --- trunk/jython/ast/asdl_antlr.py 2008-11-10 05:15:10 UTC (rev 5567) +++ trunk/jython/ast/asdl_antlr.py 2008-11-10 15:33:23 UTC (rev 5568) @@ -149,13 +149,6 @@ self.attributes(sum, depth, True); - #self.emit("", 0) - #self.emit("public static final String[] %sTypeNames = new String[] {" % - # name, depth+1) - #self.emit('"<undef>",', depth+2) - #for type in sum.types: - # self.emit('"%s",' % type.name, depth+2) - #self.emit("};", depth+1) self.emit("}", depth) self.close() @@ -298,6 +291,8 @@ elif str(f.type) == "expr": self.emit("addChild(%s);" % (f.name), depth+1) + #XXX: this method used to emit a pickle(DataOutputStream ostream) for cPickle support. + # If we want to re-add it, see Jython 2.2's pickle method in its ast nodes. def javaMethods(self, type, clsname, ctorname, fields, depth): # The java ctors @@ -356,14 +351,6 @@ self.emit("}", depth) self.emit("", 0) - # The pickle() method - #self.emit("public void pickle(DataOutputStream ostream) throws IOException {", depth) - #self.emit("pickleThis(%s, ostream);" % type.index, depth+1); - #for f in fields: - # self.emit("pickleThis(this.%s, ostream);" % f.name, depth+1) - #self.emit("}", depth) - #self.emit("", 0) - # The accept() method self.emit("public <R> R accept(VisitorIF<R> visitor) throws Exception {", depth) if clsname == ctorname: @@ -395,10 +382,6 @@ self.emit('}', depth) self.emit("", 0) - #self.emit('}', depth) - #self.emit("", 0) - - def visitField(self, field, depth): self.emit("public %s;" % self.fieldDef(field), depth) @@ -414,9 +397,6 @@ def fieldDef(self, field): jtype = str(field.type) - #if field.typedef and field.typedef.simple: - # jtype = 'int' - #else: jtype = self.bltinnames.get(jtype, jtype + 'Type') name = field.name seq = field.seq and "[]" or "" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-10 05:15:14
|
Revision: 5567 http://jython.svn.sourceforge.net/jython/?rev=5567&view=rev Author: cgroves Date: 2008-11-10 05:15:10 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Implement the collection proxies as methods on PyJavaTypes Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/CollectionIter.java branches/newstyle-java-types/src/org/python/core/CollectionProxy.java branches/newstyle-java-types/src/org/python/core/PyBuiltinCallable.java branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyObject.java Modified: branches/newstyle-java-types/src/org/python/core/CollectionIter.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/CollectionIter.java 2008-11-10 03:56:44 UTC (rev 5566) +++ branches/newstyle-java-types/src/org/python/core/CollectionIter.java 2008-11-10 05:15:10 UTC (rev 5567) @@ -2,13 +2,10 @@ package org.python.core; -import java.lang.reflect.Method; -import java.util.Collection; import java.util.Dictionary; import java.util.Enumeration; import java.util.Iterator; import java.util.Map; -import java.util.Vector; class CollectionIter{ PyObject findCollection(Object object) { @@ -30,7 +27,7 @@ return null; } - + } class EnumerationIter extends PyIterator { Modified: branches/newstyle-java-types/src/org/python/core/CollectionProxy.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/CollectionProxy.java 2008-11-10 03:56:44 UTC (rev 5566) +++ branches/newstyle-java-types/src/org/python/core/CollectionProxy.java 2008-11-10 05:15:10 UTC (rev 5567) @@ -2,7 +2,6 @@ package org.python.core; -import java.util.Collection; import java.util.Dictionary; import java.util.Enumeration; import java.util.Iterator; @@ -16,15 +15,15 @@ public static CollectionProxy findCollection(Object object) { if (object == null) return NoProxy; - + if (object instanceof List) { return new ListProxy(((List) object)); } if (object instanceof Map) { return new MapProxy(((Map) object)); } - if (object instanceof Collection) { - return new IteratorProxy(((Collection) object).iterator()); + if (object instanceof Iterable) { + return new IteratorProxy(((Iterable) object).iterator()); } if (object instanceof Iterator) { return new IteratorProxy(((Iterator) object)); @@ -44,7 +43,7 @@ return NoProxy; } - /** The basic functions to implement a mapping* */ + /** The basic functions to implement a mapping */ public int __len__() { throw Py.AttributeError("__len__"); } @@ -92,8 +91,7 @@ public PyObject __finditem__(int key) { if (key != this.counter) { - throw Py - .ValueError("enumeration indices must be consecutive ints starting at 0"); + throw Py.ValueError("enumeration indices must be consecutive ints starting at 0"); } this.counter++; if (this.proxy.hasMoreElements()) { @@ -141,8 +139,7 @@ public void __setitem__(PyObject key, PyObject value) { if (key instanceof PyInteger) { - this.proxy.setElementAt(Py.tojava(value, Object.class), - ((PyInteger) key).getValue()); + this.proxy.setElementAt(Py.tojava(value, Object.class), ((PyInteger)key).getValue()); } else { throw Py.TypeError("only integer keys accepted"); } @@ -278,8 +275,7 @@ public PyObject __finditem__(int key) { if (key != this.counter) { - throw Py - .ValueError("iterator indices must be consecutive ints starting at 0"); + throw Py.ValueError("iterator indices must be consecutive ints starting at 0"); } this.counter++; if (this.proxy.hasNext()) { Modified: branches/newstyle-java-types/src/org/python/core/PyBuiltinCallable.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBuiltinCallable.java 2008-11-10 03:56:44 UTC (rev 5566) +++ branches/newstyle-java-types/src/org/python/core/PyBuiltinCallable.java 2008-11-10 05:15:10 UTC (rev 5567) @@ -21,7 +21,7 @@ } /** - * @return a new instance of this type of PyBuiltinFunction bound to self + * Returns a new instance of this type of PyBuiltinFunction bound to self */ abstract public PyBuiltinCallable bind(PyObject self); Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-10 03:56:44 UTC (rev 5566) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-10 05:15:10 UTC (rev 5567) @@ -4,18 +4,21 @@ import java.lang.reflect.Field; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Collection; import java.util.HashMap; +import java.util.List; import java.util.Map; import org.python.core.util.StringUtil; import org.python.expose.ExposeAsSuperclass; +import org.python.util.Generic; public class PyJavaType extends PyType implements ExposeAsSuperclass { private final static Class<?>[] OO = {PyObject.class, PyObject.class}; public static PyObject wrapJavaObject(Object o) { - PyObject obj = new PyObject(PyType.fromClass(o.getClass())); + PyObject obj = new PyObjectDerived(PyType.fromClass(o.getClass())); obj.javaProxy = o; return obj; } @@ -154,6 +157,13 @@ for (Class<?> inner : underlying_class.getClasses()) { dict.__setitem__(inner.getSimpleName(), PyType.fromClass(inner)); } + for (Map.Entry<Class<?>, PyBuiltinMethod[]> entry : _collectionProxies.entrySet()) { + if (entry.getKey().isAssignableFrom(underlying_class)) { + for (PyBuiltinMethod meth : entry.getValue()) { + dict.__setitem__(meth.info.getName(), new PyMethodDescr(this, meth)); + } + } + } if (ClassDictInit.class.isAssignableFrom(underlying_class) && underlying_class != ClassDictInit.class) { try { @@ -211,4 +221,194 @@ private static PyException error(Exception e) { return Py.JavaError(e); } + + protected static class LenProxy extends PyBuiltinMethodNarrow { + public LenProxy() { + super("__len__", 0, 0); + } + + protected LenProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new LenProxy(getType(), self, info); + } + + @Override + public PyObject __call__() { + return Py.newInteger(((Collection<?>)self.javaProxy).size()); + } + } + + protected static class MapGetProxy extends PyBuiltinMethodNarrow { + public MapGetProxy() { + super("__getitem__", 1, 1); + } + + protected MapGetProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new MapGetProxy(getType(), self, info); + } + + @Override + public PyObject __call__(PyObject key) { + return Py.java2py(((Map<?, ?>)self.javaProxy).get(Py.tojava(key, Object.class))); + } + } + + protected static class MapPutProxy extends PyBuiltinMethodNarrow { + public MapPutProxy() { + super("__setitem__", 2, 2); + } + + protected MapPutProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new MapPutProxy(getType(), self, info); + } + + @Override + public PyObject __call__(PyObject key, PyObject value) { + return Py.java2py(((Map<Object, Object>)self.javaProxy).put(Py.tojava(key, Object.class), + Py.tojava(value, + Object.class))); + } + } + + protected static class MapRemoveProxy extends PyBuiltinMethodNarrow { + + public MapRemoveProxy() { + super("__delitem__", 1, 1); + } + + protected MapRemoveProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new MapRemoveProxy(getType(), self, info); + } + + @Override + public PyObject __call__(PyObject key, PyObject value) { + return Py.java2py(((Map<?, ?>)self.javaProxy).remove(Py.tojava(key, Object.class))); + } + } + + protected static class ListGetProxy extends PyBuiltinMethodNarrow { + public ListGetProxy() { + super("__getitem__", 1, 1); + } + + protected ListGetProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new ListGetProxy(getType(), self, info); + } + + @Override + public PyObject __call__(PyObject key) { + if (key instanceof PyInteger) { + return Py.java2py(((List<?>)self.javaProxy).get(((PyInteger)key).getValue())); + } else { + throw Py.TypeError("only integer keys accepted"); + } + } + } + + protected static class ListSetProxy extends PyBuiltinMethodNarrow { + public ListSetProxy() { + super("__setitem__", 2, 2); + } + + protected ListSetProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new ListSetProxy(getType(), self, info); + } + + @Override + public PyObject __call__(PyObject key, PyObject value) { + if (key instanceof PyInteger) { + ((List<Object>)self.javaProxy).set(((PyInteger)key).getValue(), + Py.tojava(value, Object.class)); + } else { + throw Py.TypeError("only integer keys accepted"); + } + return Py.None; + } + } + + protected static class ListRemoveProxy extends PyBuiltinMethodNarrow { + public ListRemoveProxy() { + super("__delitem__", 1, 1); + } + + protected ListRemoveProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new ListRemoveProxy(getType(), self, info); + } + + @Override + public PyObject __call__(PyObject key, PyObject value) { + if (key instanceof PyInteger) { + return Py.java2py(((List<Object>)self.javaProxy).remove(((PyInteger)key).getValue())); + } else { + throw Py.TypeError("only integer keys accepted"); + } + } + } + + public static class IterableProxy extends PyBuiltinMethodNarrow { + + public IterableProxy() { + super("__iter__", 0, 0); + } + + protected IterableProxy(PyType type, PyObject self, Info info) { + super(type, self, info); + } + + @Override + public PyBuiltinCallable bind(PyObject self) { + return new IterableProxy(getType(), self, info); + } + + @Override + public PyObject __call__() { + return new IteratorIter(((Iterable)self.javaProxy).iterator()); + } + } + + static Map<Class<?>, PyBuiltinMethod[]> _collectionProxies = Generic.map(); + static { + _collectionProxies.put(Iterable.class, new PyBuiltinMethod[] {new IterableProxy()}); + _collectionProxies.put(Collection.class, new PyBuiltinMethod[] {new LenProxy()}); + _collectionProxies.put(Map.class, new PyBuiltinMethod[] {new MapGetProxy(), + new MapPutProxy(), + new MapRemoveProxy()}); + _collectionProxies.put(List.class, new PyBuiltinMethod[] {new ListGetProxy(), + new ListSetProxy(), + new ListRemoveProxy()}); + } } Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-10 03:56:44 UTC (rev 5566) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-10 05:15:10 UTC (rev 5567) @@ -547,6 +547,7 @@ * @param value the value to set this key to **/ public void __setitem__(PyObject key, PyObject value) { + Thread.dumpStack(); throw Py.TypeError(String.format("'%.200s' object does not support item assignment", getType().fastGetName())); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-10 03:56:50
|
Revision: 5566 http://jython.svn.sourceforge.net/jython/?rev=5566&view=rev Author: cgroves Date: 2008-11-10 03:56:44 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Fill in Java inner classes Modified Paths: -------------- branches/newstyle-java-types/src/org/python/core/PyJavaType.java Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-10 03:36:31 UTC (rev 5565) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-10 03:56:44 UTC (rev 5566) @@ -151,6 +151,9 @@ dict.__setitem__("__init__", reflctr); } } + for (Class<?> inner : underlying_class.getClasses()) { + dict.__setitem__(inner.getSimpleName(), PyType.fromClass(inner)); + } if (ClassDictInit.class.isAssignableFrom(underlying_class) && underlying_class != ClassDictInit.class) { try { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-11-10 03:36:39
|
Revision: 5565 http://jython.svn.sourceforge.net/jython/?rev=5565&view=rev Author: fwierzbicki Date: 2008-11-10 03:36:31 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Just enough AST tweaking to get some of sympy working for Ondrej. On my todo list is to look at Python 2.6's ast testing and see if I can port that over to Jython. Modified Paths: -------------- trunk/jython/ast/asdl_antlr.py trunk/jython/src/org/python/antlr/AST.java trunk/jython/src/org/python/antlr/PythonTree.java trunk/jython/src/org/python/antlr/ast/Assert.java trunk/jython/src/org/python/antlr/ast/Assign.java trunk/jython/src/org/python/antlr/ast/Attribute.java trunk/jython/src/org/python/antlr/ast/AugAssign.java trunk/jython/src/org/python/antlr/ast/BinOp.java trunk/jython/src/org/python/antlr/ast/BoolOp.java trunk/jython/src/org/python/antlr/ast/Break.java trunk/jython/src/org/python/antlr/ast/Call.java trunk/jython/src/org/python/antlr/ast/ClassDef.java trunk/jython/src/org/python/antlr/ast/Compare.java trunk/jython/src/org/python/antlr/ast/Continue.java trunk/jython/src/org/python/antlr/ast/Delete.java trunk/jython/src/org/python/antlr/ast/Dict.java trunk/jython/src/org/python/antlr/ast/Ellipsis.java trunk/jython/src/org/python/antlr/ast/ErrorExpr.java trunk/jython/src/org/python/antlr/ast/ErrorMod.java trunk/jython/src/org/python/antlr/ast/ErrorSlice.java trunk/jython/src/org/python/antlr/ast/ErrorStmt.java trunk/jython/src/org/python/antlr/ast/Exec.java trunk/jython/src/org/python/antlr/ast/Expr.java trunk/jython/src/org/python/antlr/ast/Expression.java trunk/jython/src/org/python/antlr/ast/ExtSlice.java trunk/jython/src/org/python/antlr/ast/For.java trunk/jython/src/org/python/antlr/ast/FunctionDef.java trunk/jython/src/org/python/antlr/ast/GeneratorExp.java trunk/jython/src/org/python/antlr/ast/Global.java trunk/jython/src/org/python/antlr/ast/If.java trunk/jython/src/org/python/antlr/ast/IfExp.java trunk/jython/src/org/python/antlr/ast/Import.java trunk/jython/src/org/python/antlr/ast/ImportFrom.java trunk/jython/src/org/python/antlr/ast/Index.java trunk/jython/src/org/python/antlr/ast/Interactive.java trunk/jython/src/org/python/antlr/ast/Lambda.java trunk/jython/src/org/python/antlr/ast/List.java trunk/jython/src/org/python/antlr/ast/ListComp.java trunk/jython/src/org/python/antlr/ast/Module.java trunk/jython/src/org/python/antlr/ast/Name.java trunk/jython/src/org/python/antlr/ast/Num.java trunk/jython/src/org/python/antlr/ast/Pass.java trunk/jython/src/org/python/antlr/ast/Print.java trunk/jython/src/org/python/antlr/ast/Raise.java trunk/jython/src/org/python/antlr/ast/Repr.java trunk/jython/src/org/python/antlr/ast/Return.java trunk/jython/src/org/python/antlr/ast/Slice.java trunk/jython/src/org/python/antlr/ast/Str.java trunk/jython/src/org/python/antlr/ast/Subscript.java trunk/jython/src/org/python/antlr/ast/Suite.java trunk/jython/src/org/python/antlr/ast/TryExcept.java trunk/jython/src/org/python/antlr/ast/TryFinally.java trunk/jython/src/org/python/antlr/ast/Tuple.java trunk/jython/src/org/python/antlr/ast/UnaryOp.java trunk/jython/src/org/python/antlr/ast/While.java trunk/jython/src/org/python/antlr/ast/With.java trunk/jython/src/org/python/antlr/ast/Yield.java trunk/jython/src/org/python/antlr/ast/aliasType.java trunk/jython/src/org/python/antlr/ast/argumentsType.java trunk/jython/src/org/python/antlr/ast/boolopType.java trunk/jython/src/org/python/antlr/ast/cmpopType.java trunk/jython/src/org/python/antlr/ast/comprehensionType.java trunk/jython/src/org/python/antlr/ast/excepthandlerType.java trunk/jython/src/org/python/antlr/ast/exprType.java trunk/jython/src/org/python/antlr/ast/expr_contextType.java trunk/jython/src/org/python/antlr/ast/keywordType.java trunk/jython/src/org/python/antlr/ast/modType.java trunk/jython/src/org/python/antlr/ast/operatorType.java trunk/jython/src/org/python/antlr/ast/sliceType.java trunk/jython/src/org/python/antlr/ast/stmtType.java trunk/jython/src/org/python/antlr/ast/unaryopType.java Modified: trunk/jython/ast/asdl_antlr.py =================================================================== --- trunk/jython/ast/asdl_antlr.py 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/ast/asdl_antlr.py 2008-11-10 03:36:31 UTC (rev 5565) @@ -142,9 +142,13 @@ self.emit('', 0) self.emit("public enum %(name)sType implements AST {" % locals(), depth) self.emit("UNDEFINED,", depth + 1) - for i in range(len(sum.types)): + for i in range(len(sum.types) - 1): type = sum.types[i] self.emit("%s," % type.name, depth + 1) + self.emit("%s;" % sum.types[len(sum.types) - 1].name, depth + 1) + + self.attributes(sum, depth, True); + #self.emit("", 0) #self.emit("public static final String[] %sTypeNames = new String[] {" % # name, depth+1) @@ -154,13 +158,49 @@ #self.emit("};", depth+1) self.emit("}", depth) self.close() + + def attributes(self, obj, depth, always_emit=False): + field_list = [] + if hasattr(obj, "fields"): + for f in obj.fields: + field_list.append('"%s"' % f.name) + if len(field_list) > 0: + self.emit("private final static String[] fields = new String[] {%s};" % + ", ".join(field_list), depth+1) + self.emit("public String[] get_fields() { return fields; }", depth+1) + self.emit("", 0) + elif always_emit: + self.emit("private final static String[] fields = new String[0];", depth+1) + self.emit("public String[] get_fields() { return fields; }", depth+1) + self.emit("", 0) + + att_list = [] + if hasattr(obj, "attributes"): + for a in obj.attributes: + att_list.append('"%s"' % a.name) + if len(att_list) > 0: + self.emit("private final static String[] attributes = new String[] {%s};" % + ", ".join(att_list), depth+1) + self.emit("public String[] get_attributes() { return attributes; }", depth+1) + self.emit("", 0) + elif always_emit: + self.emit("private final static String[] attributes = new String[0];", depth+1) + self.emit("public String[] get_attributes() { return attributes; }", depth+1) + self.emit("", 0) def sum_with_constructor(self, sum, name, depth): self.open("%sType" % name) + self.emit("public abstract class %(name)sType extends PythonTree {" % locals(), depth) self.emit("", 0) + self.attributes(sum, depth); + + self.emit("public %(name)sType() {" % locals(), depth+1) + self.emit("}", depth+1) + self.emit("", 0) + self.emit("public %(name)sType(int ttype, Token token) {" % locals(), depth+1) self.emit("super(ttype, token);", depth+2) self.emit("}", depth+1) @@ -189,13 +229,7 @@ self.visit(f, depth + 1) self.emit("", depth) - ##XXX: extract - field_list = [] - for f in product.fields: - field_list.append('"%s"' % f.name) - self.emit("public static final String[] _fields = new String[] {%s};" % - ",".join(field_list), depth+1) - self.emit("", 0) + self.attributes(product, depth) self.javaMethods(product, name, "%sType" % name, product.fields, depth+1) @@ -219,13 +253,7 @@ self.visit(f, depth + 1) self.emit("", depth) - ##XXX: extract - field_list = [] - for f in cons.fields: - field_list.append('"%s"' % f.name) - self.emit("public static final String[] _fields = new String[] {%s};" % - ",".join(field_list), depth+1) - self.emit("", 0) + self.attributes(cons, depth) self.javaMethods(cons, cons.name, cons.name, cons.fields, depth+1) @@ -273,6 +301,12 @@ def javaMethods(self, type, clsname, ctorname, fields, depth): # The java ctors + fpargs = ", ".join([self.fieldDef(f) for f in fields]) + self.emit("public %s(%s) {" % (ctorname, fpargs), depth) + self.javaConstructorHelper(fields, depth) + self.emit("}", depth) + self.emit("", 0) + token = asdl.Field('Token', 'token') token.typedef = False fpargs = ", ".join([self.fieldDef(f) for f in [token] + fields]) @@ -427,7 +461,6 @@ if not sum.simple: for t in sum.types: self.visit(t, name, depth) - def visitProduct(self, product, name, depth): pass Modified: trunk/jython/src/org/python/antlr/AST.java =================================================================== --- trunk/jython/src/org/python/antlr/AST.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/AST.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -1,3 +1,8 @@ package org.python.antlr; -public interface AST {} +public interface AST { + public static String[] emptyStringArray = new String[0]; + + public String[] get_attributes(); + public String[] get_fields(); +} Modified: trunk/jython/src/org/python/antlr/PythonTree.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTree.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/PythonTree.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -27,9 +27,6 @@ /** What index is this node in the child list? Range: 0..n-1 */ public int childIndex = -1; - /** - * The empty constructor is intended only for use by PythonErrorNode. - */ public PythonTree() { } @@ -255,4 +252,12 @@ public void traverse(VisitorIF visitor) throws Exception { throw new RuntimeException("Cannot traverse node: " + this); } + + public String[] get_fields() { + return emptyStringArray; + } + + public String[] get_attributes() { + return emptyStringArray; + } } Modified: trunk/jython/src/org/python/antlr/ast/Assert.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Assert.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Assert.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,16 @@ public exprType test; public exprType msg; - public static final String[] _fields = new String[] {"test","msg"}; + private final static String[] fields = new String[] {"test", "msg"}; + public String[] get_fields() { return fields; } + public Assert(exprType test, exprType msg) { + this.test = test; + addChild(test); + this.msg = msg; + addChild(msg); + } + public Assert(Token token, exprType test, exprType msg) { super(token); this.test = test; Modified: trunk/jython/src/org/python/antlr/ast/Assign.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Assign.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Assign.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,20 @@ public exprType[] targets; public exprType value; - public static final String[] _fields = new String[] {"targets","value"}; + private final static String[] fields = new String[] {"targets", "value"}; + public String[] get_fields() { return fields; } + public Assign(exprType[] targets, exprType value) { + this.targets = targets; + if (targets != null) { + for(int itargets=0;itargets<targets.length;itargets++) { + addChild(targets[itargets]); + } + } + this.value = value; + addChild(value); + } + public Assign(Token token, exprType[] targets, exprType value) { super(token); this.targets = targets; Modified: trunk/jython/src/org/python/antlr/ast/Attribute.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Attribute.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Attribute.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,8 +11,17 @@ public String attr; public expr_contextType ctx; - public static final String[] _fields = new String[] {"value","attr","ctx"}; + private final static String[] fields = new String[] {"value", "attr", + "ctx"}; + public String[] get_fields() { return fields; } + public Attribute(exprType value, String attr, expr_contextType ctx) { + this.value = value; + addChild(value); + this.attr = attr; + this.ctx = ctx; + } + public Attribute(Token token, exprType value, String attr, expr_contextType ctx) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/AugAssign.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/AugAssign.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/AugAssign.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,8 +11,18 @@ public operatorType op; public exprType value; - public static final String[] _fields = new String[] {"target","op","value"}; + private final static String[] fields = new String[] {"target", "op", + "value"}; + public String[] get_fields() { return fields; } + public AugAssign(exprType target, operatorType op, exprType value) { + this.target = target; + addChild(target); + this.op = op; + this.value = value; + addChild(value); + } + public AugAssign(Token token, exprType target, operatorType op, exprType value) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/BinOp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BinOp.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/BinOp.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,8 +11,17 @@ public operatorType op; public exprType right; - public static final String[] _fields = new String[] {"left","op","right"}; + private final static String[] fields = new String[] {"left", "op", "right"}; + public String[] get_fields() { return fields; } + public BinOp(exprType left, operatorType op, exprType right) { + this.left = left; + addChild(left); + this.op = op; + this.right = right; + addChild(right); + } + public BinOp(Token token, exprType left, operatorType op, exprType right) { super(token); this.left = left; Modified: trunk/jython/src/org/python/antlr/ast/BoolOp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/BoolOp.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/BoolOp.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,19 @@ public boolopType op; public exprType[] values; - public static final String[] _fields = new String[] {"op","values"}; + private final static String[] fields = new String[] {"op", "values"}; + public String[] get_fields() { return fields; } + public BoolOp(boolopType op, exprType[] values) { + this.op = op; + this.values = values; + if (values != null) { + for(int ivalues=0;ivalues<values.length;ivalues++) { + addChild(values[ivalues]); + } + } + } + public BoolOp(Token token, boolopType op, exprType[] values) { super(token); this.op = op; Modified: trunk/jython/src/org/python/antlr/ast/Break.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Break.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Break.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -8,7 +8,8 @@ public class Break extends stmtType { - public static final String[] _fields = new String[] {}; + public Break() { + } public Break(Token token) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Call.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Call.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Call.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -13,9 +13,33 @@ public exprType starargs; public exprType kwargs; - public static final String[] _fields = new String[] - {"func","args","keywords","starargs","kwargs"}; + private final static String[] fields = new String[] {"func", "args", + "keywords", + "starargs", "kwargs"}; + public String[] get_fields() { return fields; } + public Call(exprType func, exprType[] args, keywordType[] keywords, + exprType starargs, exprType kwargs) { + this.func = func; + addChild(func); + this.args = args; + if (args != null) { + for(int iargs=0;iargs<args.length;iargs++) { + addChild(args[iargs]); + } + } + this.keywords = keywords; + if (keywords != null) { + for(int ikeywords=0;ikeywords<keywords.length;ikeywords++) { + addChild(keywords[ikeywords]); + } + } + this.starargs = starargs; + addChild(starargs); + this.kwargs = kwargs; + addChild(kwargs); + } + public Call(Token token, exprType func, exprType[] args, keywordType[] keywords, exprType starargs, exprType kwargs) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/ClassDef.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ClassDef.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ClassDef.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -12,9 +12,33 @@ public stmtType[] body; public exprType[] decorators; - public static final String[] _fields = new String[] - {"name","bases","body","decorators"}; + private final static String[] fields = new String[] {"name", "bases", + "body", "decorators"}; + public String[] get_fields() { return fields; } + public ClassDef(String name, exprType[] bases, stmtType[] body, exprType[] + decorators) { + this.name = name; + this.bases = bases; + if (bases != null) { + for(int ibases=0;ibases<bases.length;ibases++) { + addChild(bases[ibases]); + } + } + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.decorators = decorators; + if (decorators != null) { + for(int idecorators=0;idecorators<decorators.length;idecorators++) { + addChild(decorators[idecorators]); + } + } + } + public ClassDef(Token token, String name, exprType[] bases, stmtType[] body, exprType[] decorators) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Compare.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Compare.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Compare.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,23 @@ public cmpopType[] ops; public exprType[] comparators; - public static final String[] _fields = new String[] - {"left","ops","comparators"}; + private final static String[] fields = new String[] {"left", "ops", + "comparators"}; + public String[] get_fields() { return fields; } + public Compare(exprType left, cmpopType[] ops, exprType[] comparators) { + this.left = left; + addChild(left); + this.ops = ops; + this.comparators = comparators; + if (comparators != null) { + for(int + icomparators=0;icomparators<comparators.length;icomparators++) { + addChild(comparators[icomparators]); + } + } + } + public Compare(Token token, exprType left, cmpopType[] ops, exprType[] comparators) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Continue.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Continue.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Continue.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -8,7 +8,8 @@ public class Continue extends stmtType { - public static final String[] _fields = new String[] {}; + public Continue() { + } public Continue(Token token) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Delete.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Delete.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Delete.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,18 @@ public class Delete extends stmtType { public exprType[] targets; - public static final String[] _fields = new String[] {"targets"}; + private final static String[] fields = new String[] {"targets"}; + public String[] get_fields() { return fields; } + public Delete(exprType[] targets) { + this.targets = targets; + if (targets != null) { + for(int itargets=0;itargets<targets.length;itargets++) { + addChild(targets[itargets]); + } + } + } + public Delete(Token token, exprType[] targets) { super(token); this.targets = targets; Modified: trunk/jython/src/org/python/antlr/ast/Dict.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Dict.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Dict.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,24 @@ public exprType[] keys; public exprType[] values; - public static final String[] _fields = new String[] {"keys","values"}; + private final static String[] fields = new String[] {"keys", "values"}; + public String[] get_fields() { return fields; } + public Dict(exprType[] keys, exprType[] values) { + this.keys = keys; + if (keys != null) { + for(int ikeys=0;ikeys<keys.length;ikeys++) { + addChild(keys[ikeys]); + } + } + this.values = values; + if (values != null) { + for(int ivalues=0;ivalues<values.length;ivalues++) { + addChild(values[ivalues]); + } + } + } + public Dict(Token token, exprType[] keys, exprType[] values) { super(token); this.keys = keys; Modified: trunk/jython/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Ellipsis.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Ellipsis.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -8,7 +8,8 @@ public class Ellipsis extends sliceType { - public static final String[] _fields = new String[] {}; + public Ellipsis() { + } public Ellipsis(Token token) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/ErrorExpr.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ErrorExpr.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ErrorExpr.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -3,8 +3,6 @@ public class ErrorExpr extends exprType { - public static final String[] _fields = new String[] {}; - public ErrorExpr(PythonTree tree) { super(tree); } Modified: trunk/jython/src/org/python/antlr/ast/ErrorMod.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ErrorMod.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ErrorMod.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -3,8 +3,6 @@ public class ErrorMod extends modType { - public static final String[] _fields = new String[] {}; - public ErrorMod(PythonTree tree) { super(tree); } Modified: trunk/jython/src/org/python/antlr/ast/ErrorSlice.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ErrorSlice.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ErrorSlice.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -7,8 +7,6 @@ public class ErrorSlice extends sliceType { - public static final String[] _fields = new String[] {}; - public ErrorSlice(PythonTree tree) { super(tree); } Modified: trunk/jython/src/org/python/antlr/ast/ErrorStmt.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ErrorStmt.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ErrorStmt.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -7,8 +7,6 @@ public class ErrorStmt extends stmtType { - public static final String[] _fields = new String[] {}; - public ErrorStmt(PythonTree tree) { super(tree); } Modified: trunk/jython/src/org/python/antlr/ast/Exec.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Exec.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Exec.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,19 @@ public exprType globals; public exprType locals; - public static final String[] _fields = new String[] - {"body","globals","locals"}; + private final static String[] fields = new String[] {"body", "globals", + "locals"}; + public String[] get_fields() { return fields; } + public Exec(exprType body, exprType globals, exprType locals) { + this.body = body; + addChild(body); + this.globals = globals; + addChild(globals); + this.locals = locals; + addChild(locals); + } + public Exec(Token token, exprType body, exprType globals, exprType locals) { super(token); this.body = body; Modified: trunk/jython/src/org/python/antlr/ast/Expr.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Expr.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Expr.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,14 @@ public class Expr extends stmtType { public exprType value; - public static final String[] _fields = new String[] {"value"}; + private final static String[] fields = new String[] {"value"}; + public String[] get_fields() { return fields; } + public Expr(exprType value) { + this.value = value; + addChild(value); + } + public Expr(Token token, exprType value) { super(token); this.value = value; Modified: trunk/jython/src/org/python/antlr/ast/Expression.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Expression.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Expression.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,14 @@ public class Expression extends modType { public exprType body; - public static final String[] _fields = new String[] {"body"}; + private final static String[] fields = new String[] {"body"}; + public String[] get_fields() { return fields; } + public Expression(exprType body) { + this.body = body; + addChild(body); + } + public Expression(Token token, exprType body) { super(token); this.body = body; Modified: trunk/jython/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ExtSlice.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ExtSlice.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,18 @@ public class ExtSlice extends sliceType { public sliceType[] dims; - public static final String[] _fields = new String[] {"dims"}; + private final static String[] fields = new String[] {"dims"}; + public String[] get_fields() { return fields; } + public ExtSlice(sliceType[] dims) { + this.dims = dims; + if (dims != null) { + for(int idims=0;idims<dims.length;idims++) { + addChild(dims[idims]); + } + } + } + public ExtSlice(Token token, sliceType[] dims) { super(token); this.dims = dims; Modified: trunk/jython/src/org/python/antlr/ast/For.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/For.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/For.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -12,9 +12,30 @@ public stmtType[] body; public stmtType[] orelse; - public static final String[] _fields = new String[] - {"target","iter","body","orelse"}; + private final static String[] fields = new String[] {"target", "iter", + "body", "orelse"}; + public String[] get_fields() { return fields; } + public For(exprType target, exprType iter, stmtType[] body, stmtType[] + orelse) { + this.target = target; + addChild(target); + this.iter = iter; + addChild(iter); + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.orelse = orelse; + if (orelse != null) { + for(int iorelse=0;iorelse<orelse.length;iorelse++) { + addChild(orelse[iorelse]); + } + } + } + public For(Token token, exprType target, exprType iter, stmtType[] body, stmtType[] orelse) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/FunctionDef.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/FunctionDef.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -12,9 +12,28 @@ public stmtType[] body; public exprType[] decorators; - public static final String[] _fields = new String[] - {"name","args","body","decorators"}; + private final static String[] fields = new String[] {"name", "args", + "body", "decorators"}; + public String[] get_fields() { return fields; } + public FunctionDef(String name, argumentsType args, stmtType[] body, + exprType[] decorators) { + this.name = name; + this.args = args; + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.decorators = decorators; + if (decorators != null) { + for(int idecorators=0;idecorators<decorators.length;idecorators++) { + addChild(decorators[idecorators]); + } + } + } + public FunctionDef(Token token, String name, argumentsType args, stmtType[] body, exprType[] decorators) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/GeneratorExp.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/GeneratorExp.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,20 @@ public exprType elt; public comprehensionType[] generators; - public static final String[] _fields = new String[] {"elt","generators"}; + private final static String[] fields = new String[] {"elt", "generators"}; + public String[] get_fields() { return fields; } + public GeneratorExp(exprType elt, comprehensionType[] generators) { + this.elt = elt; + addChild(elt); + this.generators = generators; + if (generators != null) { + for(int igenerators=0;igenerators<generators.length;igenerators++) { + addChild(generators[igenerators]); + } + } + } + public GeneratorExp(Token token, exprType elt, comprehensionType[] generators) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Global.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Global.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Global.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,13 @@ public class Global extends stmtType { public String[] names; - public static final String[] _fields = new String[] {"names"}; + private final static String[] fields = new String[] {"names"}; + public String[] get_fields() { return fields; } + public Global(String[] names) { + this.names = names; + } + public Global(Token token, String[] names) { super(token); this.names = names; Modified: trunk/jython/src/org/python/antlr/ast/If.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/If.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/If.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,27 @@ public stmtType[] body; public stmtType[] orelse; - public static final String[] _fields = new String[] - {"test","body","orelse"}; + private final static String[] fields = new String[] {"test", "body", + "orelse"}; + public String[] get_fields() { return fields; } + public If(exprType test, stmtType[] body, stmtType[] orelse) { + this.test = test; + addChild(test); + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.orelse = orelse; + if (orelse != null) { + for(int iorelse=0;iorelse<orelse.length;iorelse++) { + addChild(orelse[iorelse]); + } + } + } + public If(Token token, exprType test, stmtType[] body, stmtType[] orelse) { super(token); this.test = test; Modified: trunk/jython/src/org/python/antlr/ast/IfExp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/IfExp.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/IfExp.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,19 @@ public exprType body; public exprType orelse; - public static final String[] _fields = new String[] - {"test","body","orelse"}; + private final static String[] fields = new String[] {"test", "body", + "orelse"}; + public String[] get_fields() { return fields; } + public IfExp(exprType test, exprType body, exprType orelse) { + this.test = test; + addChild(test); + this.body = body; + addChild(body); + this.orelse = orelse; + addChild(orelse); + } + public IfExp(Token token, exprType test, exprType body, exprType orelse) { super(token); this.test = test; Modified: trunk/jython/src/org/python/antlr/ast/Import.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Import.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Import.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,18 @@ public class Import extends stmtType { public aliasType[] names; - public static final String[] _fields = new String[] {"names"}; + private final static String[] fields = new String[] {"names"}; + public String[] get_fields() { return fields; } + public Import(aliasType[] names) { + this.names = names; + if (names != null) { + for(int inames=0;inames<names.length;inames++) { + addChild(names[inames]); + } + } + } + public Import(Token token, aliasType[] names) { super(token); this.names = names; Modified: trunk/jython/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ImportFrom.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ImportFrom.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,21 @@ public aliasType[] names; public int level; - public static final String[] _fields = new String[] - {"module","names","level"}; + private final static String[] fields = new String[] {"module", "names", + "level"}; + public String[] get_fields() { return fields; } + public ImportFrom(String module, aliasType[] names, int level) { + this.module = module; + this.names = names; + if (names != null) { + for(int inames=0;inames<names.length;inames++) { + addChild(names[inames]); + } + } + this.level = level; + } + public ImportFrom(Token token, String module, aliasType[] names, int level) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Index.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Index.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Index.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,14 @@ public class Index extends sliceType { public exprType value; - public static final String[] _fields = new String[] {"value"}; + private final static String[] fields = new String[] {"value"}; + public String[] get_fields() { return fields; } + public Index(exprType value) { + this.value = value; + addChild(value); + } + public Index(Token token, exprType value) { super(token); this.value = value; Modified: trunk/jython/src/org/python/antlr/ast/Interactive.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Interactive.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Interactive.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,18 @@ public class Interactive extends modType { public stmtType[] body; - public static final String[] _fields = new String[] {"body"}; + private final static String[] fields = new String[] {"body"}; + public String[] get_fields() { return fields; } + public Interactive(stmtType[] body) { + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + } + public Interactive(Token token, stmtType[] body) { super(token); this.body = body; Modified: trunk/jython/src/org/python/antlr/ast/Lambda.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Lambda.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Lambda.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,15 @@ public argumentsType args; public exprType body; - public static final String[] _fields = new String[] {"args","body"}; + private final static String[] fields = new String[] {"args", "body"}; + public String[] get_fields() { return fields; } + public Lambda(argumentsType args, exprType body) { + this.args = args; + this.body = body; + addChild(body); + } + public Lambda(Token token, argumentsType args, exprType body) { super(token); this.args = args; Modified: trunk/jython/src/org/python/antlr/ast/List.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/List.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/List.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,19 @@ public exprType[] elts; public expr_contextType ctx; - public static final String[] _fields = new String[] {"elts","ctx"}; + private final static String[] fields = new String[] {"elts", "ctx"}; + public String[] get_fields() { return fields; } + public List(exprType[] elts, expr_contextType ctx) { + this.elts = elts; + if (elts != null) { + for(int ielts=0;ielts<elts.length;ielts++) { + addChild(elts[ielts]); + } + } + this.ctx = ctx; + } + public List(Token token, exprType[] elts, expr_contextType ctx) { super(token); this.elts = elts; Modified: trunk/jython/src/org/python/antlr/ast/ListComp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/ListComp.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/ListComp.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,20 @@ public exprType elt; public comprehensionType[] generators; - public static final String[] _fields = new String[] {"elt","generators"}; + private final static String[] fields = new String[] {"elt", "generators"}; + public String[] get_fields() { return fields; } + public ListComp(exprType elt, comprehensionType[] generators) { + this.elt = elt; + addChild(elt); + this.generators = generators; + if (generators != null) { + for(int igenerators=0;igenerators<generators.length;igenerators++) { + addChild(generators[igenerators]); + } + } + } + public ListComp(Token token, exprType elt, comprehensionType[] generators) { super(token); this.elt = elt; Modified: trunk/jython/src/org/python/antlr/ast/Module.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Module.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Module.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,18 @@ public class Module extends modType { public stmtType[] body; - public static final String[] _fields = new String[] {"body"}; + private final static String[] fields = new String[] {"body"}; + public String[] get_fields() { return fields; } + public Module(stmtType[] body) { + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + } + public Module(Token token, stmtType[] body) { super(token); this.body = body; Modified: trunk/jython/src/org/python/antlr/ast/Name.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Name.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Name.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,14 @@ public String id; public expr_contextType ctx; - public static final String[] _fields = new String[] {"id","ctx"}; + private final static String[] fields = new String[] {"id", "ctx"}; + public String[] get_fields() { return fields; } + public Name(String id, expr_contextType ctx) { + this.id = id; + this.ctx = ctx; + } + public Name(Token token, String id, expr_contextType ctx) { super(token); this.id = id; Modified: trunk/jython/src/org/python/antlr/ast/Num.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Num.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Num.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,13 @@ public class Num extends exprType { public Object n; - public static final String[] _fields = new String[] {"n"}; + private final static String[] fields = new String[] {"n"}; + public String[] get_fields() { return fields; } + public Num(Object n) { + this.n = n; + } + public Num(Token token, Object n) { super(token); this.n = n; Modified: trunk/jython/src/org/python/antlr/ast/Pass.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Pass.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Pass.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -8,7 +8,8 @@ public class Pass extends stmtType { - public static final String[] _fields = new String[] {}; + public Pass() { + } public Pass(Token token) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Print.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Print.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Print.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,8 +11,22 @@ public exprType[] values; public boolean nl; - public static final String[] _fields = new String[] {"dest","values","nl"}; + private final static String[] fields = new String[] {"dest", "values", + "nl"}; + public String[] get_fields() { return fields; } + public Print(exprType dest, exprType[] values, boolean nl) { + this.dest = dest; + addChild(dest); + this.values = values; + if (values != null) { + for(int ivalues=0;ivalues<values.length;ivalues++) { + addChild(values[ivalues]); + } + } + this.nl = nl; + } + public Print(Token token, exprType dest, exprType[] values, boolean nl) { super(token); this.dest = dest; Modified: trunk/jython/src/org/python/antlr/ast/Raise.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Raise.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Raise.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,8 +11,19 @@ public exprType inst; public exprType tback; - public static final String[] _fields = new String[] {"type","inst","tback"}; + private final static String[] fields = new String[] {"type", "inst", + "tback"}; + public String[] get_fields() { return fields; } + public Raise(exprType type, exprType inst, exprType tback) { + this.type = type; + addChild(type); + this.inst = inst; + addChild(inst); + this.tback = tback; + addChild(tback); + } + public Raise(Token token, exprType type, exprType inst, exprType tback) { super(token); this.type = type; Modified: trunk/jython/src/org/python/antlr/ast/Repr.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Repr.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Repr.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,14 @@ public class Repr extends exprType { public exprType value; - public static final String[] _fields = new String[] {"value"}; + private final static String[] fields = new String[] {"value"}; + public String[] get_fields() { return fields; } + public Repr(exprType value) { + this.value = value; + addChild(value); + } + public Repr(Token token, exprType value) { super(token); this.value = value; Modified: trunk/jython/src/org/python/antlr/ast/Return.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Return.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Return.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,14 @@ public class Return extends stmtType { public exprType value; - public static final String[] _fields = new String[] {"value"}; + private final static String[] fields = new String[] {"value"}; + public String[] get_fields() { return fields; } + public Return(exprType value) { + this.value = value; + addChild(value); + } + public Return(Token token, exprType value) { super(token); this.value = value; Modified: trunk/jython/src/org/python/antlr/ast/Slice.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Slice.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Slice.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,19 @@ public exprType upper; public exprType step; - public static final String[] _fields = new String[] - {"lower","upper","step"}; + private final static String[] fields = new String[] {"lower", "upper", + "step"}; + public String[] get_fields() { return fields; } + public Slice(exprType lower, exprType upper, exprType step) { + this.lower = lower; + addChild(lower); + this.upper = upper; + addChild(upper); + this.step = step; + addChild(step); + } + public Slice(Token token, exprType lower, exprType upper, exprType step) { super(token); this.lower = lower; Modified: trunk/jython/src/org/python/antlr/ast/Str.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Str.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Str.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,13 @@ public class Str extends exprType { public Object s; - public static final String[] _fields = new String[] {"s"}; + private final static String[] fields = new String[] {"s"}; + public String[] get_fields() { return fields; } + public Str(Object s) { + this.s = s; + } + public Str(Token token, Object s) { super(token); this.s = s; Modified: trunk/jython/src/org/python/antlr/ast/Subscript.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Subscript.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Subscript.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,8 +11,17 @@ public sliceType slice; public expr_contextType ctx; - public static final String[] _fields = new String[] {"value","slice","ctx"}; + private final static String[] fields = new String[] {"value", "slice", + "ctx"}; + public String[] get_fields() { return fields; } + public Subscript(exprType value, sliceType slice, expr_contextType ctx) { + this.value = value; + addChild(value); + this.slice = slice; + this.ctx = ctx; + } + public Subscript(Token token, exprType value, sliceType slice, expr_contextType ctx) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/Suite.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Suite.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Suite.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -9,8 +9,18 @@ public class Suite extends modType { public stmtType[] body; - public static final String[] _fields = new String[] {"body"}; + private final static String[] fields = new String[] {"body"}; + public String[] get_fields() { return fields; } + public Suite(stmtType[] body) { + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + } + public Suite(Token token, stmtType[] body) { super(token); this.body = body; Modified: trunk/jython/src/org/python/antlr/ast/TryExcept.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TryExcept.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/TryExcept.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,32 @@ public excepthandlerType[] handlers; public stmtType[] orelse; - public static final String[] _fields = new String[] - {"body","handlers","orelse"}; + private final static String[] fields = new String[] {"body", "handlers", + "orelse"}; + public String[] get_fields() { return fields; } + public TryExcept(stmtType[] body, excepthandlerType[] handlers, stmtType[] + orelse) { + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.handlers = handlers; + if (handlers != null) { + for(int ihandlers=0;ihandlers<handlers.length;ihandlers++) { + addChild(handlers[ihandlers]); + } + } + this.orelse = orelse; + if (orelse != null) { + for(int iorelse=0;iorelse<orelse.length;iorelse++) { + addChild(orelse[iorelse]); + } + } + } + public TryExcept(Token token, stmtType[] body, excepthandlerType[] handlers, stmtType[] orelse) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/TryFinally.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/TryFinally.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/TryFinally.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,24 @@ public stmtType[] body; public stmtType[] finalbody; - public static final String[] _fields = new String[] {"body","finalbody"}; + private final static String[] fields = new String[] {"body", "finalbody"}; + public String[] get_fields() { return fields; } + public TryFinally(stmtType[] body, stmtType[] finalbody) { + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.finalbody = finalbody; + if (finalbody != null) { + for(int ifinalbody=0;ifinalbody<finalbody.length;ifinalbody++) { + addChild(finalbody[ifinalbody]); + } + } + } + public TryFinally(Token token, stmtType[] body, stmtType[] finalbody) { super(token); this.body = body; Modified: trunk/jython/src/org/python/antlr/ast/Tuple.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/Tuple.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/Tuple.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,19 @@ public exprType[] elts; public expr_contextType ctx; - public static final String[] _fields = new String[] {"elts","ctx"}; + private final static String[] fields = new String[] {"elts", "ctx"}; + public String[] get_fields() { return fields; } + public Tuple(exprType[] elts, expr_contextType ctx) { + this.elts = elts; + if (elts != null) { + for(int ielts=0;ielts<elts.length;ielts++) { + addChild(elts[ielts]); + } + } + this.ctx = ctx; + } + public Tuple(Token token, exprType[] elts, expr_contextType ctx) { super(token); this.elts = elts; Modified: trunk/jython/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/UnaryOp.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/UnaryOp.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -10,8 +10,15 @@ public unaryopType op; public exprType operand; - public static final String[] _fields = new String[] {"op","operand"}; + private final static String[] fields = new String[] {"op", "operand"}; + public String[] get_fields() { return fields; } + public UnaryOp(unaryopType op, exprType operand) { + this.op = op; + this.operand = operand; + addChild(operand); + } + public UnaryOp(Token token, unaryopType op, exprType operand) { super(token); this.op = op; Modified: trunk/jython/src/org/python/antlr/ast/While.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/While.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/While.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,27 @@ public stmtType[] body; public stmtType[] orelse; - public static final String[] _fields = new String[] - {"test","body","orelse"}; + private final static String[] fields = new String[] {"test", "body", + "orelse"}; + public String[] get_fields() { return fields; } + public While(exprType test, stmtType[] body, stmtType[] orelse) { + this.test = test; + addChild(test); + this.body = body; + if (body != null) { + for(int ibody=0;ibody<body.length;ibody++) { + addChild(body[ibody]); + } + } + this.orelse = orelse; + if (orelse != null) { + for(int iorelse=0;iorelse<orelse.length;iorelse++) { + addChild(orelse[iorelse]); + } + } + } + public While(Token token, exprType test, stmtType[] body, stmtType[] orelse) { super(token); Modified: trunk/jython/src/org/python/antlr/ast/With.java =================================================================== --- trunk/jython/src/org/python/antlr/ast/With.java 2008-11-10 03:31:53 UTC (rev 5564) +++ trunk/jython/src/org/python/antlr/ast/With.java 2008-11-10 03:36:31 UTC (rev 5565) @@ -11,9 +11,25 @@ public exprType optional_vars; public stmtType[] body; - public static final String[] _fields = new String[] - {"context_expr","optional_vars","body"}; + private final static String[] fields = new String[] {"context_expr", + "optional_vars", + "body"}; + public String[] get_fields() { return fields; } + public With(exprType context_expr, exprType optional_vars, stmtType[] body) + ... [truncated message content] |
From: <cg...@us...> - 2008-11-10 03:31:58
|
Revision: 5564 http://jython.svn.sourceforge.net/jython/?rev=5564&view=rev Author: cgroves Date: 2008-11-10 03:31:53 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Checkpoint of replacing PyJavaClass with PyJavaType. Works well enough that ProxyMaker creates PyObjects instead of PyJavaInstances and the interpreter starts up, but that's about it Modified Paths: -------------- branches/newstyle-java-types/Lib/test/test_java_visibility.py branches/newstyle-java-types/src/org/python/compiler/ProxyMaker.java branches/newstyle-java-types/src/org/python/core/Options.java branches/newstyle-java-types/src/org/python/core/Py.java branches/newstyle-java-types/src/org/python/core/PyBeanProperty.java branches/newstyle-java-types/src/org/python/core/PyInstance.java branches/newstyle-java-types/src/org/python/core/PyJavaType.java branches/newstyle-java-types/src/org/python/core/PyObject.java branches/newstyle-java-types/src/org/python/core/PyProxy.java branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java branches/newstyle-java-types/src/org/python/core/PyType.java branches/newstyle-java-types/src/org/python/core/ThreadState.java branches/newstyle-java-types/src/org/python/core/adapter/ClassicPyObjectAdapter.java branches/newstyle-java-types/src/org/python/core/adapter/PyObjectAdapter.java Modified: branches/newstyle-java-types/Lib/test/test_java_visibility.py =================================================================== --- branches/newstyle-java-types/Lib/test/test_java_visibility.py 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/Lib/test/test_java_visibility.py 2008-11-10 03:31:53 UTC (rev 5564) @@ -66,8 +66,6 @@ self.failUnless('visibleInstance' in c.__dict__, 'visibleInstance expected in %s __dict__' % c) - - def test_main(): test_support.run_unittest(VisibilityTest) Modified: branches/newstyle-java-types/src/org/python/compiler/ProxyMaker.java =================================================================== --- branches/newstyle-java-types/src/org/python/compiler/ProxyMaker.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/compiler/ProxyMaker.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -12,6 +12,9 @@ import java.util.Set; import org.python.core.Py; +import org.python.core.PyJavaType; +import org.python.core.PyObject; +import org.python.core.PyProxy; import org.python.objectweb.asm.Label; import org.python.objectweb.asm.Opcodes; import org.python.util.Generic; @@ -53,13 +56,40 @@ else return ((Integer)i).intValue(); } + /** + * Retrieves <code>name</code> from the PyObject in <code>proxy</code> if it's defined in + * Python. This is a specialized helper function for internal PyProxy use. + */ + public static PyObject findPython(PyProxy proxy, String name) { + PyObject o = proxy._getPyInstance(); + if (o == null) { + proxy.__initProxy__(new Object[0]); + o = proxy._getPyInstance(); + } + PyObject ret = null; + if (o.getDict() != null) { + ret = o.getDict().__finditem__(name); + } + if (ret == null) { + PyObject[] definedOn = new PyObject[1]; + PyObject typeDefined = o.getType().lookup_where(name, definedOn); + if (!(definedOn[0] instanceof PyJavaType)) { + ret = typeDefined; + } + } + if (ret == null) { + return null; + } + Py.setSystemState(proxy._getPySystemState()); + return ret.__get__(o, null); + } + Class<?> superclass; Class<?>[] interfaces; Set<String> names; Set<String> supernames = Generic.set(); public ClassFile classfile; public String myClass; - public boolean isAdapter=false; public ProxyMaker(String classname, Class<?> superclass) { this.myClass = "org.python.proxies."+classname; @@ -432,7 +462,8 @@ if (!isAbstract) { int tmp = code.getLocal("org/python/core/PyObject"); - code.invokestatic("org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); + code.invokestatic("org/python/compiler/ProxyMaker", "findPython", "(" + $pyProxy + $str + + ")" + $pyObj); code.astore(tmp); code.aload(tmp); @@ -449,20 +480,15 @@ addSuperMethod("super__"+name, name, superClass, parameters, ret, sig, access); } else { - if (!isAdapter) { - code.invokestatic("org/python/core/Py", "jgetattr", "(" + $pyProxy + $str + ")" + $pyObj); - callMethod(code, name, parameters, ret, method.getExceptionTypes()); - } else { - code.invokestatic("org/python/core/Py", "jfindattr", "(" + $pyProxy + $str + ")" + $pyObj); - code.dup(); - Label returnNull = new Label(); - code.ifnull(returnNull); - - callMethod(code, name, parameters, ret, method.getExceptionTypes()); - code.label(returnNull); - code.pop(); - doNullReturn(code, ret); - } + code.invokestatic("org/python/compiler/ProxyMaker", "findPython", "(" + $pyProxy + $str + + ")" + $pyObj); + code.dup(); + Label returnNull = new Label(); + code.ifnull(returnNull); + callMethod(code, name, parameters, ret, method.getExceptionTypes()); + code.label(returnNull); + code.pop(); + doNullReturn(code, ret); } } @@ -600,23 +626,23 @@ public void addProxy() throws Exception { // implement PyProxy interface - classfile.addField("__proxy", "Lorg/python/core/PyInstance;", + classfile.addField("__proxy", "Lorg/python/core/PyObject;", Modifier.PROTECTED); // setProxy methods Code code = classfile.addMethod("_setPyInstance", - "(Lorg/python/core/PyInstance;)V", + "(Lorg/python/core/PyObject;)V", Modifier.PUBLIC); code.aload(0); code.aload(1); - code.putfield(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); + code.putfield(classfile.name, "__proxy", "Lorg/python/core/PyObject;"); code.return_(); // getProxy method code = classfile.addMethod("_getPyInstance", - "()Lorg/python/core/PyInstance;", + "()Lorg/python/core/PyObject;", Modifier.PUBLIC); code.aload(0); - code.getfield(classfile.name, "__proxy", "Lorg/python/core/PyInstance;"); + code.getfield(classfile.name, "__proxy", "Lorg/python/core/PyObject;"); code.areturn(); // implement PyProxy interface Modified: branches/newstyle-java-types/src/org/python/core/Options.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/Options.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/Options.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -4,7 +4,7 @@ /** * A class with static fields for each of the settable options. The options from * registry and command line is copied into the fields here and the rest of - * Jyhton checks these fields. + * Jython checks these fields. */ public class Options { // Jython options. Some of these can be set from the command line @@ -24,7 +24,7 @@ public static boolean includeJavaStackInExceptions = false; /** - * When true, python exception raised in overriden methods will be shown on + * When true, python exception raised in overridden methods will be shown on * stderr. This option is remarkably useful when python is used for * implementing CORBA server. Some CORBA servers will turn python exception * (say a NameError) into an anonymous user exception without any Modified: branches/newstyle-java-types/src/org/python/core/Py.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/Py.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/Py.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -1,7 +1,6 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; @@ -16,7 +15,6 @@ import java.sql.Date; import java.sql.Time; import java.sql.Timestamp; -import java.util.Arrays; import java.util.Calendar; import java.util.HashSet; import java.util.Set; @@ -25,7 +23,6 @@ import org.python.compiler.Module; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; -import org.python.core.util.StringUtil; import org.python.modules.errno; public final class Py { @@ -84,7 +81,7 @@ public static long TPFLAGS_HEAPTYPE; /** Builtin types that are used to setup PyObject. */ - static final Set<Class> BOOTSTRAP_TYPES = new HashSet<Class>(4); + static final Set<Class<?>> BOOTSTRAP_TYPES = new HashSet<Class<?>>(4); static { BOOTSTRAP_TYPES.add(PyObject.class); BOOTSTRAP_TYPES.add(PyType.class); @@ -476,35 +473,6 @@ } /* Helper functions for PyProxy's */ - /** @deprecated */ - public static PyObject jfindattr(PyProxy proxy, String name) { - PyObject ret = getInstance(proxy, name); - if (ret == null) - return null; - Py.setSystemState(proxy._getPySystemState()); - return ret; - } - - - /** @deprecated */ - public static PyObject jgetattr(PyProxy proxy, String name) { - PyObject ret = getInstance(proxy, name); - if (ret == null) - throw Py.AttributeError("abstract method '" + name + "' not implemented"); - Py.setSystemState(proxy._getPySystemState()); - return ret; - } - - private static PyObject getInstance(PyProxy proxy, String name) { - PyInstance o = proxy._getPyInstance(); - if (o == null) { - proxy.__initProxy__(new Object[0]); - o = proxy._getPyInstance(); - } - PyObject ret = o.__jfindattr__(name); - return ret; - } - /* Convenience methods to create new constants without using "new" */ private static PyInteger[] integerCache = null; @@ -836,36 +804,20 @@ if (proxy._getPyInstance() != null) return; ThreadState ts = getThreadState(); - PyInstance instance = ts.getInitializingProxy(); + PyObject instance = ts.getInitializingProxy(); if (instance != null) { - if (instance.javaProxy != null) + if (instance.javaProxy != null) { throw Py.TypeError("Proxy instance reused"); + } instance.javaProxy = proxy; proxy._setPyInstance(instance); proxy._setPySystemState(ts.systemState); return; } - PyObject mod; - // ??pending: findClass or should avoid sys.path loading? - Class modClass = Py.findClass(module+"$_PyInner"); - if (modClass != null) { - PyCode code=null; - try { - code = ((PyRunnable)modClass.newInstance()).getMain(); - } catch (Throwable t) { - throw Py.JavaError(t); - } - mod = imp.createFromCode(module, code); - } else { - mod = imp.importName(module.intern(), false); - } - PyClass pyc = (PyClass)mod.__getattr__(pyclass.intern()); + PyObject mod = imp.importName(module.intern(), false); + PyType pyc = (PyType)mod.__getattr__(pyclass.intern()); - instance = new PyInstance(pyc); - instance.javaProxy = proxy; - proxy._setPyInstance(instance); - proxy._setPySystemState(ts.systemState); PyObject[] pargs; if (args == null || args.length == 0) { @@ -875,7 +827,10 @@ for(int i=0; i<args.length; i++) pargs[i] = Py.java2py(args[i]); } - instance.__init__(pargs, Py.NoKeywords); + instance = pyc.__call__(pargs); + instance.javaProxy = proxy; + proxy._setPyInstance(instance); + proxy._setPySystemState(ts.systemState); } /** Modified: branches/newstyle-java-types/src/org/python/core/PyBeanProperty.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyBeanProperty.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyBeanProperty.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -4,12 +4,10 @@ public class PyBeanProperty extends PyReflectedField { public Method getMethod, setMethod; - public Class myType; + public Class<?> myType; String __name__; - public PyBeanProperty(String name, Class myType, - Method getMethod, Method setMethod) - { + public PyBeanProperty(String name, Class<?> myType, Method getMethod, Method setMethod) { __name__ = name; this.getMethod = getMethod; this.setMethod = setMethod; @@ -56,7 +54,7 @@ if (value instanceof PyTuple) { try { PyTuple vtup = (PyTuple)value; - value = PyJavaClass.lookup(myType).__call__(vtup.getArray()); // xxx PyObject subclasses + value = Py.java2py(myType).__call__(vtup.getArray()); // xxx PyObject subclasses } catch (Throwable t) { // If something goes wrong ignore it? } Modified: branches/newstyle-java-types/src/org/python/core/PyInstance.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyInstance.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyInstance.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -109,7 +109,7 @@ // The javaProxy can be initialized in Py.jfindattr() throw Py.TypeError("Proxy instance already initialized"); } - PyInstance proxyInstance = proxy._getPyInstance(); + PyObject proxyInstance = proxy._getPyInstance(); if (proxyInstance != null && proxyInstance != this) { // The proxy was initialized to another instance!! throw Py.TypeError("Proxy initialization conflict"); Modified: branches/newstyle-java-types/src/org/python/core/PyJavaType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyJavaType.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -14,11 +14,22 @@ private final static Class<?>[] OO = {PyObject.class, PyObject.class}; + public static PyObject wrapJavaObject(Object o) { + PyObject obj = new PyObject(PyType.fromClass(o.getClass())); + obj.javaProxy = o; + return obj; + } + public PyJavaType() { super(TYPE == null ? fromClass(PyType.class) : TYPE); } @Override + public Class<?> getProxyType() { + return underlying_class; + } + + @Override protected void fillDict() { dict = new PyStringMap(); Map<String, Object> propnames = new HashMap<String, Object>(); @@ -83,10 +94,15 @@ } } } - dict.__setitem__(normalize_name(fldname), new PyReflectedField(field)); + if (dict.__finditem__(normalize_name(fldname)) == null) { + dict.__setitem__(normalize_name(fldname), new PyReflectedField(field)); + } } } for (String propname : propnames.keySet()) { + if(propname.equals("")) { + continue; + } String npropname = normalize_name(StringUtil.decapitalize(propname)); PyObject prev = dict.__finditem__(npropname); if (prev != null && prev instanceof PyReflectedFunction) { Modified: branches/newstyle-java-types/src/org/python/core/PyObject.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyObject.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -200,8 +200,15 @@ * @param c the Class to convert this <code>PyObject</code> to. **/ public Object __tojava__(Class<?> c) { - if (c.isInstance(this)) + if ((c == Object.class || c == Serializable.class) && javaProxy != null) { + return javaProxy; + } + if (c.isInstance(this)) { return this; + } + if (c.isInstance(javaProxy)) { + return javaProxy; + } return Py.NoConversion; } @@ -3354,19 +3361,15 @@ // Generated by make_binops.py (End) - /* A convenience function for PyProxy's */ - // Possibly add _jcall(), _jcall(Object, ...) as future optimization /** - * A convenience function for PyProxy's. - * @param args call arguments. - * @exception Throwable + * A convenience function for PyProxys. */ public PyObject _jcallexc(Object[] args) throws Throwable { PyObject[] pargs = new PyObject[args.length]; try { - int n = args.length; - for (int i = 0; i < n; i++) + for (int i = 0; i < args.length; i++) { pargs[i] = Py.java2py(args[i]); + } return __call__(pargs); } catch (PyException e) { if (e.value instanceof PyJavaInstance) { @@ -3927,12 +3930,11 @@ } static { - for (Class unbootstrapped : Py.BOOTSTRAP_TYPES) { + for (Class<?> unbootstrapped : Py.BOOTSTRAP_TYPES) { Py.writeWarning("init", "Bootstrap type wasn't encountered in bootstrapping[class=" + unbootstrapped + "]"); } } - } /* Modified: branches/newstyle-java-types/src/org/python/core/PyProxy.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyProxy.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyProxy.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -3,7 +3,7 @@ /** * Common methods for all generated proxy classes. - * + * * Proxy classes are created whenever a python class inherits from a java class. Instances of such a * python class consists of two objects: * <ul> @@ -12,24 +12,23 @@ * <li>An instance of PyInstance. The PyInstance.javaProxy contains a reference to the proxy class * instance. * </ul> - * - * All proxy classes, both dynamically generated and statically generated by jythonc implements this - * interface. + * + * All proxy classes implement this interface. */ // This interface should be applicable to ANY class // Choose names that are extremely unlikely to have conflicts public interface PyProxy { /** - * Associate an PyInstance with this proxy instance. This is done during construction and + * Associate a PyObject with this proxy instance. This is done during construction and * initialization of the proxy instance. */ - abstract public void _setPyInstance(PyInstance proxy); + void _setPyInstance(PyObject proxy); /** - * Return the associated PyInstance instance. + * Return the associated PyObject. */ - abstract public PyInstance _getPyInstance(); + PyObject _getPyInstance(); /** * Associate an system state with this proxy instance. This is done during construction and @@ -40,16 +39,16 @@ /** * Return the associated system state. */ - abstract public PySystemState _getPySystemState(); + PySystemState _getPySystemState(); /** - * Initialize the proxy instance. If the proxy have not been initialized already, this call will - * call the python constructor with <code>args</code>. + * Initialize the proxy instance. If the proxy is not initialized, this will call the python + * constructor with <code>args</code>. * <p> * In some situations is it necessary to call the __initProxy__ method from the java superclass - * ctor before the ctor makes call to methods that is overriden in python. + * ctor before the ctor makes call to methods that is overridden in python. * <p> * In most situation the __initProxy__ is called automatically by the jython runtime. */ - public abstract void __initProxy__(Object[] args); + void __initProxy__(Object[] args); } Modified: branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyReflectedConstructor.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -90,7 +90,7 @@ if (self instanceof PyInstance) { javaClass = ((PyInstance)self).instclass.proxyClass; } else { - javaClass = self.getType().underlying_class; + javaClass = self.getType().getProxyType(); } Class<?> declaringClass = argslist[0].declaringClass; @@ -98,12 +98,6 @@ throw Py.TypeError("self invalid - must implement: " + declaringClass.getName()); } - if (!PyProxy.class.isAssignableFrom(declaringClass) && !(self instanceof PyJavaInstance)) { - PyJavaClass jc = PyJavaClass.lookup(javaClass); - jc.initConstructors(); - return jc.__init__.__call__(self, args, keywords); - } - if (self.javaProxy != null) { Class<?> sup = javaClass; if (PyProxy.class.isAssignableFrom(sup)) { @@ -158,9 +152,7 @@ Object jself = null; ThreadState ts = Py.getThreadState(); try { - if (obj instanceof PyInstance) { - ts.pushInitializingProxy((PyInstance)obj); - } + ts.pushInitializingProxy(obj); try { jself = ctor.newInstance(args); } catch (InvocationTargetException e) { @@ -177,9 +169,7 @@ throw Py.JavaError(t); } } finally { - if (obj instanceof PyInstance) { - ts.popInitializingProxy(); - } + ts.popInitializingProxy(); } obj.javaProxy = jself; } Modified: branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyReflectedFunction.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -138,26 +138,6 @@ Object cself = callData.self; Method m = (Method)method; - // Check to see if we should be using a super__ method instead - // This is probably a bit inefficient... - if (self == null && cself != null && cself instanceof PyProxy && - !__name__.startsWith("super__")) { - PyInstance iself = ((PyProxy)cself)._getPyInstance(); - if (argslist[0].declaringClass != iself.instclass.proxyClass) { - String mname = ("super__"+__name__); - // xxx experimental - Method[] super__methods = (Method[])iself.instclass.super__methods.get(mname); - if (super__methods != null) { - Class[] msig = m.getParameterTypes(); - for (Method super__method : super__methods) { - if (java.util.Arrays.equals(msig,super__method.getParameterTypes())) { - m = super__method; - break; - } - } - } - } - } try { Object o = m.invoke(cself, callData.getArgsArray()); Modified: branches/newstyle-java-types/src/org/python/core/PyType.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/PyType.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/PyType.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -133,6 +133,26 @@ if (bases_list.length == 0) { bases_list = new PyObject[] {object_type}; } + List<Class<?>> interfaces = Generic.list(); + Class<?> baseClass = null; + for (PyObject base : bases_list) { + if (!(base instanceof PyType)) { + continue; + } + Class<?> proxy = ((PyType)base).getProxyType(); + if (proxy == null) { + continue; + } + if (proxy.isInterface()) { + interfaces.add(proxy); + } else { + if (baseClass != null) { + throw Py.TypeError("no multiple inheritance for Java classes: " + + proxy.getName() + " and " + baseClass.getName()); + } + baseClass = proxy; + } + } // XXX can be subclassed ? if (dict.__finditem__("__module__") == null) { @@ -147,6 +167,33 @@ } // XXX also __doc__ __module__ + + if (baseClass != null || interfaces.size() != 0) { + String proxyName = name; + PyObject module = dict.__finditem__("__module__"); + if (module != null) { + proxyName = module.toString() + "$" + proxyName; + } + Class<?> proxyClass = MakeProxies.makeProxy(baseClass, + interfaces, + name, + proxyName, + dict); + PyType proxyType = PyType.fromClass(proxyClass); + List<PyObject> cleanedBases = Generic.list(); + boolean addedProxyType = false; + for (PyObject base : bases_list) { + if (base instanceof PyJavaType) { + if (!addedProxyType) { + cleanedBases.add(proxyType); + addedProxyType = true; + } + } else { + cleanedBases.add(base); + } + } + bases_list = cleanedBases.toArray(new PyObject[cleanedBases.size()]); + } PyType newtype; if (new_.for_type == metatype) { newtype = new PyType(); // XXX set metatype @@ -294,23 +341,19 @@ } private static void fillInMRO(PyType type, Class<?> base) { - PyType[] mro; - if (base == Object.class || base == null) { - if (type.underlying_class == Object.class) { - mro = new PyType[] {type, PyObject.TYPE}; - } else { - mro = new PyType[] {type}; + if (type.underlying_class == PyObject.class) { + type.mro = new PyType[] {type}; + return; } - } else { - PyType baseType = fromClass(base); - mro = new PyType[baseType.mro.length + 1]; - System.arraycopy(baseType.mro, 0, mro, 1, baseType.mro.length); - mro[0] = type; - type.base = baseType; - type.bases = new PyObject[] {baseType}; + base = PyObject.class; } - type.mro = mro; + PyType baseType = fromClass(base); + type.mro = new PyType[baseType.mro.length + 1]; + System.arraycopy(baseType.mro, 0, type.mro, 1, baseType.mro.length); + type.mro[0] = type; + type.base = baseType; + type.bases = new PyObject[] {baseType}; } public PyObject getStatic() { @@ -417,7 +460,6 @@ mro = savedMro; throw t; } - } private void mro_internal() { @@ -504,6 +546,21 @@ return result; } + /** + * Returns the Java Class that this type inherits from, or null if this type is Python-only. + */ + public Class<?> getProxyType() { + for (PyObject base : bases) { + if (base instanceof PyType) { + Class<?> javaType = ((PyType)base).getProxyType(); + if (javaType != null) { + return javaType; + } + } + } + return null; + } + private synchronized void attachSubclass(PyType subtype) { cleanup_subclasses(); subclasses.add(new WeakReference<PyType>(subtype, subclasses_refq)); Modified: branches/newstyle-java-types/src/org/python/core/ThreadState.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/ThreadState.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/ThreadState.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -25,20 +25,20 @@ public TraceFunction profilefunc; - private LinkedList<PyInstance> initializingProxies; + private LinkedList<PyObject> initializingProxies; private PyDictionary compareStateDict; - public PyInstance getInitializingProxy() { + public PyObject getInitializingProxy() { if (initializingProxies == null) { return null; } return initializingProxies.peek(); } - public void pushInitializingProxy(PyInstance proxy) { + public void pushInitializingProxy(PyObject proxy) { if (initializingProxies == null) { - initializingProxies = new LinkedList<PyInstance>(); + initializingProxies = new LinkedList<PyObject>(); } initializingProxies.addFirst(proxy); } Modified: branches/newstyle-java-types/src/org/python/core/adapter/ClassicPyObjectAdapter.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/adapter/ClassicPyObjectAdapter.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/adapter/ClassicPyObjectAdapter.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -4,8 +4,7 @@ import org.python.core.PyArray; import org.python.core.PyFloat; import org.python.core.PyInteger; -import org.python.core.PyJavaClass; -import org.python.core.PyJavaInstance; +import org.python.core.PyJavaType; import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyProxy; @@ -14,14 +13,14 @@ /** * Implements the algorithm originally used in {@link Py#java2py} to adapt objects. - * + * * Pre-class adapters are added to handle instances of PyObject, PyProxy and * null values. Class adapters are added to handle builtin Java classes: String, * Integer, Float, Double, Byte, Long, Short, Character, Class and Boolean. An * adapter is added to the post-class adapters to handle wrapping arrays * properly. Finally, if all of the added adapters can handle an object, it's * wrapped in a PyJavaInstance. - * + * */ public class ClassicPyObjectAdapter extends ExtensiblePyObjectAdapter { @@ -67,19 +66,15 @@ add(new ClassAdapter(Character.class) { public PyObject adapt(Object o) { - return Py.makeCharacter((Character) o); - } + return Py.makeCharacter((Character)o); + } }); add(new ClassAdapter(Class.class) { public PyObject adapt(Object o) { - Class cls = (Class) o; - if (PyObject.class.isAssignableFrom(cls)) { - return PyType.fromClass(cls); - } - return PyJavaClass.lookup(cls); - } + return PyType.fromClass((Class<?>)o); + } }); add(new NumberToPyFloat(Double.class)); @@ -126,7 +121,7 @@ if (result != null) { return result; } - return new PyJavaInstance(o); + return PyJavaType.wrapJavaObject(o); } private static class NumberToPyInteger extends ClassAdapter { Modified: branches/newstyle-java-types/src/org/python/core/adapter/PyObjectAdapter.java =================================================================== --- branches/newstyle-java-types/src/org/python/core/adapter/PyObjectAdapter.java 2008-11-10 03:29:23 UTC (rev 5563) +++ branches/newstyle-java-types/src/org/python/core/adapter/PyObjectAdapter.java 2008-11-10 03:31:53 UTC (rev 5564) @@ -7,14 +7,13 @@ */ public interface PyObjectAdapter { - /** - * @return true if o can be adapted by this adapter. - */ - public abstract boolean canAdapt(Object o); + /** + * Returns true if o can be adapted by this adapter. + */ + public abstract boolean canAdapt(Object o); - /** - * @return the PyObject version of o or null if canAdapt(o) returns false. - */ - public abstract PyObject adapt(Object o); - + /** + * Returns the PyObject version of o or null if canAdapt(o) returns false. + */ + public abstract PyObject adapt(Object o); } \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-10 03:29:33
|
Revision: 5563 http://jython.svn.sourceforge.net/jython/?rev=5563&view=rev Author: cgroves Date: 2008-11-10 03:29:23 +0000 (Mon, 10 Nov 2008) Log Message: ----------- Branching for exposing Java classes as PyType and making proxies PyObject instead of PyInstance Added Paths: ----------- branches/newstyle-java-types/ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-10 02:53:09
|
Revision: 5562 http://jython.svn.sourceforge.net/jython/?rev=5562&view=rev Author: pjenvey Date: 2008-11-10 02:53:05 +0000 (Mon, 10 Nov 2008) Log Message: ----------- fix %c formatting to support unicode refs #1768075, fixes #1780767 Modified Paths: -------------- trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/src/org/python/core/PyString.java Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2008-11-10 01:22:11 UTC (rev 5561) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-11-10 02:53:05 UTC (rev 5562) @@ -4,6 +4,7 @@ Made for Jython. """ import re +import sys import unittest from test import test_support @@ -58,7 +59,20 @@ self.assertEqual(float(u'\u0663.\u0661'), 3.1) self.assertEqual(complex(u'\u0663.\u0661'), 3.1+0j) + def test_formatchar(self): + self.assertEqual('%c' % 255, '\xff') + self.assertRaises(OverflowError, '%c'.__mod__, 256) + result = u'%c' % 256 + self.assert_(isinstance(result, unicode)) + self.assertEqual(result, u'\u0100') + if sys.maxunicode == 0xffff: + self.assertEqual(u'%c' % sys.maxunicode, u'\uffff') + else: + self.assertEqual(u'%c' % sys.maxunicode, u'\U0010ffff') + self.assertRaises(OverflowError, '%c'.__mod__, sys.maxunicode + 1) + + def test_main(): test_support.run_unittest(UnicodeTestCase) Modified: trunk/jython/src/org/python/core/PyString.java =================================================================== --- trunk/jython/src/org/python/core/PyString.java 2008-11-10 01:22:11 UTC (rev 5561) +++ trunk/jython/src/org/python/core/PyString.java 2008-11-10 02:53:05 UTC (rev 5562) @@ -2960,12 +2960,16 @@ } throw e; } - if (val < 0) { - throw Py.OverflowError("unsigned byte integer is less than minimum"); - } else if (val > 255) { - throw Py.OverflowError("unsigned byte integer is greater than maximum"); + if (!needUnicode) { + if (val < 0) { + throw Py.OverflowError("unsigned byte integer is less than minimum"); + } else if (val > 255) { + throw Py.OverflowError("unsigned byte integer is greater than maximum"); + } + } else if (val < 0 || val > PySystemState.maxunicode) { + throw Py.OverflowError("%c arg not in range(0x110000) (wide Python build)"); } - string = new Character((char)val).toString(); + string = new String(new int[] {val}, 0, 1); break; default: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-10 01:22:12
|
Revision: 5561 http://jython.svn.sourceforge.net/jython/?rev=5561&view=rev Author: pjenvey Date: 2008-11-10 01:22:11 +0000 (Mon, 10 Nov 2008) Log Message: ----------- no need for getErrorHeader (line/offset) in our SyntaxError messages Modified Paths: -------------- trunk/jython/src/org/python/antlr/FailFastHandler.java Modified: trunk/jython/src/org/python/antlr/FailFastHandler.java =================================================================== --- trunk/jython/src/org/python/antlr/FailFastHandler.java 2008-11-10 00:36:41 UTC (rev 5560) +++ trunk/jython/src/org/python/antlr/FailFastHandler.java 2008-11-10 01:22:11 UTC (rev 5561) @@ -57,9 +57,7 @@ } private String message(BaseRecognizer br, RecognitionException re) { - String hdr = br.getErrorHeader(re); - String msg = br.getErrorMessage(re, br.getTokenNames()); - return hdr+" "+msg; + return br.getErrorMessage(re, br.getTokenNames()); } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-10 00:36:47
|
Revision: 5560 http://jython.svn.sourceforge.net/jython/?rev=5560&view=rev Author: pjenvey Date: 2008-11-10 00:36:41 +0000 (Mon, 10 Nov 2008) Log Message: ----------- pretty up SyntaxError surrounding output: o don't initialize an exception traceback if there's no frame o port over CPython's pythonrun::print_error_text o always include a trailing nl in SyntaxError text like CPython Modified Paths: -------------- trunk/jython/src/org/python/core/ParserFacade.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/PyException.java Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2008-11-09 20:15:15 UTC (rev 5559) +++ trunk/jython/src/org/python/core/ParserFacade.java 2008-11-10 00:36:41 UTC (rev 5560) @@ -40,16 +40,16 @@ private ParserFacade() {} - static String getLine(BufferedReader reader, int line) { + private static String getLine(BufferedReader reader, int line) { if (reader == null) { return ""; } String text = null; try { - for(int i=0; i < line; i++) { + for (int i = 0; i < line; i++) { text = reader.readLine(); } - return text; + return text == null ? text : text + "\n"; } catch (IOException ioe) { } return text; Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-11-09 20:15:15 UTC (rev 5559) +++ trunk/jython/src/org/python/core/Py.java 2008-11-10 00:36:41 UTC (rev 5560) @@ -1007,18 +1007,23 @@ stderr.print(((PyTraceback) tb).dumpStack()); } if (__builtin__.isinstance(value, Py.SyntaxError)) { - stderr.println(" File \"" + value.__findattr__("filename") + - "\", line " + value.__findattr__("lineno")); + PyObject filename = value.__findattr__("filename"); PyObject text = value.__findattr__("text"); - if (text != Py.None && text.__len__() != 0) { - stderr.println("\t" + text); - String space = "\t"; - int col = ((PyInteger) value.__findattr__("offset").__int__()).getValue(); - for (int j = 1; j < col; j++) { - space = space + " "; - } - stderr.println(space + "^"); + PyObject lineno = value.__findattr__("lineno"); + stderr.print(" File \""); + stderr.print(filename == Py.None || filename == null ? + "<string>" : filename.toString()); + stderr.print("\", line "); + stderr.print(lineno == null ? Py.newString("0") : lineno); + stderr.print("\n"); + if (text != Py.None && text != null && text.__len__() != 0) { + printSyntaxErrorText(stderr, value.__findattr__("offset").asInt(), + text.toString()); } + value = value.__findattr__("msg"); + if (value == null) { + value = Py.None; + } } if (value instanceof PyJavaInstance) { @@ -1031,6 +1036,56 @@ stderr.println(formatException(type, value, tb)); } + /** + * Print the two lines showing where a SyntaxError was caused. + * + * @param out StdoutWrapper to print to + * @param offset the offset into text + * @param text a source code String line + */ + private static void printSyntaxErrorText(StdoutWrapper out, int offset, String text) { + if (offset >= 0) { + if (offset > 0 && offset == text.length()) { + offset--; + } + + // Eat lines if the offset is on a subsequent line + while (true) { + int nl = text.indexOf("\n"); + if (nl == -1 || nl >= offset) { + break; + } + offset -= nl + 1; + text = text.substring(nl + 1, text.length()); + } + + // lstrip + int i = 0; + for (; i < text.length(); i++) { + char c = text.charAt(i); + if (c != ' ' && c != '\t') { + break; + } + offset--; + } + text = text.substring(i, text.length()); + } + + out.print(" "); + out.print(text); + if (text.length() == 0 || !text.endsWith("\n")) { + out.print("\n"); + } + if (offset == -1) { + return; + } + out.print(" "); + for (offset--; offset > 0; offset--) { + out.print(" "); + } + out.print("^\n"); + } + static String formatException(PyObject type, PyObject value, PyObject tb) { StringBuffer buf = new StringBuffer(); Modified: trunk/jython/src/org/python/core/PyException.java =================================================================== --- trunk/jython/src/org/python/core/PyException.java 2008-11-09 20:15:15 UTC (rev 5559) +++ trunk/jython/src/org/python/core/PyException.java 2008-11-10 00:36:41 UTC (rev 5560) @@ -44,14 +44,17 @@ this.type = type; this.value = value; - if (traceback == null) { + if (traceback != null) { + this.traceback = traceback; + } else { PyFrame frame = Py.getFrame(); - traceback = new PyTraceback(frame); - if (frame != null && frame.tracefunc != null) { - frame.tracefunc = frame.tracefunc.traceException(frame, this); + if (frame != null) { + this.traceback = new PyTraceback(frame); + if (frame.tracefunc != null) { + frame.tracefunc = frame.tracefunc.traceException(frame, this); + } } } - this.traceback = traceback; } public PyException(PyObject type, String value) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-09 20:15:19
|
Revision: 5559 http://jython.svn.sourceforge.net/jython/?rev=5559&view=rev Author: cgroves Date: 2008-11-09 20:15:15 +0000 (Sun, 09 Nov 2008) Log Message: ----------- Force jarjar to run if antlr is going to do a clean. This was causing the build to get into a weird state requiring a clean if local compilation failed after antlr changed. Modified Paths: -------------- trunk/jython/build.xml Modified: trunk/jython/build.xml =================================================================== --- trunk/jython/build.xml 2008-11-09 19:46:24 UTC (rev 5558) +++ trunk/jython/build.xml 2008-11-09 20:15:15 UTC (rev 5559) @@ -109,13 +109,20 @@ <target name="full-build" depends="full-check, install" description="a full build with svn checkout" /> <target name="needed-check" unless="full-build"> - <uptodate property="jarjar.notneeded" targetfile="${output.dir}/jarjar.jar"> - <srcfiles dir="extlibs" includes="*" /> + <uptodate property="antlr.notneeded" targetfile="${output.dir}/jarjar.jar"> <srcfiles dir="grammar" includes="*.g" /> </uptodate> - <uptodate property="antlr.notneeded" targetfile="${dist.dir}/jython.jar"> - <srcfiles dir="grammar" includes="*.g" /> - </uptodate> + <!-- When antlr.notneeded isn't set, a clean is run after this, so jarjar's running depends + on both that and its own jar --> + <condition property="jarjar.notneeded"> + <and> + <isset property="antlr.notneeded"/> + <uptodate targetfile="${output.dir}/jarjar.jar"> + <srcfiles dir="extlibs" includes="*" /> + <srcfiles dir="grammar" includes="*.g" /> + </uptodate> + </and> + </condition> </target> <target name="init" depends="version-init"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <cg...@us...> - 2008-11-09 19:46:27
|
Revision: 5558 http://jython.svn.sourceforge.net/jython/?rev=5558&view=rev Author: cgroves Date: 2008-11-09 19:46:24 +0000 (Sun, 09 Nov 2008) Log Message: ----------- Set the name of every PythonInterpreter module to __main__, not just those created through org.python.util.jython. Fixes proxy class lookup for proxies created in the interpreter's module. Modified Paths: -------------- trunk/jython/src/org/python/util/PythonInterpreter.java trunk/jython/src/org/python/util/jython.java Modified: trunk/jython/src/org/python/util/PythonInterpreter.java =================================================================== --- trunk/jython/src/org/python/util/PythonInterpreter.java 2008-11-08 00:08:20 UTC (rev 5557) +++ trunk/jython/src/org/python/util/PythonInterpreter.java 2008-11-09 19:46:24 UTC (rev 5558) @@ -1,41 +1,47 @@ -// Copyright (c) Corporation for National Research Initiatives package org.python.util; -import org.python.core.*; -import java.util.*; +import java.util.Properties; + +import org.python.core.CompilerFlags; +import org.python.core.Py; +import org.python.core.PyCode; +import org.python.core.PyException; +import org.python.core.PyFile; +import org.python.core.PyModule; +import org.python.core.PyObject; +import org.python.core.PyString; +import org.python.core.PyStringMap; +import org.python.core.PySystemState; +import org.python.core.__builtin__; + /** - * The PythonInterpreter class is a standard wrapper for a Jython - * interpreter for use embedding in a Java application. - * - * @author Jim Hugunin - * @version 1.0, 02/23/97 + * The PythonInterpreter class is a standard wrapper for a Jython interpreter for use embedding in a + * Java application. */ - public class PythonInterpreter { + PyModule module; + protected PySystemState systemState; + PyObject locals; protected CompilerFlags cflags = new CompilerFlags(); /** - * Initializes the jython runtime. This should only be called once, and - * should be called before any other python objects are created (including a - * PythonInterpreter). + * Initializes the jython runtime. This should only be called once, and should be called before + * any other python objects are created (including a PythonInterpreter). * * @param preProperties * A set of properties. Typically System.getProperties() is used. * @param postProperties - * An other set of properties. Values like python.home, - * python.path and all other values from the registry files can - * be added to this property set. PostProperties will override - * system properties and registry properties. + * An other set of properties. Values like python.home, python.path and all other + * values from the registry files can be added to this property set. PostProperties + * will override system properties and registry properties. * @param argv * Command line argument. These values will assigned to sys.argv. */ - public static void initialize(Properties preProperties, - Properties postProperties, - String[] argv) { + public static void initialize(Properties preProperties, Properties postProperties, String[] argv) { PySystemState.initialize(preProperties, postProperties, argv); } @@ -47,29 +53,27 @@ } /** - * Create a new interpreter with the given dictionary to use as its - * namespace - * - * @param dict the dictionary to use + * Create a new interpreter with the given dictionary to use as its namespace */ - - // Optional dictionary will be used for locals namespace public PythonInterpreter(PyObject dict) { this(dict, null); } public PythonInterpreter(PyObject dict, PySystemState systemState) { - if (dict == null) + if (dict == null) { dict = new PyStringMap(); + } if (systemState == null) { systemState = Py.getSystemState(); - if (systemState == null) + if (systemState == null) { systemState = new PySystemState(); + } } - module = new PyModule("__main__", dict); this.systemState = systemState; - locals = module.__dict__; setState(); + module = new PyModule("__main__", dict); + systemState.modules.__setitem__("__main__", module); + locals = dict; } protected void setState() { @@ -79,7 +83,8 @@ /** * Set the Python object to use for the standard output stream * - * @param outStream Python file-like object to use as output stream + * @param outStream + * Python file-like object to use as output stream */ public void setOut(PyObject outStream) { systemState.stdout = outStream; @@ -88,7 +93,8 @@ /** * Set a java.io.OutputStream to use for the standard output stream * - * @param outStream OutputStream to use as output stream + * @param outStream + * OutputStream to use as output stream */ public void setOut(java.io.OutputStream outStream) { setOut(new PyFile(outStream)); @@ -104,8 +110,6 @@ /** * Evaluate a string as Python source and return the result - * - * @param s the string to evaluate */ public PyObject eval(String s) { setState(); @@ -114,20 +118,15 @@ /** * Execute a string of Python source in the local namespace - * - * @param s the string to execute */ public void exec(String s) { setState(); - Py.exec(Py.compile_flags(s, "<string>", "exec",cflags), - locals, locals); + Py.exec(Py.compile_flags(s, "<string>", "exec", cflags), locals, locals); Py.flushLine(); } /** * Execute a Python code object in the local namespace - * - * @param code the code object to execute */ public void exec(PyObject code) { setState(); @@ -137,12 +136,10 @@ /** * Execute a file of Python source in the local namespace - * - * @param s the name of the file to execute */ - public void execfile(String s) { + public void execfile(String filename) { setState(); - __builtin__.execfile_flags(s, locals, locals, cflags); + __builtin__.execfile_flags(filename, locals, locals, cflags); Py.flushLine(); } @@ -152,11 +149,10 @@ public void execfile(java.io.InputStream s, String name) { setState(); - Py.runCode((PyCode)Py.compile_flags(s, name, "exec",cflags), locals, locals); + Py.runCode((PyCode)Py.compile_flags(s, name, "exec", cflags), locals, locals); Py.flushLine(); } - // Getting and setting the locals dictionary public PyObject getLocals() { return locals; } @@ -168,10 +164,12 @@ /** * Set a variable in the local namespace * - * @param name the name of the variable - * @param value the value to set the variable to. - Will be automatically converted to an appropriate Python object. - */ + * @param name + * the name of the variable + * @param value + * the value to set the variable to. Will be automatically converted to an + * appropriate Python object. + */ public void set(String name, Object value) { locals.__setitem__(name.intern(), Py.java2py(value)); } @@ -179,8 +177,10 @@ /** * Set a variable in the local namespace * - * @param name the name of the variable - * @param value the value to set the variable to + * @param name + * the name of the variable + * @param value + * the value to set the variable to */ public void set(String name, PyObject value) { locals.__setitem__(name.intern(), value); @@ -198,21 +198,19 @@ } /** - * Get the value of a variable in the local namespace Value will be returned - * as an instance of the given Java class. - * <code>interp.get("foo", Object.class)</code> will return the most + * Get the value of a variable in the local namespace Value will be returned as an instance of + * the given Java class. <code>interp.get("foo", Object.class)</code> will return the most * appropriate generic Java object. * * @param name * the name of the variable * @param javaclass * the class of object to return - * @return the value of the variable as the given class, or null if that - * name isn't assigned + * @return the value of the variable as the given class, or null if that name isn't assigned */ public <T> T get(String name, Class<T> javaclass) { PyObject val = locals.__finditem__(name.intern()); - if(val == null) { + if (val == null) { return null; } return Py.tojava(val, javaclass); Modified: trunk/jython/src/org/python/util/jython.java =================================================================== --- trunk/jython/src/org/python/util/jython.java 2008-11-08 00:08:20 UTC (rev 5557) +++ trunk/jython/src/org/python/util/jython.java 2008-11-09 19:46:24 UTC (rev 5558) @@ -16,7 +16,6 @@ import org.python.core.PyException; import org.python.core.PyFile; import org.python.core.PyList; -import org.python.core.PyModule; import org.python.core.PyString; import org.python.core.PyStringMap; import org.python.core.PySystemState; @@ -302,26 +301,17 @@ } /** - * @return a new python interpreter, instantiating the right - * InteractiveConsole subclass for the configured <tt>python.console</tt> + * Returns a new python interpreter using the InteractiveConsole subclass from the + * <tt>python.console</tt> registry key. */ private static InteractiveConsole newInterpreter() { - InteractiveConsole interp = null; try { - String interpClass = PySystemState.registry.getProperty( - "python.console", - "org.python.util.InteractiveConsole"); - interp = (InteractiveConsole) - Class.forName(interpClass).newInstance(); + String interpClass = PySystemState.registry.getProperty("python.console", + "org.python.util.InteractiveConsole"); + return (InteractiveConsole)Class.forName(interpClass).newInstance(); } catch (Exception e) { - interp = new InteractiveConsole(); -} - - //System.err.println("interp"); - PyModule mod = imp.addModule("__main__"); - interp.setLocals(mod.__dict__); - //System.err.println("imp"); - return interp; + return new InteractiveConsole(); + } } /** This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-08 00:08:31
|
Revision: 5557 http://jython.svn.sourceforge.net/jython/?rev=5557&view=rev Author: pjenvey Date: 2008-11-08 00:08:20 +0000 (Sat, 08 Nov 2008) Log Message: ----------- rearrange the rich cmp methods so they can't call themselves fixes #1115 thanks Tom Mueller Modified Paths: -------------- trunk/jython/Lib/test/test_list_jy.py trunk/jython/src/org/python/core/PySequence.java Modified: trunk/jython/Lib/test/test_list_jy.py =================================================================== --- trunk/jython/Lib/test/test_list_jy.py 2008-11-07 08:25:32 UTC (rev 5556) +++ trunk/jython/Lib/test/test_list_jy.py 2008-11-08 00:08:20 UTC (rev 5557) @@ -1,17 +1,30 @@ import unittest import test.test_support -class ListTest(unittest.TestCase): - - def test_recursive_list_slices(self): - x = [1,2,3,4,5] - x[1:] = x +class ListTestCase(unittest.TestCase): - self.assertEquals(x, [1, 1, 2, 3, 4, 5], - "Recursive assignment to list slices failed") + def test_recursive_list_slices(self): + x = [1,2,3,4,5] + x[1:] = x + self.assertEquals(x, [1, 1, 2, 3, 4, 5], + "Recursive assignment to list slices failed") + def test_subclass_richcmp(self): + # http://bugs.jython.org/issue1115 + class Foo(list): + def __init__(self, dotstring): + list.__init__(self, map(int, dotstring.split("."))) + bar1 = Foo('1.2.3') + bar2 = Foo('1.2.4') + self.assert_(bar1 < bar2) + self.assert_(bar1 <= bar2) + self.assert_(bar2 > bar1) + self.assert_(bar2 >= bar1) + + def test_main(): - test.test_support.run_unittest(ListTest) + test.test_support.run_unittest(ListTestCase) + if __name__ == "__main__": - test_main() + test_main() Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2008-11-07 08:25:32 UTC (rev 5556) +++ trunk/jython/src/org/python/core/PySequence.java 2008-11-08 00:08:20 UTC (rev 5557) @@ -136,6 +136,10 @@ } public synchronized PyObject __lt__(PyObject o) { + return seq___lt__(o); + } + + final synchronized PyObject seq___lt__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -146,11 +150,11 @@ return __finditem__(i)._lt(o.__finditem__(i)); } - final synchronized PyObject seq___lt__(PyObject o) { - return __lt__(o); + public synchronized PyObject __le__(PyObject o) { + return seq___le__(o); } - public synchronized PyObject __le__(PyObject o) { + final synchronized PyObject seq___le__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -161,11 +165,11 @@ return __finditem__(i)._le(o.__finditem__(i)); } - final synchronized PyObject seq___le__(PyObject o) { - return __le__(o); + public synchronized PyObject __gt__(PyObject o) { + return seq___gt__(o); } - public synchronized PyObject __gt__(PyObject o) { + final synchronized PyObject seq___gt__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -175,11 +179,11 @@ return __finditem__(i)._gt(o.__finditem__(i)); } - final synchronized PyObject seq___gt__(PyObject o) { - return __gt__(o); + public synchronized PyObject __ge__(PyObject o) { + return seq___ge__(o); } - public synchronized PyObject __ge__(PyObject o) { + final synchronized PyObject seq___ge__(PyObject o) { if(!(getType() == o.getType()) && !(getType().isSubType(o.getType()))) { return null; } @@ -190,10 +194,6 @@ return __finditem__(i)._ge(o.__finditem__(i)); } - final synchronized PyObject seq___ge__(PyObject o) { - return __ge__(o); - } - // Return value >= 0 is the index where the sequences differs. // -1: reached the end of o1 without a difference // -2: reached the end of both seqeunces without a difference This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-07 08:25:41
|
Revision: 5556 http://jython.svn.sourceforge.net/jython/?rev=5556&view=rev Author: pjenvey Date: 2008-11-07 08:25:32 +0000 (Fri, 07 Nov 2008) Log Message: ----------- use codecs.BOM_UTF8 Modified Paths: -------------- trunk/jython/Lib/test/test_builtin_jy.py Modified: trunk/jython/Lib/test/test_builtin_jy.py =================================================================== --- trunk/jython/Lib/test/test_builtin_jy.py 2008-11-07 08:20:22 UTC (rev 5555) +++ trunk/jython/Lib/test/test_builtin_jy.py 2008-11-07 08:25:32 UTC (rev 5556) @@ -2,6 +2,7 @@ import sys import unittest import test.test_support +from codecs import BOM_UTF8 class BuiltinTest(unittest.TestCase): @@ -123,19 +124,17 @@ class ExecEvalTest(unittest.TestCase): - bom = '\xef\xbb\xbf' - def test_eval_bom(self): - self.assertEqual(eval(self.bom + '"foo"'), 'foo') + self.assertEqual(eval(BOM_UTF8 + '"foo"'), 'foo') # Actual BOM ignored, so causes a SyntaxError self.assertRaises(SyntaxError, eval, - self.bom.decode('iso-8859-1') + '"foo"') + BOM_UTF8.decode('iso-8859-1') + '"foo"') def test_parse_str_eval(self): foo = 'föö' for code in ("'%s'" % foo.decode('utf-8'), "# coding: utf-8\n'%s'" % foo, - "%s'%s'" % (self.bom, foo)): + "%s'%s'" % (BOM_UTF8, foo)): mod = compile(code, 'foo.py', 'eval') bar = eval(mod) self.assertEqual(foo, bar) @@ -146,7 +145,7 @@ foo = 'föö' for code in ("a = '%s'" % foo.decode('utf-8'), "# coding: utf-8\na = '%s'" % foo, - "%sa = '%s'" % (self.bom, foo)): + "%sa = '%s'" % (BOM_UTF8, foo)): ns = {} exec code in ns self.assertEqual(foo, ns['a']) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-07 08:20:28
|
Revision: 5555 http://jython.svn.sourceforge.net/jython/?rev=5555&view=rev Author: pjenvey Date: 2008-11-07 08:20:22 +0000 (Fri, 07 Nov 2008) Log Message: ----------- add a simple unicodeobject::PyUnicode_EncodeDecimal equivalent for unicode number conversion. fixes test_unicode.test_codecs_errors Modified Paths: -------------- trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/src/org/python/core/PyUnicode.java Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2008-11-07 05:27:30 UTC (rev 5554) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-11-07 08:20:22 UTC (rev 5555) @@ -50,7 +50,15 @@ self.assertEqual(ord(bar[2]), 92) self.assertEqual(ord(bar[3]), 110) + def test_encode_decimal(self): + self.assertEqual(int(u'\u0039\u0032'), 92) + self.assertEqual(int(u'\u0660'), 0) + self.assertEqual(int(u' \u001F\u0966\u096F\u0039'), 99) + self.assertEqual(long(u'\u0663'), 3) + self.assertEqual(float(u'\u0663.\u0661'), 3.1) + self.assertEqual(complex(u'\u0663.\u0661'), 3.1+0j) + def test_main(): test_support.run_unittest(UnicodeTestCase) Modified: trunk/jython/src/org/python/core/PyUnicode.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicode.java 2008-11-07 05:27:30 UTC (rev 5554) +++ trunk/jython/src/org/python/core/PyUnicode.java 2008-11-07 08:20:22 UTC (rev 5555) @@ -1311,6 +1311,93 @@ return newSubsequenceIterator(); } + @Override + public PyComplex __complex__() { + return new PyString(encodeDecimal()).__complex__(); + } + + @Override + public int atoi(int base) { + return new PyString(encodeDecimal()).atoi(base); + } + + @Override + public PyLong atol(int base) { + return new PyString(encodeDecimal()).atol(base); + } + + @Override + public double atof() { + return new PyString(encodeDecimal()).atof(); + } + + /** + * Encode unicode into a valid decimal String. Throws a UnicodeEncodeError on invalid + * characters. + * + * @return a valid decimal as an encoded String + */ + private String encodeDecimal() { + if (isBasicPlane()) { + return encodeDecimalBasic(); + } + + int digit; + StringBuilder sb = new StringBuilder(); + int i = 0; + for (Iterator<Integer> iter = newSubsequenceIterator(); iter.hasNext(); i++) { + int codePoint = iter.next(); + if (Character.isWhitespace(codePoint)) { + sb.append(' '); + continue; + } + digit = Character.digit(codePoint, 10); + if (digit >= 0) { + sb.append(digit); + continue; + } + if (0 < codePoint && codePoint < 256) { + sb.appendCodePoint(codePoint); + continue; + } + // All other characters are considered unencodable + codecs.encoding_error("strict", "decimal", string, i, i + 1, + "invalid decimal Unicode string"); + } + return sb.toString(); + } + + /** + * Encode unicode in the basic plane into a valid decimal String. Throws a + * UnicodeEncodeError on invalid characters. + * + * @return a valid decimal as an encoded String + */ + private String encodeDecimalBasic() { + int digit; + StringBuilder sb = new StringBuilder(); + for (int i = 0; i < string.length(); i++) { + char ch = string.charAt(i); + if (Character.isWhitespace(ch)) { + sb.append(' '); + continue; + } + digit = Character.digit(ch, 10); + if (digit >= 0) { + sb.append(digit); + continue; + } + if (0 < ch && ch < 256) { + sb.append(ch); + continue; + } + // All other characters are considered unencodable + codecs.encoding_error("strict", "decimal", string, i, i + 1, + "invalid decimal Unicode string"); + } + return sb.toString(); + } + @ExposedMethod final String unicode_toString() { return toString(); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-07 05:27:34
|
Revision: 5554 http://jython.svn.sourceforge.net/jython/?rev=5554&view=rev Author: pjenvey Date: 2008-11-07 05:27:30 +0000 (Fri, 07 Nov 2008) Log Message: ----------- clarify comments Modified Paths: -------------- trunk/jython/src/org/python/antlr/GrammarActions.java Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2008-11-07 01:48:27 UTC (rev 5553) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2008-11-07 05:27:30 UTC (rev 5554) @@ -437,7 +437,9 @@ String string = t.getText(); char quoteChar = string.charAt(0); int start = 0; + int end; boolean ustring = false; + if (quoteChar == 'u' || quoteChar == 'U') { ustring = true; start++; @@ -456,28 +458,27 @@ quotes = 1; } + start = quotes + start; + end = string.length() - quotes; // string is properly decoded according to the source encoding - String result; - int end = string.length() - quotes; - start = quotes + start; // XXX: No need to re-encode when the encoding is iso-8859-1, but ParserFacade // needs to normalize the encoding name if (!ustring && encoding != null) { - // Plain strs with a specified encoding: First re-encode them back out - result = new PyUnicode(string.substring(start, end)).encode(encoding); + // str with a specified encoding: first re-encode back out + string = new PyUnicode(string.substring(start, end)).encode(encoding); if (!raw) { // Handle escapes in non-raw strs - result = PyString.decode_UnicodeEscape(result, 0, result.length(), "strict", + string = PyString.decode_UnicodeEscape(string, 0, string.length(), "strict", ustring); } } else if (raw) { - // Raw str/unicode without an encoding (ascii): simply passthru - result = string.substring(start, end); + // Raw str without an encoding or raw unicode: simply passthru + string = string.substring(start, end); } else { // Plain unicode: already decoded, just handle escapes - result = PyString.decode_UnicodeEscape(string, start, end, "strict", ustring); + string = PyString.decode_UnicodeEscape(string, start, end, "strict", ustring); } - return new StringPair(result, ustring); + return new StringPair(string, ustring); } Token extractStringToken(List s) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-07 01:48:32
|
Revision: 5553 http://jython.svn.sourceforge.net/jython/?rev=5553&view=rev Author: pjenvey Date: 2008-11-07 01:48:27 +0000 (Fri, 07 Nov 2008) Log Message: ----------- fix prefix/exec_prefix/copyright being unicode Modified Paths: -------------- trunk/jython/src/org/python/core/PySystemState.java Modified: trunk/jython/src/org/python/core/PySystemState.java =================================================================== --- trunk/jython/src/org/python/core/PySystemState.java 2008-11-07 01:15:50 UTC (rev 5552) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-11-07 01:48:27 UTC (rev 5553) @@ -3,10 +3,7 @@ import java.io.File; import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.FilterInputStream; import java.io.IOException; -import java.io.InputStream; import java.net.URL; import java.net.URLDecoder; import java.security.AccessControlException; @@ -56,7 +53,7 @@ * The copyright notice for this release. */ // TBD: should we use \u00a9 Unicode c-inside-circle? - public static String copyright = + public static PyObject copyright = Py.newString( "Copyright (c) 2000-2008, Jython Developers\n" + "All rights reserved.\n\n" + @@ -72,7 +69,7 @@ "Copyright (c) 1991-1995 Stichting Mathematisch Centrum, " + "Amsterdam.\n" + - "All Rights Reserved.\n\n"; + "All Rights Reserved.\n\n"); private static Hashtable builtinNames; public static PyTuple builtin_module_names = null; @@ -85,8 +82,8 @@ private static PyObject defaultExecutable; public static Properties registry; // = init_registry(); - public static String prefix; - public static String exec_prefix=""; + public static PyObject prefix; + public static PyObject exec_prefix = Py.EmptyString; private static boolean initialized = false; @@ -446,7 +443,8 @@ } registry = preProperties; - prefix = exec_prefix = findRoot(preProperties, postProperties, jarFileName); + String prefix = findRoot(preProperties, postProperties, jarFileName); + String exec_prefix = prefix; // Load the default registry if (prefix != null) { @@ -461,14 +459,17 @@ } catch (Exception exc) { } } - try { - String jythonpath = System.getenv("JYTHONPATH"); - if (jythonpath != null) - registry.setProperty("python.path", jythonpath); - } catch (SecurityException e) { - } + PySystemState.prefix = Py.newString(prefix); + PySystemState.exec_prefix = Py.newString(exec_prefix); + try { + String jythonpath = System.getenv("JYTHONPATH"); + if (jythonpath != null) { + registry.setProperty("python.path", jythonpath); + } + } catch (SecurityException e) { + } if (postProperties != null) { - registry.putAll(postProperties); + registry.putAll(postProperties); } if (standalone) { // set default standalone property (if not yet set) @@ -625,7 +626,7 @@ } cachedir = new File(props.getProperty(PYTHON_CACHEDIR, CACHEDIR_DEFAULT_NAME)); if (!cachedir.isAbsolute()) { - cachedir = new File(PySystemState.prefix, cachedir.getPath()); + cachedir = new File(prefix.toString(), cachedir.getPath()); } } @@ -727,7 +728,7 @@ PyList path = new PyList(); addPaths(path, props.getProperty("python.path", "")); if (prefix != null) { - String libpath = new File(prefix, "Lib").toString(); + String libpath = new File(prefix.toString(), "Lib").toString(); path.append(new PyString(libpath)); } if (standalone) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-07 01:16:00
|
Revision: 5552 http://jython.svn.sourceforge.net/jython/?rev=5552&view=rev Author: pjenvey Date: 2008-11-07 01:15:50 +0000 (Fri, 07 Nov 2008) Log Message: ----------- unused imports, some coding standards Modified Paths: -------------- trunk/jython/src/org/python/antlr/BaseParser.java trunk/jython/src/org/python/antlr/ExpressionParser.java trunk/jython/src/org/python/antlr/FailFastHandler.java trunk/jython/src/org/python/antlr/InteractiveParser.java trunk/jython/src/org/python/antlr/ModuleParser.java trunk/jython/src/org/python/antlr/PythonTree.java trunk/jython/src/org/python/core/ParserFacade.java Modified: trunk/jython/src/org/python/antlr/BaseParser.java =================================================================== --- trunk/jython/src/org/python/antlr/BaseParser.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/antlr/BaseParser.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -1,31 +1,10 @@ package org.python.antlr; import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonToken; -import org.antlr.runtime.CommonTokenStream; -import org.antlr.runtime.RecognitionException; import org.antlr.runtime.Token; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.CommonTreeAdaptor; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.antlr.runtime.tree.TreeAdaptor; -import org.python.antlr.ast.modType; -import org.python.antlr.ast.Module; -import org.python.antlr.ast.stmtType; public class BaseParser { - public static class PyLexer extends PythonLexer { - public PyLexer(CharStream lexer) { - super(lexer); - } - public Token nextToken() { - startPos = getCharPositionInLine(); - return super.nextToken(); - } - } - protected CharStream charStream; protected boolean partial; protected String filename; @@ -35,4 +14,15 @@ public void setAntlrErrorHandler(ErrorHandler eh) { this.errorHandler = eh; } + + public static class PyLexer extends PythonLexer { + public PyLexer(CharStream lexer) { + super(lexer); + } + + public Token nextToken() { + startPos = getCharPositionInLine(); + return super.nextToken(); + } + } } Modified: trunk/jython/src/org/python/antlr/ExpressionParser.java =================================================================== --- trunk/jython/src/org/python/antlr/ExpressionParser.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/antlr/ExpressionParser.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -1,18 +1,9 @@ package org.python.antlr; import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonToken; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.Token; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.CommonTreeAdaptor; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.antlr.runtime.tree.TreeAdaptor; import org.python.antlr.ast.modType; -import org.python.antlr.ast.Module; -import org.python.antlr.ast.stmtType; public class ExpressionParser extends BaseParser { Modified: trunk/jython/src/org/python/antlr/FailFastHandler.java =================================================================== --- trunk/jython/src/org/python/antlr/FailFastHandler.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/antlr/FailFastHandler.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -6,11 +6,7 @@ import org.antlr.runtime.Lexer; import org.antlr.runtime.MismatchedTokenException; import org.antlr.runtime.RecognitionException; -import org.python.antlr.ast.ErrorMod; import org.python.antlr.ast.exprType; -import org.python.antlr.ast.ErrorExpr; -import org.python.antlr.ast.ErrorSlice; -import org.python.antlr.ast.ErrorStmt; import org.python.antlr.ast.modType; import org.python.antlr.ast.sliceType; import org.python.antlr.ast.stmtType; Modified: trunk/jython/src/org/python/antlr/InteractiveParser.java =================================================================== --- trunk/jython/src/org/python/antlr/InteractiveParser.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/antlr/InteractiveParser.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -3,19 +3,9 @@ import java.io.BufferedReader; import java.io.IOException; -import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonToken; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.Token; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.CommonTreeAdaptor; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.antlr.runtime.tree.TreeAdaptor; import org.python.antlr.ast.modType; -import org.python.antlr.ast.Module; -import org.python.antlr.ast.stmtType; public class InteractiveParser extends BaseParser { Modified: trunk/jython/src/org/python/antlr/ModuleParser.java =================================================================== --- trunk/jython/src/org/python/antlr/ModuleParser.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/antlr/ModuleParser.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -1,18 +1,9 @@ package org.python.antlr; import org.antlr.runtime.CharStream; -import org.antlr.runtime.CommonToken; import org.antlr.runtime.CommonTokenStream; import org.antlr.runtime.RecognitionException; -import org.antlr.runtime.Token; -import org.antlr.runtime.tree.CommonTree; -import org.antlr.runtime.tree.CommonTreeAdaptor; -import org.antlr.runtime.tree.CommonTreeNodeStream; -import org.antlr.runtime.tree.Tree; -import org.antlr.runtime.tree.TreeAdaptor; import org.python.antlr.ast.modType; -import org.python.antlr.ast.Module; -import org.python.antlr.ast.stmtType; public class ModuleParser extends BaseParser { public ModuleParser(CharStream cs, String filename, String encoding) { Modified: trunk/jython/src/org/python/antlr/PythonTree.java =================================================================== --- trunk/jython/src/org/python/antlr/PythonTree.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/antlr/PythonTree.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -5,9 +5,6 @@ import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; -import java.io.DataOutputStream; -import java.io.IOException; - import org.python.antlr.ast.VisitorIF; public class PythonTree extends BaseTree implements AST { Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2008-11-07 01:04:00 UTC (rev 5551) +++ trunk/jython/src/org/python/core/ParserFacade.java 2008-11-07 01:15:50 UTC (rev 5552) @@ -12,7 +12,6 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.antlr.runtime.ANTLRReaderStream; import org.antlr.runtime.CharStream; import org.antlr.runtime.CommonTokenStream; @@ -22,9 +21,7 @@ import org.python.antlr.ParseException; import org.python.antlr.ModuleParser; import org.python.antlr.NoCloseReaderStream; -import org.python.antlr.PythonParser; import org.python.antlr.PythonTree; -import org.python.antlr.PythonTree; import org.python.antlr.PythonLexer; import org.python.antlr.PythonPartial; import org.python.antlr.PythonTokenSource; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-11-07 01:04:04
|
Revision: 5551 http://jython.svn.sourceforge.net/jython/?rev=5551&view=rev Author: pjenvey Date: 2008-11-07 01:04:00 +0000 (Fri, 07 Nov 2008) Log Message: ----------- o make the parser aware of the source encoding to fix str handling when encodings are specified. fixes test_doctest o distinguish unicode source w/ PyCF_SOURCE_IS_UTF8 instead of the Py.compile_flags byte[] variant. refactor __builtin__.compile o simplify ParserFacade by re-encoding unicode input; avoids the two prepBufReader code paths for InputStreams vs Readers. less efficient but CPython does this anyway Modified Paths: -------------- trunk/jython/Lib/test/test_builtin_jy.py trunk/jython/Lib/test/test_str_jy.py trunk/jython/Lib/test/test_unicode_jy.py trunk/jython/grammar/Python.g trunk/jython/src/org/python/antlr/BaseParser.java trunk/jython/src/org/python/antlr/ExpressionParser.java trunk/jython/src/org/python/antlr/GrammarActions.java trunk/jython/src/org/python/antlr/InteractiveParser.java trunk/jython/src/org/python/antlr/ModuleParser.java trunk/jython/src/org/python/core/ParserFacade.java trunk/jython/src/org/python/core/Py.java trunk/jython/src/org/python/core/__builtin__.java Modified: trunk/jython/Lib/test/test_builtin_jy.py =================================================================== --- trunk/jython/Lib/test/test_builtin_jy.py 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/Lib/test/test_builtin_jy.py 2008-11-07 01:04:00 UTC (rev 5551) @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- import sys import unittest import test.test_support @@ -120,6 +121,36 @@ def test_round_non_float(self): self.assertEqual(round(self.Foo(), 1), 3.1) +class ExecEvalTest(unittest.TestCase): + + bom = '\xef\xbb\xbf' + + def test_eval_bom(self): + self.assertEqual(eval(self.bom + '"foo"'), 'foo') + # Actual BOM ignored, so causes a SyntaxError + self.assertRaises(SyntaxError, eval, + self.bom.decode('iso-8859-1') + '"foo"') + + def test_parse_str_eval(self): + foo = 'föö' + for code in ("'%s'" % foo.decode('utf-8'), + "# coding: utf-8\n'%s'" % foo, + "%s'%s'" % (self.bom, foo)): + mod = compile(code, 'foo.py', 'eval') + bar = eval(mod) + self.assertEqual(foo, bar) + bar = eval(code) + self.assertEqual(foo, bar) + + def test_parse_str_exec(self): + foo = 'föö' + for code in ("a = '%s'" % foo.decode('utf-8'), + "# coding: utf-8\na = '%s'" % foo, + "%sa = '%s'" % (self.bom, foo)): + ns = {} + exec code in ns + self.assertEqual(foo, ns['a']) + def test_main(): test.test_support.run_unittest(BuiltinTest, LoopTest, @@ -129,7 +160,8 @@ ReturnTest, ReprTest, CallableTest, - ConversionTest) + ConversionTest, + ExecEvalTest) if __name__ == "__main__": test_main() Modified: trunk/jython/Lib/test/test_str_jy.py =================================================================== --- trunk/jython/Lib/test/test_str_jy.py 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/Lib/test/test_str_jy.py 2008-11-07 01:04:00 UTC (rev 5551) @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- from test import test_support import unittest @@ -130,12 +131,47 @@ self.assertEqual(repr(test2), '"\'bar"') self.assertEqual(repr(unicode(test2)), 'u"\'bar"') + +class ParserTest(unittest.TestCase): + + def test_parse_str(self): + foo = 'ą\n' + self.assertEqual(len(foo), 3, repr(foo)) + self.assertEqual(repr(foo), "'\\xc4\\x85\\n'") + self.assertEqual(ord(foo[0]), 196) + self.assertEqual(ord(foo[1]), 133) + self.assertEqual(ord(foo[2]), 10) + + bar = foo.decode('utf-8') + self.assertEqual(len(bar), 2) + self.assertEqual(repr(bar), "u'\\u0105\\n'") + self.assertEqual(ord(bar[0]), 261) + self.assertEqual(ord(bar[1]), 10) + + def test_parse_raw_str(self): + foo = r'ą\n' + self.assertEqual(len(foo), 4, repr(foo)) + self.assertEqual(repr(foo), "'\\xc4\\x85\\\\n'") + self.assertEqual(ord(foo[0]), 196) + self.assertEqual(ord(foo[1]), 133) + self.assertEqual(ord(foo[2]), 92) + self.assertEqual(ord(foo[3]), 110) + + bar = foo.decode('utf-8') + self.assertEqual(len(bar), 3) + self.assertEqual(repr(bar), "u'\\u0105\\\\n'") + self.assertEqual(ord(bar[0]), 261) + self.assertEqual(ord(bar[1]), 92) + self.assertEqual(ord(bar[2]), 110) + def test_main(): - test_support.run_unittest(WrappedStrCmpTest, + test_support.run_unittest( + WrappedStrCmpTest, IntToStrTest, StringSlicingTest, FormatTest, - DisplayTest) + DisplayTest, + ParserTest) if __name__ == '__main__': test_main() Modified: trunk/jython/Lib/test/test_unicode_jy.py =================================================================== --- trunk/jython/Lib/test/test_unicode_jy.py 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/Lib/test/test_unicode_jy.py 2008-11-07 01:04:00 UTC (rev 5551) @@ -1,3 +1,4 @@ +# -*- coding: utf-8 -*- """Misc unicode tests Made for Jython. @@ -19,7 +20,37 @@ self.assertEqual(chunker.match(quoted1, 1).groups(), (orig, u'"')) self.assertEqual(chunker.match(quoted2, 1).groups(), (orig, u'"')) + def test_parse_unicode(self): + foo = u'ą\n' + self.assertEqual(len(foo), 2, repr(foo)) + self.assertEqual(repr(foo), "u'\\u0105\\n'") + self.assertEqual(ord(foo[0]), 261) + self.assertEqual(ord(foo[1]), 10) + bar = foo.encode('utf-8') + self.assertEqual(len(bar), 3) + self.assertEqual(repr(bar), "'\\xc4\\x85\\n'") + self.assertEqual(ord(bar[0]), 196) + self.assertEqual(ord(bar[1]), 133) + self.assertEqual(ord(bar[2]), 10) + + def test_parse_raw_unicode(self): + foo = ur'ą\n' + self.assertEqual(len(foo), 3, repr(foo)) + self.assertEqual(repr(foo), "u'\\u0105\\\\n'") + self.assertEqual(ord(foo[0]), 261) + self.assertEqual(ord(foo[1]), 92) + self.assertEqual(ord(foo[2]), 110) + + bar = foo.encode('utf-8') + self.assertEqual(len(bar), 4) + self.assertEqual(repr(bar), "'\\xc4\\x85\\\\n'") + self.assertEqual(ord(bar[0]), 196) + self.assertEqual(ord(bar[1]), 133) + self.assertEqual(ord(bar[2]), 92) + self.assertEqual(ord(bar[3]), 110) + + def test_main(): test_support.run_unittest(UnicodeTestCase) Modified: trunk/jython/grammar/Python.g =================================================================== --- trunk/jython/grammar/Python.g 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/grammar/Python.g 2008-11-07 01:04:00 UTC (rev 5551) @@ -159,6 +159,8 @@ private GrammarActions actions = new GrammarActions(); + private String encoding; + public void setErrorHandler(ErrorHandler eh) { this.errorHandler = eh; actions.setErrorHandler(eh); @@ -180,6 +182,11 @@ return super.recoverFromMismatchedToken(input, ttype, follow); } + public PythonParser(TokenStream input, String encoding) { + this(input); + this.encoding = encoding; + } + } @rulecatch { @@ -1235,7 +1242,7 @@ | COMPLEX -> ^(COMPLEX<Num>[$COMPLEX, actions.makeComplex($COMPLEX)]) | (S+=STRING)+ - -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S)]) + -> ^(STRING<Str>[actions.extractStringToken($S), actions.extractStrings($S, encoding)]) ; //listmaker: test ( list_for | (',' test)* [','] ) Modified: trunk/jython/src/org/python/antlr/BaseParser.java =================================================================== --- trunk/jython/src/org/python/antlr/BaseParser.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/antlr/BaseParser.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -29,6 +29,7 @@ protected CharStream charStream; protected boolean partial; protected String filename; + protected String encoding; protected ErrorHandler errorHandler = new FailFastHandler(); public void setAntlrErrorHandler(ErrorHandler eh) { Modified: trunk/jython/src/org/python/antlr/ExpressionParser.java =================================================================== --- trunk/jython/src/org/python/antlr/ExpressionParser.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/antlr/ExpressionParser.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -16,9 +16,10 @@ public class ExpressionParser extends BaseParser { - public ExpressionParser(CharStream cs, String filename) { + public ExpressionParser(CharStream cs, String filename, String encoding) { this.charStream = cs; this.filename = filename; + this.encoding = encoding; } public modType parse() { @@ -28,7 +29,7 @@ CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); - PythonParser parser = new PythonParser(tokens); + PythonParser parser = new PythonParser(tokens, encoding); parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); Modified: trunk/jython/src/org/python/antlr/GrammarActions.java =================================================================== --- trunk/jython/src/org/python/antlr/GrammarActions.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/antlr/GrammarActions.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -414,14 +414,14 @@ } } - PyString extractStrings(List s) { + PyString extractStrings(List s, String encoding) { boolean ustring = false; Token last = null; StringBuffer sb = new StringBuffer(); Iterator iter = s.iterator(); while (iter.hasNext()) { last = (Token)iter.next(); - StringPair sp = extractString(last); + StringPair sp = extractString(last, encoding); if (sp.isUnicode()) { ustring = true; } @@ -433,40 +433,51 @@ return new PyString(sb.toString()); } - StringPair extractString(Token t) { - String s = t.getText(); - char quoteChar = s.charAt(0); - int start=0; + StringPair extractString(Token t, String encoding) { + String string = t.getText(); + char quoteChar = string.charAt(0); + int start = 0; boolean ustring = false; if (quoteChar == 'u' || quoteChar == 'U') { ustring = true; start++; } - quoteChar = s.charAt(start); + quoteChar = string.charAt(start); boolean raw = false; if (quoteChar == 'r' || quoteChar == 'R') { raw = true; start++; } int quotes = 3; - if (s.length() - start == 2) { + if (string.length() - start == 2) { quotes = 1; } - if (s.charAt(start) != s.charAt(start+1)) { + if (string.charAt(start) != string.charAt(start+1)) { quotes = 1; } - if (raw) { - return new StringPair(s.substring(quotes+start, s.length()-quotes), ustring); + // string is properly decoded according to the source encoding + String result; + int end = string.length() - quotes; + start = quotes + start; + // XXX: No need to re-encode when the encoding is iso-8859-1, but ParserFacade + // needs to normalize the encoding name + if (!ustring && encoding != null) { + // Plain strs with a specified encoding: First re-encode them back out + result = new PyUnicode(string.substring(start, end)).encode(encoding); + if (!raw) { + // Handle escapes in non-raw strs + result = PyString.decode_UnicodeEscape(result, 0, result.length(), "strict", + ustring); + } + } else if (raw) { + // Raw str/unicode without an encoding (ascii): simply passthru + result = string.substring(start, end); } else { - StringBuffer sb = new StringBuffer(s.length()); - char[] ca = s.toCharArray(); - int n = ca.length-quotes; - int i=quotes+start; - int last_i=i; - return new StringPair(PyString.decode_UnicodeEscape(s, i, n, "strict", ustring), ustring); - //return decode_UnicodeEscape(s, i, n, "strict", ustring); + // Plain unicode: already decoded, just handle escapes + result = PyString.decode_UnicodeEscape(string, start, end, "strict", ustring); } + return new StringPair(result, ustring); } Token extractStringToken(List s) { Modified: trunk/jython/src/org/python/antlr/InteractiveParser.java =================================================================== --- trunk/jython/src/org/python/antlr/InteractiveParser.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/antlr/InteractiveParser.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -21,9 +21,10 @@ private BufferedReader bufreader; - public InteractiveParser(BufferedReader br, String filename) { + public InteractiveParser(BufferedReader br, String filename, String encoding) { this.bufreader = br; this.filename = filename; + this.encoding = encoding; } public modType parse() throws IOException { @@ -33,7 +34,7 @@ CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename, true); tokens = new CommonTokenStream(indentedSource); - PythonParser parser = new PythonParser(tokens); + PythonParser parser = new PythonParser(tokens, encoding); parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); Modified: trunk/jython/src/org/python/antlr/ModuleParser.java =================================================================== --- trunk/jython/src/org/python/antlr/ModuleParser.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/antlr/ModuleParser.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -15,14 +15,15 @@ import org.python.antlr.ast.stmtType; public class ModuleParser extends BaseParser { - public ModuleParser(CharStream cs, String filename) { - this(cs, filename, false); + public ModuleParser(CharStream cs, String filename, String encoding) { + this(cs, filename, encoding, false); } - public ModuleParser(CharStream cs, String filename, boolean partial) { - this.partial = partial; + public ModuleParser(CharStream cs, String filename, String encoding, boolean partial) { this.charStream = cs; this.filename = filename; + this.encoding = encoding; + this.partial = partial; } public modType file_input() { @@ -32,7 +33,7 @@ CommonTokenStream tokens = new CommonTokenStream(lexer); PythonTokenSource indentedSource = new PythonTokenSource(tokens, filename); tokens = new CommonTokenStream(indentedSource); - PythonParser parser = new PythonParser(tokens); + PythonParser parser = new PythonParser(tokens, encoding); parser.setErrorHandler(errorHandler); parser.setTreeAdaptor(new PythonTreeAdaptor()); try { Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/core/ParserFacade.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -7,9 +7,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; -import java.io.LineNumberReader; import java.io.Reader; -import java.io.StringReader; import java.io.UnsupportedEncodingException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -34,11 +32,11 @@ import org.python.core.io.StreamIO; import org.python.core.io.TextIOInputStream; import org.python.core.io.UniversalIOWrapper; +import org.python.core.util.StringUtil; /** * Facade for the classes in the org.python.antlr package. */ - public class ParserFacade { private static int MARK_LIMIT = 100000; @@ -107,14 +105,14 @@ // validPartialSentence if (kind.equals("eval")) { CharStream cs = new NoCloseReaderStream(reader); - ExpressionParser e = new ExpressionParser(cs, filename); + ExpressionParser e = new ExpressionParser(cs, filename, cflags.encoding); return e.parse(); } else if (kind.equals("single")) { - InteractiveParser i = new InteractiveParser(reader, filename); + InteractiveParser i = new InteractiveParser(reader, filename, cflags.encoding); return i.parse(); } else if (kind.equals("exec")) { CharStream cs = new NoCloseReaderStream(reader); - ModuleParser g = new ModuleParser(cs, filename); + ModuleParser g = new ModuleParser(cs, filename, cflags.encoding); return g.file_input(); } else { throw Py.ValueError("parse kind must be eval, exec, or single"); @@ -129,7 +127,7 @@ try { // prepBufReader takes care of encoding detection and universal // newlines: - bufReader = prepBufreader(stream, cflags, filename); + bufReader = prepBufReader(stream, cflags, filename); return parse(bufReader, kind, filename, cflags ); } catch (Throwable t) { throw fixParseError(bufReader, t, filename); @@ -144,7 +142,7 @@ CompilerFlags cflags) { BufferedReader bufReader = null; try { - bufReader = prepBufReader(string); + bufReader = prepBufReader(string, cflags, filename); return parse(bufReader, kind, filename, cflags); } catch (Throwable t) { throw fixParseError(bufReader, t, filename); @@ -161,7 +159,7 @@ // XXX: What's the idea of the stdprompt argument? BufferedReader reader = null; try { - reader = prepBufReader(string); + reader = prepBufReader(string, cflags, filename); return parse(reader, kind, filename, cflags); } catch (Throwable t) { PyException p = fixParseError(reader, t, filename); @@ -194,75 +192,62 @@ } } catch (Exception e) { - System.out.println(e); return lexer.eofWhileNested; } return true; } - private static BufferedReader prepBufreader(InputStream istream, - CompilerFlags cflags, + private static BufferedReader prepBufReader(InputStream input, CompilerFlags cflags, String filename) throws IOException { - boolean bom = false; - String encoding = null; - InputStream bstream = new BufferedInputStream(istream); - bom = adjustForBOM(bstream); - encoding = readEncoding(bstream); + input = new BufferedInputStream(input); + boolean bom = adjustForBOM(input); + String encoding = readEncoding(input); if (encoding == null) { if (bom) { - encoding = "UTF-8"; + encoding = "utf-8"; } else if (cflags != null && cflags.encoding != null) { encoding = cflags.encoding; } } + if (cflags.source_is_utf8) { + if (encoding != null) { + throw new ParseException("encoding declaration in Unicode string"); + } + encoding = "utf-8"; + } + cflags.encoding = encoding; // Enable universal newlines mode on the input - StreamIO rawIO = new StreamIO(bstream, true); + StreamIO rawIO = new StreamIO(input, true); org.python.core.io.BufferedReader bufferedIO = new org.python.core.io.BufferedReader(rawIO, 0); UniversalIOWrapper textIO = new UniversalIOWrapper(bufferedIO); - bstream = new TextIOInputStream(textIO); + input = new TextIOInputStream(textIO); Reader reader; - if(encoding != null) { - try { - reader = new InputStreamReader(bstream, encoding); - } catch(UnsupportedEncodingException exc) { - throw new PySyntaxError("Encoding '" + encoding + "' isn't supported by this JVM.", 0, 0, "", filename); - } - } else { - try { - // Default to ISO-8859-1 to get bytes off the input stream since it leaves their values alone. - reader = new InputStreamReader(bstream, "ISO-8859-1"); - } catch(UnsupportedEncodingException e) { - // This JVM is whacked, it doesn't even have iso-8859-1 - throw Py.SystemError("Java couldn't find the ISO-8859-1 encoding"); - } + try { + // Using iso-8859-1 for the raw bytes when no encoding was specified + reader = new InputStreamReader(input, encoding == null ? "iso-8859-1" : encoding); + } catch (UnsupportedEncodingException exc) { + throw new PySyntaxError("Unknown encoding: " + encoding, 1, 0, "", filename); } - - BufferedReader bufreader = new BufferedReader(reader); - return bufreader; + return new BufferedReader(reader); } - private static BufferedReader prepBufReader(String string) throws IOException { - BufferedReader bufReader; - - // LineNumberReader takes care of universal newlines - bufReader = new LineNumberReader(new StringReader(string)); - - // If the input is a decoded string (implied from the String argument - // for prepBufReader), it can't have an encoding declaration. - bufReader.mark(MARK_LIMIT); - if (findEncoding(bufReader) != null) { - throw new ParseException("encoding declaration in Unicode string"); + private static BufferedReader prepBufReader(String string, CompilerFlags cflags, + String filename) throws IOException { + if (cflags.source_is_utf8) { + // Passed unicode, re-encode the String to raw bytes + // NOTE: This could be more efficient if we duplicate + // prepBufReader/adjustForBOM/readEncoding to work on Readers, instead of + // encoding + string = new PyUnicode(string).encode("utf-8"); } - bufReader.reset(); - - return bufReader; + InputStream input = new ByteArrayInputStream(StringUtil.toBytes(string)); + return prepBufReader(input, cflags, filename); } - /** * Check for a BOM mark at the begginning of stream. If there is a BOM * mark, advance the stream passed it. If not, reset() to start at the Modified: trunk/jython/src/org/python/core/Py.java =================================================================== --- trunk/jython/src/org/python/core/Py.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/core/Py.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -1190,6 +1190,7 @@ public static void exec(PyObject o, PyObject globals, PyObject locals) { PyCode code; + int flags = 0; if (o instanceof PyCode) { code = (PyCode) o; if (locals == null && o instanceof PyTableCode && ((PyTableCode) o).hasFreevars()) { @@ -1198,6 +1199,9 @@ } else { String contents = null; if (o instanceof PyString) { + if (o instanceof PyUnicode) { + flags |= PyTableCode.PyCF_SOURCE_IS_UTF8; + } contents = o.toString(); } else if (o instanceof PyFile) { PyFile fp = (PyFile) o; @@ -1210,7 +1214,7 @@ "exec: argument 1 must be string, code or file object"); } code = (PyCode)Py.compile_flags(contents, "<string>", "exec", - Py.getCompilerFlags()); + getCompilerFlags(flags, false)); } Py.runCode(code, locals, globals); } @@ -1683,31 +1687,6 @@ return Py.compile_flags(node, filename, kind, cflags); } - /** - * Compiles python source code coming from bytestrings - */ - public static PyObject compile_flags(byte[] bytes, String filename, - String kind, CompilerFlags cflags) { - for(int i = 0; i < bytes.length; i++) { - if (bytes[i] == 0) { - throw Py.TypeError("compile() expected string without null bytes"); - } - } - byte[] data; - if (cflags != null && cflags.dont_imply_dedent) { - data = new byte[bytes.length + 1]; - System.arraycopy(bytes, 0, data, 0, bytes.length); - data[data.length - 1] = '\n'; - } else { - data = new byte[bytes.length + 2]; - System.arraycopy(bytes, 0, data, 0, bytes.length); - data[data.length - 1] = data[data.length - 2] = '\n'; - } - modType node = ParserFacade.parse(new ByteArrayInputStream(data), kind, - filename, cflags); - return Py.compile_flags(node, filename, kind, cflags); - } - public static PyObject compile_command_flags(String string, String filename, String kind, CompilerFlags cflags, boolean stdprompt) { modType node = ParserFacade.partialParse(string + "\n", kind, filename, Modified: trunk/jython/src/org/python/core/__builtin__.java =================================================================== --- trunk/jython/src/org/python/core/__builtin__.java 2008-11-06 22:37:32 UTC (rev 5550) +++ trunk/jython/src/org/python/core/__builtin__.java 2008-11-07 01:04:00 UTC (rev 5551) @@ -1,8 +1,6 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import java.io.ByteArrayInputStream; -import java.io.InputStream; import java.util.Iterator; import java.util.Map; @@ -264,26 +262,6 @@ public PyObject fancyCall(PyObject[] args) { switch (this.index) { - case 44: - if (args.length > 5) { - throw info.unexpectedCall(args.length, false); - } - int flags = 0; - if (args.length > 3) { - flags = Py.py2int(args[3]); - } - boolean dont_inherit = false; - if (args.length > 4) { - dont_inherit = Py.py2boolean(args[4]); - } - modType ast = py2node(args[0]); - if (ast != null) { - return __builtin__.compile(ast, args[1].toString(), args[2].toString(), flags, dont_inherit); - } - if (args[0] instanceof PyUnicode) { - flags += PyTableCode.PyCF_SOURCE_IS_UTF8; - } - return __builtin__.compile((PyString)args[0], args[1].toString(), args[2].toString(), flags, dont_inherit); case 29: return __builtin__.map(args); case 43: @@ -296,22 +274,6 @@ public PyObject getModule() { return module; } - - /** - * @returns modType if obj is a wrapper around an AST modType else returns - * null - * - * XXX: Reaches into implementation details -- needs to be reviewed if our - * java integration changes. - */ - private static modType py2node(PyObject obj) { - Object node = obj.__tojava__(modType.class); - if (node == Py.NoConversion) { - return null; - } - return (modType)node; - } - } /** @@ -374,7 +336,6 @@ dict.__setitem__("range", new BuiltinFunctions("range", 2, 1, 3)); dict.__setitem__("sum", new BuiltinFunctions("sum", 12, 1, 2)); dict.__setitem__("unichr", new BuiltinFunctions("unichr", 6, 1)); - dict.__setitem__("compile", new BuiltinFunctions("compile", 44, 3, -1)); dict.__setitem__("delattr", new BuiltinFunctions("delattr", 15, 2)); dict.__setitem__("dir", new BuiltinFunctions("dir", 16, 0, 1)); dict.__setitem__("divmod", new BuiltinFunctions("divmod", 17, 2)); @@ -402,6 +363,7 @@ dict.__setitem__("setattr", new BuiltinFunctions("setattr", 39, 3)); dict.__setitem__("vars", new BuiltinFunctions("vars", 41, 0, 1)); dict.__setitem__("zip", new BuiltinFunctions("zip", 43, 0, -1)); + dict.__setitem__("compile", new CompileFunction()); dict.__setitem__("reversed", new BuiltinFunctions("reversed", 45, 1)); dict.__setitem__("__import__", new ImportFunction()); dict.__setitem__("sorted", new SortedFunction()); @@ -475,38 +437,6 @@ throw Py.TypeError("number coercion failed"); } - public static PyObject compile(PyString data, String filename, String kind) { - if (data instanceof PyUnicode) { - return Py.compile_flags(data.toString(), filename, kind, Py.getCompilerFlags()); - } else { - return Py.compile_flags(data.toBytes(), filename, kind, Py.getCompilerFlags()); - } - } - - public static PyObject compile(modType node, String filename, String kind) { - return Py.compile_flags(node, filename, kind, Py.getCompilerFlags()); - } - - public static PyObject compile(PyString data, String filename, String kind, int flags, boolean dont_inherit) { - if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { - throw Py.ValueError("compile(): unrecognised flags"); - } - if (data instanceof PyUnicode) { - return Py.compile_flags(data.toString(), filename, kind, - Py.getCompilerFlags(flags, dont_inherit)); - } else { - return Py.compile_flags(data.toBytes(), filename, kind, - Py.getCompilerFlags(flags, dont_inherit)); - } - } - - public static PyObject compile(modType node, String filename, String kind, int flags, boolean dont_inherit) { - if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { - throw Py.ValueError("compile(): unrecognised flags"); - } - return Py.compile_flags(node, filename, kind, Py.getCompilerFlags(flags, dont_inherit)); - } - public static void delattr(PyObject o, String n) { o.__delattr__(n); } @@ -562,7 +492,7 @@ code = (PyCode) o; } else { if (o instanceof PyString) { - code = (PyCode)compile((PyString)o, "<string>", "eval"); + code = (PyCode)CompileFunction.compile((PyString)o, "<string>", "eval"); } else { throw Py.TypeError("eval: argument 1 must be string or code object"); } @@ -1562,3 +1492,77 @@ return new PyFloat(tmp / multiple); } } + +class CompileFunction extends PyBuiltinFunction { + CompileFunction() { + super("compile", + "compile(source, filename, mode[, flags[, dont_inherit]]) -> code object\n\n" + + "Compile the source string (a Python module, statement or expression)\n" + + "into a code object that can be executed by the exec statement or eval().\n" + + "The filename will be used for run-time error messages.\n" + + "The mode must be 'exec' to compile a module, 'single' to compile a\n" + + "single (interactive) statement, or 'eval' to compile an expression.\n" + + "The flags argument, if present, controls which future statements influence\n" + + "the compilation of the code.\n" + + "The dont_inherit argument, if non-zero, stops the compilation inheriting\n" + + "the effects of any future statements in effect in the code calling\n" + + "compile; if absent or zero these statements do influence the compilation,\n" + + "in addition to any features explicitly specified."); + } + + public PyObject __call__(PyObject args[], String kwds[]) { + ArgParser ap = new ArgParser("compile", args, kwds, + new String[] {"source", "filename", "mode", "flags", + "dont_inherit"}, + 3); + PyObject source = ap.getPyObject(0); + String filename = ap.getString(1); + String mode = ap.getString(2); + int flags = ap.getInt(3, 0); + boolean dont_inherit = ap.getPyObject(4, Py.False).__nonzero__(); + return compile(source, filename, mode, flags, dont_inherit); + } + + public static PyObject compile(PyObject source, String filename, String mode) { + return compile(source, filename, mode, 0, false); + } + + public static PyObject compile(PyObject source, String filename, String mode, int flags, + boolean dont_inherit) { + if ((flags & ~PyTableCode.CO_ALL_FEATURES) != 0) { + throw Py.ValueError("compile(): unrecognised flags"); + } + if (!mode.equals("exec") && !mode.equals("eval") && !mode.equals("single")) { + throw Py.ValueError("compile() arg 3 must be 'exec' or 'eval' or 'single'"); + } + + modType ast = py2node(source); + if (ast != null) { + return Py.compile_flags(ast, filename, mode, Py.getCompilerFlags(flags, dont_inherit)); + } + + if (!(source instanceof PyString)) { + throw Py.TypeError("expected a readable buffer object"); + } + if (source instanceof PyUnicode) { + flags |= PyTableCode.PyCF_SOURCE_IS_UTF8; + } + return Py.compile_flags(((PyString)source).toString(), filename, mode, + Py.getCompilerFlags(flags, dont_inherit)); + } + + /** + * @returns modType if obj is a wrapper around an AST modType else returns + * null + * + * XXX: Reaches into implementation details -- needs to be reviewed if our + * java integration changes. + */ + private static modType py2node(PyObject obj) { + Object node = obj.__tojava__(modType.class); + if (node == Py.NoConversion) { + return null; + } + return (modType)node; + } +} This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-11-06 22:37:35
|
Revision: 5550 http://jython.svn.sourceforge.net/jython/?rev=5550&view=rev Author: otmarhumbel Date: 2008-11-06 22:37:32 +0000 (Thu, 06 Nov 2008) Log Message: ----------- do not use Runtime.exec(String) any more, it turned out to be dangerous on some platforms, use Runtime.exec(String[]) instead Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/ChildProcess.java trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java trunk/installer/test/java/org/python/util/install/ChildProcessTest.java trunk/installer/test/java/org/python/util/install/ChmodTest_Standalone.java Modified: trunk/installer/src/java/org/python/util/install/ChildProcess.java =================================================================== --- trunk/installer/src/java/org/python/util/install/ChildProcess.java 2008-11-06 16:53:15 UTC (rev 5549) +++ trunk/installer/src/java/org/python/util/install/ChildProcess.java 2008-11-06 22:37:32 UTC (rev 5550) @@ -93,14 +93,9 @@ private static final int NOT_SET_EXITVALUE = -9; /** - * The command to be executed - */ - private String _command = null; - - /** * The command as an array of strings */ - private String _commandArray[] = null; + private String _command[] = null; /** * The timeout (in milliseconds) @@ -143,82 +138,44 @@ public ChildProcess() {} /** - * Constructor taking the command as an argument - * - * @param command - * The command to be executed. - */ - public ChildProcess(String command) { - setCommand(command); - } - - /** * Constructor taking a command array as an argument * - * @param commandArray + * @param command * The command to be executed, every token as array element. */ - public ChildProcess(String commandArray[]) { - setCommandArray(commandArray); - } - - /** - * Constructor taking the command and the timeout as an argument - * - * @param command - * The command to be executed. - * @param timeout - * in milliseconds. Special value: <code>INFINITE_TIMEOUT</code> indicates no timeout - * at all. - */ - public ChildProcess(String command, long timeout) { + public ChildProcess(String command[]) { setCommand(command); - setTimeout(timeout); } /** * Constructor taking a command array and the timeout as an argument * - * @param commandArray + * @param command * The command to be executed, every token as array element. * @param timeout * in milliseconds. Special value: <code>INFINITE_TIMEOUT</code> indicates no timeout * at all. */ - public ChildProcess(String commandArray[], long timeout) { - setCommandArray(commandArray); + public ChildProcess(String command[], long timeout) { + setCommand(command); setTimeout(timeout); } /** - * Set the command to be executed + * Set the command array. This will override (but not overwrite) a previously set command */ - public void setCommand(String command) { + public void setCommand(String command[]) { _command = command; } /** - * Get the command to be executed + * Returns the command array */ - public String getCommand() { + public String[] getCommand() { return _command; } /** - * Set the command array. This will override (but not overwrite) a previously set command - */ - public void setCommandArray(String commandArray[]) { - _commandArray = commandArray; - } - - /** - * Returns the command array - */ - public String[] getCommandArray() { - return _commandArray; - } - - /** * Set the timeout (how long should the calling process wait for the child). * * @param timeout @@ -310,11 +267,7 @@ // determine start time _startTime = System.currentTimeMillis(); // start the process - if (getCommandArray() != null) { - _process = Runtime.getRuntime().exec(getCommandArray()); - } else { - _process = Runtime.getRuntime().exec(getCommand()); - } + _process = Runtime.getRuntime().exec(getCommand()); debugCommand(); // handle stdout and stderr StdoutMonitor stdoutMonitor = new StdoutMonitor(); @@ -386,11 +339,11 @@ */ private void debugCommand() { if (isDebug()) { - String[] commandArray = getCommandArray(); - if (commandArray != null) { + String[] command = getCommand(); + if (command != null) { System.out.print("[ChildProcess] command '"); - for (int i = 0; i < commandArray.length; i++) { - String commandPart = commandArray[i]; + for (int i = 0; i < command.length; i++) { + String commandPart = command[i]; if (i == 0) { System.out.print(commandPart); } else { @@ -398,9 +351,6 @@ } } System.out.println("' is now running..."); - } else { - System.out.println("[ChildProcess] command '" + getCommand() - + "' is now running..."); } } } Modified: trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java =================================================================== --- trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java 2008-11-06 16:53:15 UTC (rev 5549) +++ trunk/installer/src/java/org/python/util/install/StartScriptGenerator.java 2008-11-06 22:37:32 UTC (rev 5550) @@ -58,7 +58,7 @@ protected boolean hasUnixlikeShell() { int errorCode = 0; try { - String command = "sh -c env"; + String command[] = new String[] {"sh", "-c", "env"}; long timeout = 3000; ChildProcess childProcess = new ChildProcess(command, timeout); childProcess.setDebug(false); Modified: trunk/installer/test/java/org/python/util/install/ChildProcessTest.java =================================================================== --- trunk/installer/test/java/org/python/util/install/ChildProcessTest.java 2008-11-06 16:53:15 UTC (rev 5549) +++ trunk/installer/test/java/org/python/util/install/ChildProcessTest.java 2008-11-06 22:37:32 UTC (rev 5550) @@ -15,7 +15,7 @@ */ public void testDefault() { ChildProcess childProcess = new ChildProcess(); - String command = buildJavaCommand(CLASS_NAME); + String command[] = buildJavaCommand(CLASS_NAME); childProcess.setCommand(command); childProcess.setDebug(true); int exitValue = childProcess.run(); @@ -27,7 +27,7 @@ */ public void testTimeout() { ChildProcess childProcess = new ChildProcess(); - String command = buildJavaCommand(CLASS_NAME); + String command[] = buildJavaCommand(CLASS_NAME); childProcess.setCommand(command); childProcess.setDebug(true); childProcess.setTimeout(2000); // timeout to 2 seconds @@ -38,23 +38,11 @@ } /** - * test the child process with a command array - */ - public void testCommandArray() { - String command = buildJavaCommand(CLASS_NAME); - String commandArray[] = command.split(" "); - ChildProcess childProcess = new ChildProcess(commandArray); - childProcess.setDebug(true); - int exitValue = childProcess.run(); - assertEquals("Expected child process to end normally instead of " + exitValue, 0, exitValue); - } - - /** * test silent mode */ public void testSilent() throws IOException { ChildProcess childProcess = new ChildProcess(); - String command = "lwiklsl -siwK"; + String command[] = new String[] {"lwiklsl", "-siwK"}; childProcess.setCommand(command); childProcess.setDebug(false); childProcess.setSilent(true); @@ -81,12 +69,12 @@ // // private methods // - private String buildJavaCommand(String classAndArguments) { + private String[] buildJavaCommand(String classAndArguments) { String quote = ""; if (System.getProperty("os.name", "unknown").toLowerCase().indexOf("windows") >= 0) { quote = "\""; } String classpath = System.getProperty("java.class.path"); - return "java -classpath " + quote + classpath + quote + " " + classAndArguments; + return new String[] {"java", "-classpath", quote.concat(classpath).concat(quote), classAndArguments}; } } \ No newline at end of file Modified: trunk/installer/test/java/org/python/util/install/ChmodTest_Standalone.java =================================================================== --- trunk/installer/test/java/org/python/util/install/ChmodTest_Standalone.java 2008-11-06 16:53:15 UTC (rev 5549) +++ trunk/installer/test/java/org/python/util/install/ChmodTest_Standalone.java 2008-11-06 22:37:32 UTC (rev 5550) @@ -37,7 +37,8 @@ System.err.println(getPrefix() + "unable to create file " + path); System.exit(1); } else { - ChildProcess childProcess = new ChildProcess("chmod " + _mode + " " + path, 3000); + String command[] = new String[] {"chmod", _mode, path}; + ChildProcess childProcess = new ChildProcess(command, 3000); childProcess.setDebug(true); int exitValue = childProcess.run(); if (exitValue != 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <otm...@us...> - 2008-11-06 16:53:18
|
Revision: 5549 http://jython.svn.sourceforge.net/jython/?rev=5549&view=rev Author: otmarhumbel Date: 2008-11-06 16:53:15 +0000 (Thu, 06 Nov 2008) Log Message: ----------- added the shell interpreter, this fixes 'UNIXProcess.forkAndExec native error: Exec format error' on RedHat (as reported on http://ant.apache.org/manual/CoreTasks/exec.html) thanks to Reini for helping us out here Modified Paths: -------------- trunk/installer/src/java/org/python/util/install/driver/jython_test.template Modified: trunk/installer/src/java/org/python/util/install/driver/jython_test.template =================================================================== --- trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-06 05:20:01 UTC (rev 5548) +++ trunk/installer/src/java/org/python/util/install/driver/jython_test.template 2008-11-06 16:53:15 UTC (rev 5549) @@ -1,3 +1,5 @@ +#!/usr/bin/env bash + # 3 variables to be set from the caller (unquoted) -> quoted in here: _INSTALL_DIR="{0}" _SCRIPT="{1}" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |