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: <nr...@us...> - 2008-07-18 20:51:02
|
Revision: 4971 http://jython.svn.sourceforge.net/jython/?rev=4971&view=rev Author: nriley Date: 2008-07-18 20:51:00 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Conditionalize launcher test; no need for Cygwin test. Modified Paths: -------------- branches/asm/build.xml Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-07-18 20:40:17 UTC (rev 4970) +++ branches/asm/build.xml 2008-07-18 20:51:00 UTC (rev 4971) @@ -204,12 +204,6 @@ <condition property="os.family.windows"> <os family="windows"/> </condition> - <condition property="os.unix-or-cygwin"> - <or> - <os family="unix"/> - <equals arg1="${OSNAME}" arg2="cygwin"/> - </or> - </condition> </target> <target name="full-preinit"> @@ -732,20 +726,20 @@ </batchtest> </junit> </target> - <target name="launchertest" depends="developer-build"> + <target name="launchertest" depends="developer-build" if="os.family.unix"> <exec executable="${test.shell.dir}/test-jython.sh"> <arg value="${dist.dir}"/> </exec> </target> <target name="regrtest" depends="developer-build,regrtest-unix,regrtest-windows"/> - <target name="regrtest-unix" if="os.unix-or-cygwin"> + <target name="regrtest-unix" if="os.family.unix"> <exec executable="${dist.dir}/bin/jython"> <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> <arg value="--expected"/> </exec> </target> - <target name="regrtest-windows" if="os.windows" unless="os.unix-or-cygwin"> + <target name="regrtest-windows" if="os.family.windows"> <exec executable="${dist.dir}/bin/jython.bat"> <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-18 20:40:19
|
Revision: 4970 http://jython.svn.sourceforge.net/jython/?rev=4970&view=rev Author: nriley Date: 2008-07-18 20:40:17 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Make ant regrtest work on Windows again. Modified Paths: -------------- branches/asm/build.xml Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-07-18 19:21:37 UTC (rev 4969) +++ branches/asm/build.xml 2008-07-18 20:40:17 UTC (rev 4970) @@ -201,6 +201,15 @@ <condition property="os.family.unix"> <os family="unix"/> </condition> + <condition property="os.family.windows"> + <os family="windows"/> + </condition> + <condition property="os.unix-or-cygwin"> + <or> + <os family="unix"/> + <equals arg1="${OSNAME}" arg2="cygwin"/> + </or> + </condition> </target> <target name="full-preinit"> @@ -728,13 +737,21 @@ <arg value="${dist.dir}"/> </exec> </target> - <target name="regrtest" depends="developer-build"> + <target name="regrtest" depends="developer-build,regrtest-unix,regrtest-windows"/> + <target name="regrtest-unix" if="os.unix-or-cygwin"> <exec executable="${dist.dir}/bin/jython"> <arg value="${dist.dir}/Lib/test/regrtest.py"/> <!-- Only run the tests that are expected to work on Jython --> <arg value="--expected"/> </exec> </target> + <target name="regrtest-windows" if="os.windows" unless="os.unix-or-cygwin"> + <exec executable="${dist.dir}/bin/jython.bat"> + <arg value="${dist.dir}/Lib/test/regrtest.py"/> + <!-- Only run the tests that are expected to work on Jython --> + <arg value="--expected"/> + </exec> + </target> <!-- run bugtests, create a config if necessary --> <target name="bugtest" depends="create-bugtest-config"> This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-18 19:21:39
|
Revision: 4969 http://jython.svn.sourceforge.net/jython/?rev=4969&view=rev Author: nriley Date: 2008-07-18 19:21:37 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Actually use JYTHON_OPTS; correct error message and properly delete _JYTHON_HOME. Modified Paths: -------------- branches/asm/src/shell/jython.bat Modified: branches/asm/src/shell/jython.bat =================================================================== --- branches/asm/src/shell/jython.bat 2008-07-18 19:20:39 UTC (rev 4968) +++ branches/asm/src/shell/jython.bat 2008-07-18 19:21:37 UTC (rev 4969) @@ -16,6 +16,11 @@ rem ----- Verify and set required environment variables ----------------------- +set _JAVA_CMD=java +if not "%JAVA_HOME%" == "" ( + set _JAVA_CMD="%JAVA_HOME%\bin\java" +) + set _JYTHON_HOME="%JYTHON_HOME%" if not "%JYTHON_HOME%" == "" goto gotHome pushd "%~dp0%\.." @@ -23,32 +28,31 @@ popd :gotHome -if exist %_JYTHON_HOME%/jython.jar goto homeOK -echo Cannot find jython.jar in %_JYTHON_HOME% -echo Try running this batch file from the 'bin' directory of an installed Jython -echo or setting JYTHON_HOME. -goto cleanup - -:homeOK -set _JAVA_CMD=java -if not "%JAVA_HOME%" == "" ( - set _JAVA_CMD=%JAVA_HOME%\bin\java -) - -set _CP=%_JYTHON_HOME%\jython-complete.jar -if not exist %_JYTHON_HOME%\jython.jar goto run +if not exist %_JYTHON_HOME%\jython.jar goto tryComplete rem prefer built version set _CP=%_JYTHON_HOME%\jython.jar for %%j in (%_JYTHON_HOME%\javalib\*.jar) do ( set _CP=!_CP!;"%%j" ) +goto run +:tryComplete +set _CP=%_JYTHON_HOME%\jython-complete.jar +if exist %_JYTHON_HOME%/jython-complete.jar goto run + +echo Cannot find jython.jar or jython-complete.jar in %_JYTHON_HOME% +echo Try running this batch file from the 'bin' directory of an installed Jython +echo or setting JYTHON_HOME. +goto cleanup + +rem ----- Execute the requested command ---------------------------------------- + :run -%_JAVA_CMD% %JAVA_OPTS% -Xss512k -Xbootclasspath/a:%_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %* +%_JAVA_CMD% %JAVA_OPTS% -Xss512k -Xbootclasspath/a:%_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %JYTHON_OPTS% %* set E=%ERRORLEVEL% :cleanup -set _JYTHON_HOME=%JYTHON_HOME% +set _JYTHON_HOME= set _JAVA_CMD= set _CP= This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-18 19:20:41
|
Revision: 4968 http://jython.svn.sourceforge.net/jython/?rev=4968&view=rev Author: nriley Date: 2008-07-18 19:20:39 +0000 (Fri, 18 Jul 2008) Log Message: ----------- Work with jython-complete.jar; handle spaces in $JAVA_HOME. Modified Paths: -------------- branches/asm/src/shell/jython Modified: branches/asm/src/shell/jython =================================================================== --- branches/asm/src/shell/jython 2008-07-18 00:28:49 UTC (rev 4967) +++ branches/asm/src/shell/jython 2008-07-18 19:20:39 UTC (rev 4968) @@ -34,6 +34,15 @@ fi done +if [ -z "$JAVA_HOME" ] ; then + JAVA_CMD=(java) +else + if $cygwin; then + JAVA_HOME=`cygpath -u "$JAVA_HOME"` + fi + JAVA_CMD=("$JAVA_HOME/bin/java") +fi + if [ -z "$JYTHON_HOME" ] ; then JYTHON_HOME_1=`dirname "$PRG"` # the ./bin dir JYTHON_HOME=`dirname "$JYTHON_HOME_1"` # the . dir @@ -43,35 +52,28 @@ JYTHON_OPTS="" fi -if [ -z "$JAVA_HOME" ] ; then - JAVA_CMD='java' -else - if $cygwin; then - JAVA_HOME=`cygpath -u "$JAVA_HOME"` - fi - JAVA_CMD="$JAVA_HOME/bin/java" -fi - CP_DELIMITER=":" CP=$JYTHON_HOME/jython.jar -if [ ! -f "$CP" ]; then - echo "$0: '$CP' does not exist." >&2 +if [ -f "$CP" ] ; then + # add necessary jars for command-line execution + for j in "$JYTHON_HOME"/javalib/*.jar; do + if [ "$CP" ]; then + CP="$CP$CP_DELIMITER$j" + else + CP="$j" + fi + done +elif [ ! -f "$JYTHON_HOME"/jython-complete.jar ] ; then + echo "$0: $JYTHON_HOME contains neither jython.jar nor jython-complete.jar." >&2 echo "Try running this script from the 'bin' directory of an installed Jython or " >&2 echo 'setting $JYTHON_HOME.' >&2 exit 1 +else + CP=$JYTHON_HOME/jython-complete.jar fi -# add necessary jars for command-line execution -for j in "$JYTHON_HOME"/javalib/*.jar; do - if [ "$CP" ]; then - CP="$CP$CP_DELIMITER$j" - else - CP="$j" - fi -done - if $cygwin; then CP=`cygpath -wp "$CP"` PRG=`cygpath -w "$PRG"` @@ -119,12 +121,12 @@ # Run under JDB --jdb) if [ -z "$JAVA_HOME" ] ; then - JAVA_CMD='jdb' + JAVA_CMD=(jdb) else if $cygwin; then JAVA_HOME=`cygpath -u "$JAVA_HOME"` fi - JAVA_CMD="$JAVA_HOME/bin/jdb" + JAVA_CMD=("$JAVA_HOME/bin/jdb") fi ;; -h|--help) @@ -172,12 +174,12 @@ java_args=("${java_args[@]}" -classpath "$CP$CP_DELIMITER$CLASSPATH") else if [ -z $help_requested ] ; then - JAVA_CMD="exec $JAVA_CMD" + JAVA_CMD=(exec "${JAVA_CMD[@]}") fi java_args=("${java_args[@]}" -Xbootclasspath/a:"$CP" -classpath "$CLASSPATH") fi -$JAVA_CMD $JAVA_OPTS "${java_args[@]}" -Dpython.home="$JYTHON_HOME" \ +"${JAVA_CMD[@]}" $JAVA_OPTS "${java_args[@]}" -Dpython.home="$JYTHON_HOME" \ -Dpython.executable="$PRG" org.python.util.jython $JYTHON_OPTS "$@" if [ -n "$profile_requested" ] ; then This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-18 00:28:53
|
Revision: 4967 http://jython.svn.sourceforge.net/jython/?rev=4967&view=rev Author: pjenvey Date: 2008-07-18 00:28:49 +0000 (Fri, 18 Jul 2008) Log Message: ----------- boost the mark limit even higher for the lenghty lines in pygments.lexers._vimbuiltins Modified Paths: -------------- branches/asm/src/org/python/core/ParserFacade.java Modified: branches/asm/src/org/python/core/ParserFacade.java =================================================================== --- branches/asm/src/org/python/core/ParserFacade.java 2008-07-17 21:25:44 UTC (rev 4966) +++ branches/asm/src/org/python/core/ParserFacade.java 2008-07-18 00:28:49 UTC (rev 4967) @@ -204,7 +204,7 @@ private static String readEncoding(InputStream stream) throws IOException { - stream.mark(10000); + stream.mark(100000); String encoding = null; BufferedReader br = new BufferedReader(new InputStreamReader(stream), 512); for (int i = 0; i < 2; i++) { @@ -218,6 +218,8 @@ break; } } + // XXX: reset() can still raise an IOException if a line exceeds our large mark + // limit stream.reset(); return encodingMap(encoding); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 21:25:49
|
Revision: 4966 http://jython.svn.sourceforge.net/jython/?rev=4966&view=rev Author: pjenvey Date: 2008-07-17 21:25:44 +0000 (Thu, 17 Jul 2008) Log Message: ----------- fix loading of 0L in cPickle proto 2 and match cPickle's dumps(0L, 2) to pickle's Modified Paths: -------------- trunk/jython/src/org/python/modules/cPickle.java Added Paths: ----------- trunk/jython/Lib/test/test_cpickle_jy.py Added: trunk/jython/Lib/test/test_cpickle_jy.py =================================================================== --- trunk/jython/Lib/test/test_cpickle_jy.py (rev 0) +++ trunk/jython/Lib/test/test_cpickle_jy.py 2008-07-17 21:25:44 UTC (rev 4966) @@ -0,0 +1,22 @@ +"""Misc cPickle tests. + +Made for Jython. +""" +import cPickle +import pickle +import unittest +from test import test_support + +class CPickleTestCase(unittest.TestCase): + + def test_zero_long(self): + self.assertEqual(cPickle.loads(cPickle.dumps(0L, 2)), 0L) + self.assertEqual(cPickle.dumps(0L, 2), pickle.dumps(0L, 2)) + + +def test_main(): + test_support.run_unittest(CPickleTestCase) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2008-07-17 21:19:56 UTC (rev 4965) +++ trunk/jython/src/org/python/modules/cPickle.java 2008-07-17 21:25:44 UTC (rev 4966) @@ -1163,9 +1163,17 @@ private void save_long(PyObject object) { if(protocol >= 2) { BigInteger integer = ((PyLong)object).getValue(); + + if (integer.compareTo(BigInteger.ZERO) == 0) { + // It's 0 -- an empty bytestring. + file.write(LONG1); + file.write((char)0); + return; + } + byte[] bytes = integer.toByteArray(); int l = bytes.length; - if(l < 256) { + if (l < 256) { file.write(LONG1); file.write((char)l); } else { @@ -1938,6 +1946,10 @@ private void load_bin_long(int length) { int longLength = read_binint(length); + if (longLength == 0) { + push(new PyLong(BigInteger.ZERO)); + return; + } String s = file.read(longLength); byte[] bytes = new byte[s.length()]; // Write to the byte array in reverse order: pickle orders This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-17 21:20:18
|
Revision: 4965 http://jython.svn.sourceforge.net/jython/?rev=4965&view=rev Author: fwierzbicki Date: 2008-07-17 21:19:56 +0000 (Thu, 17 Jul 2008) Log Message: ----------- added custom toStringTree to each node. Modified Paths: -------------- branches/asm/ast/asdl_antlr.py branches/asm/src/org/python/antlr/ast/Assert.java branches/asm/src/org/python/antlr/ast/Assign.java branches/asm/src/org/python/antlr/ast/Attribute.java branches/asm/src/org/python/antlr/ast/AugAssign.java branches/asm/src/org/python/antlr/ast/BinOp.java branches/asm/src/org/python/antlr/ast/BoolOp.java branches/asm/src/org/python/antlr/ast/Break.java branches/asm/src/org/python/antlr/ast/Call.java branches/asm/src/org/python/antlr/ast/ClassDef.java branches/asm/src/org/python/antlr/ast/Compare.java branches/asm/src/org/python/antlr/ast/Continue.java branches/asm/src/org/python/antlr/ast/Delete.java branches/asm/src/org/python/antlr/ast/Dict.java branches/asm/src/org/python/antlr/ast/Ellipsis.java branches/asm/src/org/python/antlr/ast/Exec.java branches/asm/src/org/python/antlr/ast/Expr.java branches/asm/src/org/python/antlr/ast/Expression.java branches/asm/src/org/python/antlr/ast/ExtSlice.java branches/asm/src/org/python/antlr/ast/For.java branches/asm/src/org/python/antlr/ast/FunctionDef.java branches/asm/src/org/python/antlr/ast/GeneratorExp.java branches/asm/src/org/python/antlr/ast/Global.java branches/asm/src/org/python/antlr/ast/If.java branches/asm/src/org/python/antlr/ast/IfExp.java branches/asm/src/org/python/antlr/ast/Import.java branches/asm/src/org/python/antlr/ast/ImportFrom.java branches/asm/src/org/python/antlr/ast/Index.java branches/asm/src/org/python/antlr/ast/Interactive.java branches/asm/src/org/python/antlr/ast/Lambda.java branches/asm/src/org/python/antlr/ast/List.java branches/asm/src/org/python/antlr/ast/ListComp.java branches/asm/src/org/python/antlr/ast/Module.java branches/asm/src/org/python/antlr/ast/Name.java branches/asm/src/org/python/antlr/ast/Num.java branches/asm/src/org/python/antlr/ast/Pass.java branches/asm/src/org/python/antlr/ast/Print.java branches/asm/src/org/python/antlr/ast/Raise.java branches/asm/src/org/python/antlr/ast/Repr.java branches/asm/src/org/python/antlr/ast/Return.java branches/asm/src/org/python/antlr/ast/Slice.java branches/asm/src/org/python/antlr/ast/Str.java branches/asm/src/org/python/antlr/ast/Subscript.java branches/asm/src/org/python/antlr/ast/Suite.java branches/asm/src/org/python/antlr/ast/TryExcept.java branches/asm/src/org/python/antlr/ast/TryFinally.java branches/asm/src/org/python/antlr/ast/Tuple.java branches/asm/src/org/python/antlr/ast/UnaryOp.java branches/asm/src/org/python/antlr/ast/Unicode.java branches/asm/src/org/python/antlr/ast/While.java branches/asm/src/org/python/antlr/ast/With.java branches/asm/src/org/python/antlr/ast/Yield.java branches/asm/src/org/python/antlr/ast/aliasType.java branches/asm/src/org/python/antlr/ast/argumentsType.java branches/asm/src/org/python/antlr/ast/comprehensionType.java branches/asm/src/org/python/antlr/ast/excepthandlerType.java branches/asm/src/org/python/antlr/ast/keywordType.java Modified: branches/asm/ast/asdl_antlr.py =================================================================== --- branches/asm/ast/asdl_antlr.py 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/ast/asdl_antlr.py 2008-07-17 21:19:56 UTC (rev 4965) @@ -306,6 +306,18 @@ self.emit("}", depth) self.emit("", 0) + # The toStringTree() method + self.emit("public String toStringTree() {", depth) + self.emit('StringBuffer sb = new StringBuffer("%s[");' % clsname, + depth+1) + for f in fields: + self.emit('sb.append("%s=");' % f.name, depth+1) + self.emit("sb.append(this.%s);" % f.name, depth+1) + self.emit('sb.append("]");', depth+1) + self.emit("return sb.toString();", depth+1) + 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); Modified: branches/asm/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "Assert"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Assert["); + sb.append("test="); + sb.append(this.test); + sb.append("msg="); + sb.append(this.msg); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAssert(this); } Modified: branches/asm/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -49,6 +49,16 @@ return "Assign"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Assign["); + sb.append("targets="); + sb.append(this.targets); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAssign(this); } Modified: branches/asm/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Attribute"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Attribute["); + sb.append("value="); + sb.append(this.value); + sb.append("attr="); + sb.append(this.attr); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAttribute(this); } Modified: branches/asm/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "AugAssign"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("AugAssign["); + sb.append("target="); + sb.append(this.target); + sb.append("op="); + sb.append(this.op); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitAugAssign(this); } Modified: branches/asm/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -40,6 +40,18 @@ return "BinOp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("BinOp["); + sb.append("left="); + sb.append(this.left); + sb.append("op="); + sb.append(this.op); + sb.append("right="); + sb.append(this.right); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitBinOp(this); } Modified: branches/asm/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -49,6 +49,16 @@ return "BoolOp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("BoolOp["); + sb.append("op="); + sb.append(this.op); + sb.append("values="); + sb.append(this.values); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitBoolOp(this); } Modified: branches/asm/src/org/python/antlr/ast/Break.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Break.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Break.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Break"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Break["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitBreak(this); } Modified: branches/asm/src/org/python/antlr/ast/Call.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Call.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Call.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -80,6 +80,22 @@ return "Call"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Call["); + sb.append("func="); + sb.append(this.func); + sb.append("args="); + sb.append(this.args); + sb.append("keywords="); + sb.append(this.keywords); + sb.append("starargs="); + sb.append(this.starargs); + sb.append("kwargs="); + sb.append(this.kwargs); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitCall(this); } Modified: branches/asm/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -71,6 +71,18 @@ return "ClassDef"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ClassDef["); + sb.append("name="); + sb.append(this.name); + sb.append("bases="); + sb.append(this.bases); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitClassDef(this); } Modified: branches/asm/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -60,6 +60,18 @@ return "Compare"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Compare["); + sb.append("left="); + sb.append(this.left); + sb.append("ops="); + sb.append(this.ops); + sb.append("comparators="); + sb.append(this.comparators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitCompare(this); } Modified: branches/asm/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Continue"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Continue["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitContinue(this); } Modified: branches/asm/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Delete"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Delete["); + sb.append("targets="); + sb.append(this.targets); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitDelete(this); } Modified: branches/asm/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -64,6 +64,16 @@ return "Dict"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Dict["); + sb.append("keys="); + sb.append(this.keys); + sb.append("values="); + sb.append(this.values); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitDict(this); } Modified: branches/asm/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Ellipsis"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Ellipsis["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitEllipsis(this); } Modified: branches/asm/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Exec"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Exec["); + sb.append("body="); + sb.append(this.body); + sb.append("globals="); + sb.append(this.globals); + sb.append("locals="); + sb.append(this.locals); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExec(this); } Modified: branches/asm/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Expr"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Expr["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExpr(this); } Modified: branches/asm/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Expression"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Expression["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExpression(this); } Modified: branches/asm/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "ExtSlice"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ExtSlice["); + sb.append("dims="); + sb.append(this.dims); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitExtSlice(this); } Modified: branches/asm/src/org/python/antlr/ast/For.java =================================================================== --- branches/asm/src/org/python/antlr/ast/For.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/For.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -76,6 +76,20 @@ return "For"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("For["); + sb.append("target="); + sb.append(this.target); + sb.append("iter="); + sb.append(this.iter); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitFor(this); } Modified: branches/asm/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -76,6 +76,20 @@ return "FunctionDef"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("FunctionDef["); + sb.append("name="); + sb.append(this.name); + sb.append("args="); + sb.append(this.args); + sb.append("body="); + sb.append(this.body); + sb.append("decorators="); + sb.append(this.decorators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitFunctionDef(this); } Modified: branches/asm/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -52,6 +52,16 @@ return "GeneratorExp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("GeneratorExp["); + sb.append("elt="); + sb.append(this.elt); + sb.append("generators="); + sb.append(this.generators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitGeneratorExp(this); } Modified: branches/asm/src/org/python/antlr/ast/Global.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Global.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Global.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Global"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Global["); + sb.append("names="); + sb.append(this.names); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitGlobal(this); } Modified: branches/asm/src/org/python/antlr/ast/If.java =================================================================== --- branches/asm/src/org/python/antlr/ast/If.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/If.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -71,6 +71,18 @@ return "If"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("If["); + sb.append("test="); + sb.append(this.test); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitIf(this); } Modified: branches/asm/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "IfExp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("IfExp["); + sb.append("test="); + sb.append(this.test); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitIfExp(this); } Modified: branches/asm/src/org/python/antlr/ast/Import.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Import.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Import.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Import"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Import["); + sb.append("names="); + sb.append(this.names); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitImport(this); } Modified: branches/asm/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -57,6 +57,18 @@ return "ImportFrom"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ImportFrom["); + sb.append("module="); + sb.append(this.module); + sb.append("names="); + sb.append(this.names); + sb.append("level="); + sb.append(this.level); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitImportFrom(this); } Modified: branches/asm/src/org/python/antlr/ast/Index.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Index.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Index.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Index"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Index["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitIndex(this); } Modified: branches/asm/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Interactive"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Interactive["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitInteractive(this); } Modified: branches/asm/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "Lambda"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Lambda["); + sb.append("args="); + sb.append(this.args); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitLambda(this); } Modified: branches/asm/src/org/python/antlr/ast/List.java =================================================================== --- branches/asm/src/org/python/antlr/ast/List.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/List.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -49,6 +49,16 @@ return "List"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("List["); + sb.append("elts="); + sb.append(this.elts); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitList(this); } Modified: branches/asm/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -51,6 +51,16 @@ return "ListComp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("ListComp["); + sb.append("elt="); + sb.append(this.elt); + sb.append("generators="); + sb.append(this.generators); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitListComp(this); } Modified: branches/asm/src/org/python/antlr/ast/Module.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Module.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Module.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Module"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Module["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitModule(this); } Modified: branches/asm/src/org/python/antlr/ast/Name.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Name.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Name.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "Name"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Name["); + sb.append("id="); + sb.append(this.id); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitName(this); } Modified: branches/asm/src/org/python/antlr/ast/Num.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Num.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Num.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Num"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Num["); + sb.append("n="); + sb.append(this.n); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitNum(this); } Modified: branches/asm/src/org/python/antlr/ast/Pass.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -26,6 +26,12 @@ return "Pass"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Pass["); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitPass(this); } Modified: branches/asm/src/org/python/antlr/ast/Print.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Print.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Print.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -55,6 +55,18 @@ return "Print"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Print["); + sb.append("dest="); + sb.append(this.dest); + sb.append("values="); + sb.append(this.values); + sb.append("nl="); + sb.append(this.nl); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitPrint(this); } Modified: branches/asm/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -40,6 +40,18 @@ return "Raise"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Raise["); + sb.append("type="); + sb.append(this.type); + sb.append("inst="); + sb.append(this.inst); + sb.append("tback="); + sb.append(this.tback); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitRaise(this); } Modified: branches/asm/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Repr"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Repr["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitRepr(this); } Modified: branches/asm/src/org/python/antlr/ast/Return.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Return.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Return.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Return"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Return["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitReturn(this); } Modified: branches/asm/src/org/python/antlr/ast/Slice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Slice"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Slice["); + sb.append("lower="); + sb.append(this.lower); + sb.append("upper="); + sb.append(this.upper); + sb.append("step="); + sb.append(this.step); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitSlice(this); } Modified: branches/asm/src/org/python/antlr/ast/Str.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Str.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Str.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Str"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Str["); + sb.append("s="); + sb.append(this.s); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitStr(this); } Modified: branches/asm/src/org/python/antlr/ast/Subscript.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -41,6 +41,18 @@ return "Subscript"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Subscript["); + sb.append("value="); + sb.append(this.value); + sb.append("slice="); + sb.append(this.slice); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitSubscript(this); } Modified: branches/asm/src/org/python/antlr/ast/Suite.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -45,6 +45,14 @@ return "Suite"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Suite["); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitSuite(this); } Modified: branches/asm/src/org/python/antlr/ast/TryExcept.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -87,6 +87,18 @@ return "TryExcept"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("TryExcept["); + sb.append("body="); + sb.append(this.body); + sb.append("handlers="); + sb.append(this.handlers); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitTryExcept(this); } Modified: branches/asm/src/org/python/antlr/ast/TryFinally.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -65,6 +65,16 @@ return "TryFinally"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("TryFinally["); + sb.append("body="); + sb.append(this.body); + sb.append("finalbody="); + sb.append(this.finalbody); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitTryFinally(this); } Modified: branches/asm/src/org/python/antlr/ast/Tuple.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -50,6 +50,16 @@ return "Tuple"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Tuple["); + sb.append("elts="); + sb.append(this.elts); + sb.append("ctx="); + sb.append(this.ctx); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitTuple(this); } Modified: branches/asm/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "UnaryOp"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("UnaryOp["); + sb.append("op="); + sb.append(this.op); + sb.append("operand="); + sb.append(this.operand); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitUnaryOp(this); } Modified: branches/asm/src/org/python/antlr/ast/Unicode.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Unicode"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Unicode["); + sb.append("s="); + sb.append(this.s); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitUnicode(this); } Modified: branches/asm/src/org/python/antlr/ast/While.java =================================================================== --- branches/asm/src/org/python/antlr/ast/While.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/While.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -72,6 +72,18 @@ return "While"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("While["); + sb.append("test="); + sb.append(this.test); + sb.append("body="); + sb.append(this.body); + sb.append("orelse="); + sb.append(this.orelse); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitWhile(this); } Modified: branches/asm/src/org/python/antlr/ast/With.java =================================================================== --- branches/asm/src/org/python/antlr/ast/With.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/With.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -57,6 +57,18 @@ return "With"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("With["); + sb.append("context_expr="); + sb.append(this.context_expr); + sb.append("optional_vars="); + sb.append(this.optional_vars); + sb.append("body="); + sb.append(this.body); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitWith(this); } Modified: branches/asm/src/org/python/antlr/ast/Yield.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -30,6 +30,14 @@ return "Yield"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("Yield["); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { return visitor.visitYield(this); } Modified: branches/asm/src/org/python/antlr/ast/aliasType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "alias"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("alias["); + sb.append("name="); + sb.append(this.name); + sb.append("asname="); + sb.append(this.asname); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/argumentsType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -76,6 +76,20 @@ return "arguments"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("arguments["); + sb.append("args="); + sb.append(this.args); + sb.append("vararg="); + sb.append(this.vararg); + sb.append("kwarg="); + sb.append(this.kwarg); + sb.append("defaults="); + sb.append(this.defaults); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -56,6 +56,18 @@ return "comprehension"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("comprehension["); + sb.append("target="); + sb.append(this.target); + sb.append("iter="); + sb.append(this.iter); + sb.append("ifs="); + sb.append(this.ifs); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -65,6 +65,22 @@ return "excepthandler"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("excepthandler["); + sb.append("type="); + sb.append(this.type); + sb.append("name="); + sb.append(this.name); + sb.append("body="); + sb.append(this.body); + sb.append("lineno="); + sb.append(this.lineno); + sb.append("col_offset="); + sb.append(this.col_offset); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; Modified: branches/asm/src/org/python/antlr/ast/keywordType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-17 16:38:20 UTC (rev 4964) +++ branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-17 21:19:56 UTC (rev 4965) @@ -34,6 +34,16 @@ return "keyword"; } + public String toStringTree() { + StringBuffer sb = new StringBuffer("keyword["); + sb.append("arg="); + sb.append(this.arg); + sb.append("value="); + sb.append(this.value); + sb.append("]"); + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { traverse(visitor); return null; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-17 16:38:26
|
Revision: 4964 http://jython.svn.sourceforge.net/jython/?rev=4964&view=rev Author: fwierzbicki Date: 2008-07-17 16:38:20 +0000 (Thu, 17 Jul 2008) Log Message: ----------- start on lambda, comp_op, and list comp. Modified Paths: -------------- trunk/sandbox/wierzbicki/backup/Python.g Modified: trunk/sandbox/wierzbicki/backup/Python.g =================================================================== --- trunk/sandbox/wierzbicki/backup/Python.g 2008-07-17 04:59:53 UTC (rev 4963) +++ trunk/sandbox/wierzbicki/backup/Python.g 2008-07-17 16:38:20 UTC (rev 4964) @@ -77,7 +77,7 @@ tokens { INDENT; DEDENT; - + ModuleTok; Interactive; Expression; @@ -165,6 +165,9 @@ import org.python.antlr.ast.Break; import org.python.antlr.ast.Call; import org.python.antlr.ast.ClassDef; +import org.python.antlr.ast.cmpopType; +import org.python.antlr.ast.Compare; +import org.python.antlr.ast.comprehensionType; import org.python.antlr.ast.Context; import org.python.antlr.ast.Continue; import org.python.antlr.ast.Delete; @@ -182,6 +185,7 @@ import org.python.antlr.ast.ImportFrom; import org.python.antlr.ast.Index; import org.python.antlr.ast.keywordType; +import org.python.antlr.ast.Lambda; import org.python.antlr.ast.modType; import org.python.antlr.ast.Module; import org.python.antlr.ast.Name; @@ -990,7 +994,7 @@ @after { $exec_stmt.tree = $stype; } - : keyEXEC expr[expr_contextType.Load] ('in' t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? { + : keyEXEC expr[expr_contextType.Load] (IN t1=test[expr_contextType.Load] (COMMA t2=test[expr_contextType.Load])?)? { $stype = new Exec($expr.start, (exprType)$expr.tree, (exprType)$t1.tree, (exprType)$t2.tree); } ; @@ -1111,7 +1115,23 @@ ; //comparison: expr (comp_op expr)* -comparison[expr_contextType ctype]: expr[ctype] (comp_op^ expr[ctype])* +comparison[expr_contextType ctype] +@after { + if ($comparison.tree instanceof Compare) { + System.out.println("found Compare"); + Compare c = (Compare)$comparison.tree; + //FIXME: Only handling the case of a single comparison. + c.left = (exprType)c.getChild(0); + System.out.println("c.left:" + c.left); + c.comparators = new exprType[]{(exprType)c.getChild(1)}; + switch (c.getType()) { + case IN: + c.ops = new cmpopType[]{cmpopType.In}; + break; + } + } +} + : expr[ctype] (IN<Compare>^ expr[ctype])* ; //comp_op: '<'|'>'|'=='|'>='|'<='|'<>'|'!='|'in'|'not' 'in'|'is'|'is' 'not' @@ -1122,8 +1142,8 @@ | LESSEQUAL | ALT_NOTEQUAL | NOTEQUAL - | 'in' - | NOT 'in' -> NotIn + | IN + | NOT IN -> NotIn | 'is' | 'is' NOT -> IsNot ; @@ -1265,7 +1285,7 @@ //lambdef: 'lambda' [varargslist] ':' test lambdef: LAMBDA (varargslist)? COLON test[expr_contextType.Load] {debug("parsed lambda");} - -> ^(LAMBDA varargslist? ^(Body test)) + -> ^(LAMBDA<Lambda>[$LAMBDA, $varargslist.args, (exprType)$test.tree]) ; //trailer: '(' [arglist] ')' | '[' subscriptlist ']' | '.' NAME @@ -1414,7 +1434,7 @@ //list_for: 'for' exprlist 'in' testlist_safe [list_iter] list_for : FOR exprlist[expr_contextType.Load] IN testlist[expr_contextType.Load] (list_iter)? - -> ^(ListFor ^(Target exprlist) ^(IN testlist) ^(Ifs list_iter)?) + -> ^(FOR<comprehensionType>[$FOR, $exprlist.etype, $testlist.etype, null]) ; //list_if: 'if' test [list_iter] This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 04:59:55
|
Revision: 4963 http://jython.svn.sourceforge.net/jython/?rev=4963&view=rev Author: pjenvey Date: 2008-07-17 04:59:53 +0000 (Thu, 17 Jul 2008) Log Message: ----------- o fix PythonPOSIXHandler getEnv/getCurrentWorkingDirectory return signatures o fix posixpath.__all__ o only enable os.symlink/readlink and posixpath friends if the posix factory appears native. pure java support for symlinks is still sketchy -- in particular with dead links -- switching these on enables tests in test_glob, test_posixpath, test_tarfile that utilize dead links and are doomed to failure o allow partial filling of stat results from jna-posix, padding the rest with 0s Modified Paths: -------------- branches/asm/Lib/os.py branches/asm/Lib/posixpath.py Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-17 03:29:17 UTC (rev 4962) +++ branches/asm/Lib/os.py 2008-07-17 04:59:53 UTC (rev 4963) @@ -93,17 +93,8 @@ # should *NOT* use it _name = get_os_type() -if _name in ('nt', 'ce'): - import ntpath as path -else: - import posixpath as path +from org.python.posix import JavaPOSIX, POSIXHandler, POSIXFactory -sys.modules['os.path'] = _path = path -from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull -linesep = java.lang.System.getProperty('line.separator') - -from org.python.posix import POSIXHandler, POSIXFactory - class PythonPOSIXHandler(POSIXHandler): def error(self, error, msg): err = getattr(errno, error.name(), None) @@ -117,9 +108,9 @@ def isVerbose(self): return False def getCurrentWorkingDirectory(self): - return getcwd() + return File(getcwd()) def getEnv(self): - return environ + return ['%s=%s' % (key, val) for key, val in environ.iteritems()] def getInputStream(self): return getattr(java.lang.System, 'in') # XXX handle resetting def getOutputStream(self): @@ -130,7 +121,17 @@ return java.lang.System.err # XXX handle resetting _posix = POSIXFactory.getPOSIX(PythonPOSIXHandler(), True) +_native_posix = not isinstance(_posix, JavaPOSIX) +if _name in ('nt', 'ce'): + import ntpath as path +else: + import posixpath as path + +sys.modules['os.path'] = _path = path +from os.path import curdir, pardir, sep, pathsep, defpath, extsep, altsep, devnull +linesep = java.lang.System.getProperty('line.separator') + # open for reading only O_RDONLY = 0x0 # open for writing only @@ -188,6 +189,17 @@ for (name, index) in stat_result._stat_members: self.__dict__[name] = results[index] + @classmethod + def from_jnastat(cls, s): + results = [] + for meth in (s.mode, s.ino, s.dev, s.nlink, s.uid, s.gid, s.st_size, + s.atime, s.mtime, s.ctime): + try: + results.append(meth()) + except NotImplementedError: + results.append(0) + return cls(results) + def __getitem__(self, i): if i < 0 or i > 9: raise IndexError(i) @@ -421,10 +433,7 @@ """ abs_path = sys.getPath(path) try: - s = _posix.stat(abs_path) - return stat_result((s.mode(), s.ino(), s.dev(), s.nlink(), - s.uid(), s.gid(), s.st_size(), - s.atime(), s.mtime(), s.ctime())) + return stat_result.from_jnastat(_posix.stat(abs_path)) except NotImplementedError: pass except: @@ -452,10 +461,7 @@ """ abs_path = sys.getPath(path) try: - s = _posix.lstat(abs_path) - return stat_result((s.mode(), s.ino(), s.dev(), s.nlink(), - s.uid(), s.gid(), s.st_size(), - s.atime(), s.mtime(), s.ctime())) + return stat_result.from_jnastat(_posix.lstat(abs_path)) except NotImplementedError: pass except: @@ -639,7 +645,7 @@ except: raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) -if _name == 'posix': +if _name == 'posix' and _native_posix: def symlink(src, dst): """symlink(src, dst) Modified: branches/asm/Lib/posixpath.py =================================================================== --- branches/asm/Lib/posixpath.py 2008-07-17 03:29:17 UTC (rev 4962) +++ branches/asm/Lib/posixpath.py 2008-07-17 04:59:53 UTC (rev 4963) @@ -33,9 +33,6 @@ altsep = None devnull = '/dev/null' -# XXX: There should be a global way of disabling native JNA posix -native_posix = True - # Normalize the case of a pathname. Trivial in Posix, string.lower on Mac. # On MS-DOS this may also turn slashes into backslashes; however, other # normalizations (such as optimizing '../' away) are not allowed @@ -218,7 +215,7 @@ # Are two filenames really pointing to the same file? -if not native_posix: +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() @@ -243,8 +240,10 @@ s2 = os.fstat(fp2) return samestat(s1, s2) + __all__append("sameopenfile") -if native_posix: + +if os._native_posix: # Are two stat buffers (obtained from stat, fstat or lstat) # describing the same file? @@ -274,7 +273,7 @@ return True # path/.. is the same i-node as path return False - __all__.extend(["sameopenfile", "samestat", "ismount"]) + __all__.extend(["samestat", "ismount"]) # Directory tree walk. @@ -442,7 +441,7 @@ return abspath(filename) -if not native_posix: +if not os._native_posix: def _resolve_link(path): """Internal helper function. Takes a path and follows symlinks until we either arrive at something that isn't a symlink, or This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 03:29:22
|
Revision: 4962 http://jython.svn.sourceforge.net/jython/?rev=4962&view=rev Author: pjenvey Date: 2008-07-17 03:29:17 +0000 (Thu, 17 Jul 2008) Log Message: ----------- Merged revisions 4931-4961 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r4948 | amak | 2008-07-15 14:24:55 -0700 (Tue, 15 Jul 2008) | 1 line Merging forward IPv6 and UDP <broadcast> changes from Release 22 maint. ........ r4953 | pjenvey | 2008-07-15 18:15:46 -0700 (Tue, 15 Jul 2008) | 1 line restore proto=0 as _realsocket asserts it so ........ r4954 | pjenvey | 2008-07-15 18:18:14 -0700 (Tue, 15 Jul 2008) | 1 line don't attempt a traceback line for a bogus lineno ........ r4955 | pjenvey | 2008-07-15 19:11:48 -0700 (Tue, 15 Jul 2008) | 1 line use getClass here incase class becomes a permanent keyword in 2.5 ........ r4957 | pjenvey | 2008-07-16 17:29:54 -0700 (Wed, 16 Jul 2008) | 1 line allow passing unicode hostnames to socket.connect ........ r4958 | pjenvey | 2008-07-16 17:37:53 -0700 (Wed, 16 Jul 2008) | 1 line make the r4954 fix resemble asm's version ........ r4960 | pjenvey | 2008-07-16 18:43:59 -0700 (Wed, 16 Jul 2008) | 1 line use the full path of sys.prefix ........ Modified Paths: -------------- branches/asm/Lib/socket.py branches/asm/Lib/test/test_socket.py branches/asm/src/org/python/core/PySystemState.java branches/asm/src/org/python/core/PyTraceback.java Property Changed: ---------------- branches/asm/ Property changes on: branches/asm ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-4930 + /trunk/jython:1-4961 Modified: branches/asm/Lib/socket.py =================================================================== --- branches/asm/Lib/socket.py 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/Lib/socket.py 2008-07-17 03:29:17 UTC (rev 4962) @@ -147,8 +147,8 @@ SHUT_WR = 1 SHUT_RDWR = 2 -__all__ = [ 'AF_INET', 'SOCK_DGRAM', 'SOCK_RAW', - 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', +__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', + 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', 'SocketType', 'error', 'herror', 'gaierror', 'timeout', @@ -158,8 +158,12 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] +AF_UNSPEC = 0 AF_INET = 2 +AF_INET6 = 23 +AI_PASSIVE=1 + SOCK_DGRAM = 1 SOCK_STREAM = 2 SOCK_RAW = 3 # not supported @@ -372,8 +376,7 @@ bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent - def sendto(self, byte_array, address, flags): - host, port = _unpack_address_tuple(address) + def sendto(self, byte_array, host, port, flags): socket_address = java.net.InetSocketAddress(host, port) if self.mode == MODE_TIMEOUT: return self._do_send_net(byte_array, socket_address, flags) @@ -430,6 +433,10 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# Name and address functions + +has_ipv6 = 1 + def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) @@ -495,11 +502,29 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=0, socktype=SOCK_STREAM, proto=0, flags=0): - return ( (AF_INET, socktype, 0, "", (gethostbyname(host), port)), ) +def getaddrinfo(host, port, family=None, socktype=None, proto=0, flags=None): + try: + if not family in [AF_INET, AF_INET6, AF_UNSPEC]: + raise NotSupportedError() + filter_fns = [] + filter_fns.append({ + AF_INET: lambda x: isinstance(x, java.net.Inet4Address), + AF_INET6: lambda x: isinstance(x, java.net.Inet6Address), + AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress), + }[family]) + # Cant see a way to support AI_PASSIVE right now. + # if flags and flags & AI_PASSIVE: + # pass + results = [] + for a in java.net.InetAddress.getAllByName(host): + if len([f for f in filter_fns if f(a)]): + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()] + # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses + results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) + return results + except java.lang.Exception, jlx: + raise _map_exception(jlx) -has_ipv6 = 1 - def getnameinfo(sock_addr, flags): raise NotImplementedError("getnameinfo not yet supported on jython.") @@ -609,13 +634,28 @@ def _get_jsocket(self): return self.sock_impl.jsocket -def _unpack_address_tuple(address_tuple): +def _unpack_address_tuple(address_tuple, for_tx=False): + # TODO: Upgrade to support the 4-tuples used for IPv6 addresses + # which include flowinfo and scope_id. + # To be upgraded in synch with getaddrinfo error_message = "Address must be a tuple of (hostname, port)" - if type(address_tuple) is not type( () ) \ - or type(address_tuple[0]) is not type("") \ - or type(address_tuple[1]) is not type(0): + if not isinstance(address_tuple, tuple) or \ + not isinstance(address_tuple[0], basestring) or \ + not isinstance(address_tuple[1], (int, long)): raise TypeError(error_message) - return address_tuple[0], address_tuple[1] + hostname = address_tuple[0] + if isinstance(hostname, unicode): + # XXX: Should be encode('idna') (See CPython + # socketmodule::getsockaddrarg), but Jython's idna support is + # currently broken + hostname = hostname.encode() + hostname = hostname.strip() + if hostname == "<broadcast>": + if for_tx: + hostname = "255.255.255.255" + else: + hostname = "0.0.0.0" + return hostname, address_tuple[1] class _tcpsocket(_nonblocking_api_mixin): @@ -632,7 +672,7 @@ assert not self.sock_impl assert not self.local_addr # Do the address format check - host, port = _unpack_address_tuple(addr) + _unpack_address_tuple(addr) self.local_addr = addr def listen(self, backlog=50): @@ -641,7 +681,7 @@ assert not self.sock_impl self.server = 1 if self.local_addr: - host, port = self.local_addr + host, port = _unpack_address_tuple(self.local_addr) else: host, port = "", 0 self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[SO_REUSEADDR]) @@ -678,7 +718,7 @@ host, port = self._get_host_port(addr) self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = self.local_addr + bind_host, bind_port = _unpack_address_tuple(self.local_addr) self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) @@ -836,8 +876,9 @@ if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() + host, port = _unpack_address_tuple(addr, True) byte_array = java.lang.String(data).getBytes('iso-8859-1') - result = self.sock_impl.sendto(byte_array, addr, flags) + result = self.sock_impl.sendto(byte_array, host, port, flags) return result except java.lang.Exception, jlx: raise _map_exception(jlx) Modified: branches/asm/Lib/test/test_socket.py =================================================================== --- branches/asm/Lib/test/test_socket.py 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/Lib/test/test_socket.py 2008-07-17 03:29:17 UTC (rev 4962) @@ -801,6 +801,21 @@ self.cli.settimeout(10) self.cli.sendto(EIGHT_BIT_MSG, 0, (HOST, PORT)) +class UDPBroadcastTest(ThreadedUDPSocketTest): + + def setUp(self): + self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + def testBroadcast(self): + self.serv.bind( ("<broadcast>", PORT) ) + msg = self.serv.recv(len(EIGHT_BIT_MSG)) + self.assertEqual(msg, EIGHT_BIT_MSG) + + def _testBroadcast(self): + self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + self.cli.sendto(EIGHT_BIT_MSG, ("<broadcast>", PORT) ) + class BasicSocketPairTest(SocketPairTest): def __init__(self, methodName='runTest'): @@ -1421,6 +1436,14 @@ def setUp(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +class UnicodeTest(ThreadedTCPSocketTest): + + def testUnicodeHostname(self): + pass + + def _testUnicodeHostname(self): + self.cli.connect((unicode(HOST), PORT)) + def test_main(): tests = [ GeneralModuleTests, @@ -1442,13 +1465,18 @@ PrivateFileObjectTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, - SmallBufferedFileObjectClassTestCase + SmallBufferedFileObjectClassTestCase, + UnicodeTest ] if hasattr(socket, "socketpair"): tests.append(BasicSocketPairTest) if sys.platform[:4] == 'java': tests.append(TestJythonTCPExceptions) tests.append(TestJythonUDPExceptions) + # TODO: Broadcast requires permission, and is blocked by some firewalls + # Need some way to discover the network setup on the test machine + if False: + tests.append(UDPBroadcastTest) suites = [unittest.makeSuite(klass, 'test') for klass in tests] test_support.run_suite(unittest.TestSuite(suites)) Modified: branches/asm/src/org/python/core/PySystemState.java =================================================================== --- branches/asm/src/org/python/core/PySystemState.java 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/src/org/python/core/PySystemState.java 2008-07-17 03:29:17 UTC (rev 4962) @@ -383,6 +383,14 @@ } } } + if (root != null) { + File rootFile = new File(root); + try { + root = rootFile.getCanonicalPath(); + } catch (IOException ioe) { + root = rootFile.getAbsolutePath(); + } + } return root; } Modified: branches/asm/src/org/python/core/PyTraceback.java =================================================================== --- branches/asm/src/org/python/core/PyTraceback.java 2008-07-17 03:21:35 UTC (rev 4961) +++ branches/asm/src/org/python/core/PyTraceback.java 2008-07-17 03:29:17 UTC (rev 4962) @@ -80,7 +80,7 @@ // Continue, we may have the line } - if (i == tb_lineno && line != null) {//FJW: XXX: added null check just to avoid NPE. + if (line != null && i == tb_lineno) { i = 0; while (i < line.length()) { char c = line.charAt(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 03:21:37
|
Revision: 4961 http://jython.svn.sourceforge.net/jython/?rev=4961&view=rev Author: pjenvey Date: 2008-07-17 03:21:35 +0000 (Thu, 17 Jul 2008) Log Message: ----------- fix the symlink related tests by adding readlink, using _posix.lstat and utilizing _posix symlink stuff in posixpath. also utilize real stat results in posixpath, and re-enable ismount in ntpath since we can support it in posixpath Modified Paths: -------------- branches/asm/Lib/ntpath.py branches/asm/Lib/os.py branches/asm/Lib/posixpath.py Modified: branches/asm/Lib/ntpath.py =================================================================== --- branches/asm/Lib/ntpath.py 2008-07-17 01:43:59 UTC (rev 4960) +++ branches/asm/Lib/ntpath.py 2008-07-17 03:21:35 UTC (rev 4961) @@ -13,7 +13,7 @@ __all__ = ["normcase","isabs","join","splitdrive","split","splitext", "basename","dirname","commonprefix","getsize","getmtime", "getatime","getctime", "islink","exists","lexists","isdir","isfile", - "walk","expanduser","expandvars","normpath","abspath", + "ismount","walk","expanduser","expandvars","normpath","abspath", "splitunc","curdir","pardir","sep","pathsep","defpath","altsep", "extsep","devnull","realpath","supports_unicode_filenames"] @@ -287,21 +287,18 @@ return stat.S_ISREG(st.st_mode) -if os.name != 'java': - # Is a path a mount point? Either a root (with or without drive letter) - # or an UNC path with at most a / or \ after the mount point. +# Is a path a mount point? Either a root (with or without drive letter) +# or an UNC path with at most a / or \ after the mount point. - def ismount(path): - """Test whether a path is a mount point (defined as root of drive)""" - unc, rest = splitunc(path) - if unc: - return rest in ("", "/", "\\") - p = splitdrive(path)[1] - return len(p) == 1 and p[0] in '/\\' +def ismount(path): + """Test whether a path is a mount point (defined as root of drive)""" + unc, rest = splitunc(path) + if unc: + return rest in ("", "/", "\\") + p = splitdrive(path)[1] + return len(p) == 1 and p[0] in '/\\' - __all__.append("ismount") - # Directory tree walk. # For each directory under top (including top itself, but excluding # '.' and '..'), func(arg, dirname, filenames) is called, where Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-17 01:43:59 UTC (rev 4960) +++ branches/asm/Lib/os.py 2008-07-17 03:21:35 UTC (rev 4961) @@ -283,7 +283,6 @@ just the rightmost) will be created if it does not exist. The optional parameter is currently ignored. """ - sys_path = sys.getPath(path) if File(sys_path).mkdirs(): return @@ -451,6 +450,16 @@ Like stat(path), but do not follow symbolic links. """ + abs_path = sys.getPath(path) + try: + s = _posix.lstat(abs_path) + return stat_result((s.mode(), s.ino(), s.dev(), s.nlink(), + s.uid(), s.gid(), s.st_size(), + s.atime(), s.mtime(), s.ctime())) + except NotImplementedError: + pass + except: + raise f = File(sys.getPath(path)) abs_parent = f.getAbsoluteFile().getParentFile() if not abs_parent: @@ -636,8 +645,16 @@ Create a symbolic link pointing to src named dst. """ - return _posix.symlink(src, dst) + _posix.symlink(src, sys.getPath(dst)) + def readlink(path): + """readlink(path) -> path + + Return a string representing the path to which the symbolic link + points. + """ + return _posix.readlink(sys.getPath(path)) + # Provide lazy popen*, and system objects # Do these lazily, as most jython programs don't need them, # and they are very expensive to initialize Modified: branches/asm/Lib/posixpath.py =================================================================== --- branches/asm/Lib/posixpath.py 2008-07-17 01:43:59 UTC (rev 4960) +++ branches/asm/Lib/posixpath.py 2008-07-17 03:21:35 UTC (rev 4961) @@ -33,6 +33,9 @@ altsep = None devnull = '/dev/null' +# XXX: There should be a global way of disabling native JNA posix +native_posix = True + # Normalize the case of a pathname. Trivial in Posix, string.lower on Mac. # On MS-DOS this may also turn slashes into backslashes; however, other # normalizations (such as optimizing '../' away) are not allowed @@ -215,7 +218,7 @@ # Are two filenames really pointing to the same file? -if os.name == 'java': +if not native_posix: def samefile(f1, f2): """Test whether two pathnames reference the same actual file""" canon1 = java.io.File(_ensure_str(f1)).getCanonicalPath() @@ -241,6 +244,7 @@ return samestat(s1, s2) +if native_posix: # Are two stat buffers (obtained from stat, fstat or lstat) # describing the same file? @@ -438,7 +442,7 @@ return abspath(filename) -if os.name == 'java': +if not native_posix: def _resolve_link(path): """Internal helper function. Takes a path and follows symlinks until we either arrive at something that isn't a symlink, or This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 01:44:02
|
Revision: 4960 http://jython.svn.sourceforge.net/jython/?rev=4960&view=rev Author: pjenvey Date: 2008-07-17 01:43:59 +0000 (Thu, 17 Jul 2008) Log Message: ----------- use the full path of sys.prefix 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-07-17 01:23:59 UTC (rev 4959) +++ trunk/jython/src/org/python/core/PySystemState.java 2008-07-17 01:43:59 UTC (rev 4960) @@ -379,6 +379,14 @@ } } } + if (root != null) { + File rootFile = new File(root); + try { + root = rootFile.getCanonicalPath(); + } catch (IOException ioe) { + root = rootFile.getAbsolutePath(); + } + } return root; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 01:24:02
|
Revision: 4959 http://jython.svn.sourceforge.net/jython/?rev=4959&view=rev Author: pjenvey Date: 2008-07-17 01:23:59 +0000 (Thu, 17 Jul 2008) Log Message: ----------- add symlink on posix Modified Paths: -------------- branches/asm/Lib/os.py Modified: branches/asm/Lib/os.py =================================================================== --- branches/asm/Lib/os.py 2008-07-17 00:37:53 UTC (rev 4958) +++ branches/asm/Lib/os.py 2008-07-17 01:23:59 UTC (rev 4959) @@ -630,6 +630,14 @@ except: raise OSError(errno.EBADF, errno.strerror(errno.EBADF)) +if _name == 'posix': + def symlink(src, dst): + """symlink(src, dst) + + Create a symbolic link pointing to src named dst. + """ + return _posix.symlink(src, dst) + # Provide lazy popen*, and system objects # Do these lazily, as most jython programs don't need them, # and they are very expensive to initialize This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 00:37:56
|
Revision: 4958 http://jython.svn.sourceforge.net/jython/?rev=4958&view=rev Author: pjenvey Date: 2008-07-17 00:37:53 +0000 (Thu, 17 Jul 2008) Log Message: ----------- make the r4954 fix resemble asm's version Modified Paths: -------------- trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2008-07-17 00:29:54 UTC (rev 4957) +++ trunk/jython/src/org/python/core/PyTraceback.java 2008-07-17 00:37:53 UTC (rev 4958) @@ -80,7 +80,7 @@ // Continue, we may have the line } - if (tb_lineno > 0 && i == tb_lineno) { + if (line != null && i == tb_lineno) { i = 0; while (i < line.length()) { char c = line.charAt(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-17 00:29:55
|
Revision: 4957 http://jython.svn.sourceforge.net/jython/?rev=4957&view=rev Author: pjenvey Date: 2008-07-17 00:29:54 +0000 (Thu, 17 Jul 2008) Log Message: ----------- allow passing unicode hostnames to socket.connect Modified Paths: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2008-07-16 02:13:48 UTC (rev 4956) +++ trunk/jython/Lib/socket.py 2008-07-17 00:29:54 UTC (rev 4957) @@ -639,11 +639,17 @@ # which include flowinfo and scope_id. # To be upgraded in synch with getaddrinfo error_message = "Address must be a tuple of (hostname, port)" - if type(address_tuple) is not type( () ) \ - or type(address_tuple[0]) is not type("") \ - or type(address_tuple[1]) is not type(0): + if not isinstance(address_tuple, tuple) or \ + not isinstance(address_tuple[0], basestring) or \ + not isinstance(address_tuple[1], (int, long)): raise TypeError(error_message) - hostname = address_tuple[0].strip() + hostname = address_tuple[0] + if isinstance(hostname, unicode): + # XXX: Should be encode('idna') (See CPython + # socketmodule::getsockaddrarg), but Jython's idna support is + # currently broken + hostname = hostname.encode() + hostname = hostname.strip() if hostname == "<broadcast>": if for_tx: hostname = "255.255.255.255" Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2008-07-16 02:13:48 UTC (rev 4956) +++ trunk/jython/Lib/test/test_socket.py 2008-07-17 00:29:54 UTC (rev 4957) @@ -1436,6 +1436,14 @@ def setUp(self): self.socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) +class UnicodeTest(ThreadedTCPSocketTest): + + def testUnicodeHostname(self): + pass + + def _testUnicodeHostname(self): + self.cli.connect((unicode(HOST), PORT)) + def test_main(): tests = [ GeneralModuleTests, @@ -1457,7 +1465,8 @@ PrivateFileObjectTestCase, UnbufferedFileObjectClassTestCase, LineBufferedFileObjectClassTestCase, - SmallBufferedFileObjectClassTestCase + SmallBufferedFileObjectClassTestCase, + UnicodeTest ] if hasattr(socket, "socketpair"): tests.append(BasicSocketPairTest) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-16 02:13:50
|
Revision: 4956 http://jython.svn.sourceforge.net/jython/?rev=4956&view=rev Author: pjenvey Date: 2008-07-15 19:13:48 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Merged revisions 4953,4955 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk ........ r4953 | pjenvey | 2008-07-15 18:15:46 -0700 (Tue, 15 Jul 2008) | 1 line restore proto=0 as _realsocket asserts it so ........ r4955 | pjenvey | 2008-07-15 19:11:48 -0700 (Tue, 15 Jul 2008) | 1 line use getClass here incase class becomes a permanent keyword in 2.5 ........ Modified Paths: -------------- branches/Release_2_2maint/jython/Lib/socket.py Property Changed: ---------------- branches/Release_2_2maint/ Property changes on: branches/Release_2_2maint ___________________________________________________________________ Name: svnmerge-integrated - /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059,4132 + /trunk:1-3437,3458,3461,3466-3467,3471-3474,3479-3480,3490,3492,3496,3498,3501-3506,3512-3513,3515-3517,3519-3520,3522,3524,3527,3538,3540,3542-3545,3547-3548,3551,3553,3555-3556,3559,3563,3570,3574-3575,3577-3590,3592-3603,3605-3629,3634-3638,3640,3643-3657,3659-3661,3663-3681,3684,3686-3687,3692,3695,3732-3734,3739,3742-3743,3745,3747-3748,3751,3753-3756,3761-3762,3785,3803,3820-3822,3825,3827-3836,3851-3864,3866,3871-3875,3879,3881-3885,3890-3892,3895-3896,3898-3900,3904,3912-3913,4022,4059,4132,4953,4955 Modified: branches/Release_2_2maint/jython/Lib/socket.py =================================================================== --- branches/Release_2_2maint/jython/Lib/socket.py 2008-07-16 02:11:48 UTC (rev 4955) +++ branches/Release_2_2maint/jython/Lib/socket.py 2008-07-16 02:13:48 UTC (rev 4956) @@ -494,7 +494,7 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None): +def getaddrinfo(host, port, family=None, socktype=None, proto=0, flags=None): try: if not family in [AF_INET, AF_INET6, AF_UNSPEC]: raise NotSupportedError() @@ -510,7 +510,7 @@ results = [] for a in java.net.InetAddress.getAllByName(host): if len([f for f in filter_fns if f(a)]): - family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.class] + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()] # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) return results This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-16 02:11:49
|
Revision: 4955 http://jython.svn.sourceforge.net/jython/?rev=4955&view=rev Author: pjenvey Date: 2008-07-15 19:11:48 -0700 (Tue, 15 Jul 2008) Log Message: ----------- use getClass here incase class becomes a permanent keyword in 2.5 Modified Paths: -------------- trunk/jython/Lib/socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2008-07-16 01:18:14 UTC (rev 4954) +++ trunk/jython/Lib/socket.py 2008-07-16 02:11:48 UTC (rev 4955) @@ -518,7 +518,7 @@ results = [] for a in java.net.InetAddress.getAllByName(host): if len([f for f in filter_fns if f(a)]): - family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.class] + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.getClass()] # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) return results This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-16 01:18:15
|
Revision: 4954 http://jython.svn.sourceforge.net/jython/?rev=4954&view=rev Author: pjenvey Date: 2008-07-15 18:18:14 -0700 (Tue, 15 Jul 2008) Log Message: ----------- don't attempt a traceback line for a bogus lineno Modified Paths: -------------- trunk/jython/src/org/python/core/PyTraceback.java Modified: trunk/jython/src/org/python/core/PyTraceback.java =================================================================== --- trunk/jython/src/org/python/core/PyTraceback.java 2008-07-16 01:15:46 UTC (rev 4953) +++ trunk/jython/src/org/python/core/PyTraceback.java 2008-07-16 01:18:14 UTC (rev 4954) @@ -80,7 +80,7 @@ // Continue, we may have the line } - if (i == tb_lineno) { + if (tb_lineno > 0 && i == tb_lineno) { i = 0; while (i < line.length()) { char c = line.charAt(i); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-16 01:15:47
|
Revision: 4953 http://jython.svn.sourceforge.net/jython/?rev=4953&view=rev Author: pjenvey Date: 2008-07-15 18:15:46 -0700 (Tue, 15 Jul 2008) Log Message: ----------- restore proto=0 as _realsocket asserts it so Modified Paths: -------------- trunk/jython/Lib/socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2008-07-15 22:51:51 UTC (rev 4952) +++ trunk/jython/Lib/socket.py 2008-07-16 01:15:46 UTC (rev 4953) @@ -502,7 +502,7 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None): +def getaddrinfo(host, port, family=None, socktype=None, proto=0, flags=None): try: if not family in [AF_INET, AF_INET6, AF_UNSPEC]: raise NotSupportedError() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2008-07-15 22:51:54
|
Revision: 4952 http://jython.svn.sourceforge.net/jython/?rev=4952&view=rev Author: amak Date: 2008-07-15 15:51:51 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Backing out what I thought were simple changes, which appear to have broken the build. Modified Paths: -------------- branches/asm/Lib/socket.py branches/asm/Lib/test/test_socket.py Removed Paths: ------------- branches/asm/Lib/test/test_socket_ipv6.py Modified: branches/asm/Lib/socket.py =================================================================== --- branches/asm/Lib/socket.py 2008-07-15 22:37:38 UTC (rev 4951) +++ branches/asm/Lib/socket.py 2008-07-15 22:51:51 UTC (rev 4952) @@ -147,8 +147,8 @@ SHUT_WR = 1 SHUT_RDWR = 2 -__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', - 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', +__all__ = [ 'AF_INET', 'SOCK_DGRAM', 'SOCK_RAW', + 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', 'SocketType', 'error', 'herror', 'gaierror', 'timeout', @@ -158,12 +158,8 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] -AF_UNSPEC = 0 AF_INET = 2 -AF_INET6 = 23 -AI_PASSIVE=1 - SOCK_DGRAM = 1 SOCK_STREAM = 2 SOCK_RAW = 3 # not supported @@ -376,7 +372,8 @@ bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent - def sendto(self, byte_array, host, port, flags): + def sendto(self, byte_array, address, flags): + host, port = _unpack_address_tuple(address) socket_address = java.net.InetSocketAddress(host, port) if self.mode == MODE_TIMEOUT: return self._do_send_net(byte_array, socket_address, flags) @@ -433,10 +430,6 @@ else: return self._do_receive_nio(0, num_bytes, flags) -# Name and address functions - -has_ipv6 = 1 - def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) @@ -502,29 +495,11 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None): - try: - if not family in [AF_INET, AF_INET6, AF_UNSPEC]: - raise NotSupportedError() - filter_fns = [] - filter_fns.append({ - AF_INET: lambda x: isinstance(x, java.net.Inet4Address), - AF_INET6: lambda x: isinstance(x, java.net.Inet6Address), - AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress), - }[family]) - # Cant see a way to support AI_PASSIVE right now. - # if flags and flags & AI_PASSIVE: - # pass - results = [] - for a in java.net.InetAddress.getAllByName(host): - if len([f for f in filter_fns if f(a)]): - family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.class] - # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses - results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) - return results - except java.lang.Exception, jlx: - raise _map_exception(jlx) +def getaddrinfo(host, port, family=0, socktype=SOCK_STREAM, proto=0, flags=0): + return ( (AF_INET, socktype, 0, "", (gethostbyname(host), port)), ) +has_ipv6 = 1 + def getnameinfo(sock_addr, flags): raise NotImplementedError("getnameinfo not yet supported on jython.") @@ -634,22 +609,13 @@ def _get_jsocket(self): return self.sock_impl.jsocket -def _unpack_address_tuple(address_tuple, for_tx=False): - # TODO: Upgrade to support the 4-tuples used for IPv6 addresses - # which include flowinfo and scope_id. - # To be upgraded in synch with getaddrinfo +def _unpack_address_tuple(address_tuple): error_message = "Address must be a tuple of (hostname, port)" if type(address_tuple) is not type( () ) \ or type(address_tuple[0]) is not type("") \ or type(address_tuple[1]) is not type(0): raise TypeError(error_message) - hostname = address_tuple[0].strip() - if hostname == "<broadcast>": - if for_tx: - hostname = "255.255.255.255" - else: - hostname = "0.0.0.0" - return hostname, address_tuple[1] + return address_tuple[0], address_tuple[1] class _tcpsocket(_nonblocking_api_mixin): @@ -666,7 +632,7 @@ assert not self.sock_impl assert not self.local_addr # Do the address format check - _unpack_address_tuple(addr) + host, port = _unpack_address_tuple(addr) self.local_addr = addr def listen(self, backlog=50): @@ -675,7 +641,7 @@ assert not self.sock_impl self.server = 1 if self.local_addr: - host, port = _unpack_address_tuple(self.local_addr) + host, port = self.local_addr else: host, port = "", 0 self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[SO_REUSEADDR]) @@ -712,7 +678,7 @@ host, port = self._get_host_port(addr) self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = _unpack_address_tuple(self.local_addr) + bind_host, bind_port = self.local_addr self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) @@ -870,9 +836,8 @@ if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() - host, port = _unpack_address_tuple(addr, True) byte_array = java.lang.String(data).getBytes('iso-8859-1') - result = self.sock_impl.sendto(byte_array, host, port, flags) + result = self.sock_impl.sendto(byte_array, addr, flags) return result except java.lang.Exception, jlx: raise _map_exception(jlx) Modified: branches/asm/Lib/test/test_socket.py =================================================================== --- branches/asm/Lib/test/test_socket.py 2008-07-15 22:37:38 UTC (rev 4951) +++ branches/asm/Lib/test/test_socket.py 2008-07-15 22:51:51 UTC (rev 4952) @@ -801,21 +801,6 @@ self.cli.settimeout(10) self.cli.sendto(EIGHT_BIT_MSG, 0, (HOST, PORT)) -class UDPBroadcastTest(ThreadedUDPSocketTest): - - def setUp(self): - self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) - self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - - def testBroadcast(self): - self.serv.bind( ("<broadcast>", PORT) ) - msg = self.serv.recv(len(EIGHT_BIT_MSG)) - self.assertEqual(msg, EIGHT_BIT_MSG) - - def _testBroadcast(self): - self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) - self.cli.sendto(EIGHT_BIT_MSG, ("<broadcast>", PORT) ) - class BasicSocketPairTest(SocketPairTest): def __init__(self, methodName='runTest'): @@ -1464,10 +1449,6 @@ if sys.platform[:4] == 'java': tests.append(TestJythonTCPExceptions) tests.append(TestJythonUDPExceptions) - # TODO: Broadcast requires permission, and is blocked by some firewalls - # Need some way to discover the network setup on the test machine - if False: - tests.append(UDPBroadcastTest) suites = [unittest.makeSuite(klass, 'test') for klass in tests] test_support.run_suite(unittest.TestSuite(suites)) Deleted: branches/asm/Lib/test/test_socket_ipv6.py =================================================================== --- branches/asm/Lib/test/test_socket_ipv6.py 2008-07-15 22:37:38 UTC (rev 4951) +++ branches/asm/Lib/test/test_socket_ipv6.py 2008-07-15 22:51:51 UTC (rev 4952) @@ -1,61 +0,0 @@ -""" -AMAK: 20080714: -This module contains IPv6 related tests. -I have placed them in a separate module from the rest of the socket tests, because -1. The tests pass on my IPv6 enabled windows box, on JVMs >= 1.5 -2. They don't pass on Ubuntu, on any JVM version. The equivalent java code to lookup - IPv6 addresses doesn't work either, so I need to research how to configure Ubuntu - so that java.net.Inet6Address.getAllByName() actually returns IPv6 addresses. -3. I don't want to include these tests with the standard socket tests until - the network status and config of the various test environments, e.g. Mac, BSD, Solaris, etc, - are known. -""" - -import unittest -import test_support - -import socket - -class NameLookupTests(unittest.TestCase): - - def testLocalhostV4Lookup(self): - results = socket.getaddrinfo("localhost", 80, socket.AF_INET, socket.SOCK_STREAM, 0) - self.failUnlessEqual(len(results), 1) - self.failUnlessEqual('127.0.0.1', results[0][4][0]) - - def testRemoteV4Lookup(self): - results = socket.getaddrinfo("www.python.org", 80, socket.AF_INET, socket.SOCK_STREAM, 0) - self.failUnlessEqual(len(results), 1) - self.failUnlessEqual('82.94.237.218', results[0][4][0]) - - def testLocalhostV6Lookup(self): - results = socket.getaddrinfo("localhost", 80, socket.AF_INET6, socket.SOCK_STREAM, 0) - self.failUnlessEqual(len(results), 1) - self.failUnlessEqual('0:0:0:0:0:0:0:1', results[0][4][0]) - - def testRemoteV6Lookup(self): - # This test relies on those nice Dutch folks at sixxs.org keeping the same IPv6 address for their gateway - results = socket.getaddrinfo("www.python.org.sixxs.org", 80, socket.AF_INET6, socket.SOCK_STREAM, 0) - self.failUnlessEqual(len(results), 1) - self.failUnlessEqual('2001:838:2:1:2a0:24ff:feab:3b53', results[0][4][0]) - - def testLocalhostV4AndV6Lookup(self): - results = socket.getaddrinfo("localhost", 80, socket.AF_UNSPEC, socket.SOCK_STREAM, 0) - self.failUnlessEqual(len(results), 2) - - def testRemoteV4AndV6Lookup(self): - # Need a remote host with both IPv4 and IPv6 addresses; pass for now - pass - - def testAI_PASSIVE(self): - pass - -def test_main(): - tests = [ - NameLookupTests, - ] - suites = [unittest.makeSuite(klass, 'test') for klass in tests] - test_support.run_suite(unittest.TestSuite(suites)) - -if __name__ == "__main__": - test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-15 22:37:40
|
Revision: 4951 http://jython.svn.sourceforge.net/jython/?rev=4951&view=rev Author: nriley Date: 2008-07-15 15:37:38 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Oops, left some debugging code in. Modified Paths: -------------- branches/asm/src/shell/jython.bat Modified: branches/asm/src/shell/jython.bat =================================================================== --- branches/asm/src/shell/jython.bat 2008-07-15 22:33:04 UTC (rev 4950) +++ branches/asm/src/shell/jython.bat 2008-07-15 22:37:38 UTC (rev 4951) @@ -40,7 +40,6 @@ rem prefer built version set _CP=%_JYTHON_HOME%\jython.jar for %%j in (%_JYTHON_HOME%\javalib\*.jar) do ( - echo %%j set _CP=!_CP!;"%%j" ) @@ -54,4 +53,4 @@ set _CP= :finish -exit /b %E% \ No newline at end of file +exit /b %E% This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-15 22:33:08
|
Revision: 4950 http://jython.svn.sourceforge.net/jython/?rev=4950&view=rev Author: nriley Date: 2008-07-15 15:33:04 -0700 (Tue, 15 Jul 2008) Log Message: ----------- (Partial) Windows port of Jython launcher script; should work on Windows 2000 and later. Added Paths: ----------- branches/asm/src/shell/jython.bat Added: branches/asm/src/shell/jython.bat =================================================================== --- branches/asm/src/shell/jython.bat (rev 0) +++ branches/asm/src/shell/jython.bat 2008-07-15 22:33:04 UTC (rev 4950) @@ -0,0 +1,57 @@ +@echo off +rem --------------------------------------------------------------------------- +rem jython.bat - start script for Jython (adapted from jruby.bat) +rem +rem Environment variables (optional) +rem +rem JAVA_HOME Java installation directory +rem +rem JYTHON_HOME Jython installation directory +rem +rem JYTHON_OPTS Default Jython command line arguments +rem +rem --------------------------------------------------------------------------- + +setlocal enabledelayedexpansion + +rem ----- Verify and set required environment variables ----------------------- + +set _JYTHON_HOME="%JYTHON_HOME%" +if not "%JYTHON_HOME%" == "" goto gotHome +pushd "%~dp0%\.." +set _JYTHON_HOME="%CD%" +popd + +:gotHome +if exist %_JYTHON_HOME%/jython.jar goto homeOK +echo Cannot find jython.jar in %_JYTHON_HOME% +echo Try running this batch file from the 'bin' directory of an installed Jython +echo or setting JYTHON_HOME. +goto cleanup + +:homeOK +set _JAVA_CMD=java +if not "%JAVA_HOME%" == "" ( + set _JAVA_CMD=%JAVA_HOME%\bin\java +) + +set _CP=%_JYTHON_HOME%\jython-complete.jar +if not exist %_JYTHON_HOME%\jython.jar goto run +rem prefer built version +set _CP=%_JYTHON_HOME%\jython.jar +for %%j in (%_JYTHON_HOME%\javalib\*.jar) do ( + echo %%j + set _CP=!_CP!;"%%j" +) + +:run +%_JAVA_CMD% %JAVA_OPTS% -Xss512k -Xbootclasspath/a:%_CP% -Dpython.home=%_JYTHON_HOME% -Dpython.executable="%~f0" -classpath "%CLASSPATH%" org.python.util.jython %* +set E=%ERRORLEVEL% + +:cleanup +set _JYTHON_HOME=%JYTHON_HOME% +set _JAVA_CMD= +set _CP= + +:finish +exit /b %E% \ 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: <am...@us...> - 2008-07-15 21:33:44
|
Revision: 4949 http://jython.svn.sourceforge.net/jython/?rev=4949&view=rev Author: amak Date: 2008-07-15 14:33:35 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Merging support for IPv6 and UDP <broadcast> Modified Paths: -------------- branches/asm/Lib/socket.py branches/asm/Lib/test/test_socket.py Added Paths: ----------- branches/asm/Lib/test/test_socket_ipv6.py Modified: branches/asm/Lib/socket.py =================================================================== --- branches/asm/Lib/socket.py 2008-07-15 21:24:55 UTC (rev 4948) +++ branches/asm/Lib/socket.py 2008-07-15 21:33:35 UTC (rev 4949) @@ -147,8 +147,8 @@ SHUT_WR = 1 SHUT_RDWR = 2 -__all__ = [ 'AF_INET', 'SOCK_DGRAM', 'SOCK_RAW', - 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', +__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', + 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', 'SocketType', 'error', 'herror', 'gaierror', 'timeout', @@ -158,8 +158,12 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] +AF_UNSPEC = 0 AF_INET = 2 +AF_INET6 = 23 +AI_PASSIVE=1 + SOCK_DGRAM = 1 SOCK_STREAM = 2 SOCK_RAW = 3 # not supported @@ -372,8 +376,7 @@ bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent - def sendto(self, byte_array, address, flags): - host, port = _unpack_address_tuple(address) + def sendto(self, byte_array, host, port, flags): socket_address = java.net.InetSocketAddress(host, port) if self.mode == MODE_TIMEOUT: return self._do_send_net(byte_array, socket_address, flags) @@ -430,6 +433,10 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# Name and address functions + +has_ipv6 = 1 + def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) @@ -495,11 +502,29 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=0, socktype=SOCK_STREAM, proto=0, flags=0): - return ( (AF_INET, socktype, 0, "", (gethostbyname(host), port)), ) +def getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None): + try: + if not family in [AF_INET, AF_INET6, AF_UNSPEC]: + raise NotSupportedError() + filter_fns = [] + filter_fns.append({ + AF_INET: lambda x: isinstance(x, java.net.Inet4Address), + AF_INET6: lambda x: isinstance(x, java.net.Inet6Address), + AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress), + }[family]) + # Cant see a way to support AI_PASSIVE right now. + # if flags and flags & AI_PASSIVE: + # pass + results = [] + for a in java.net.InetAddress.getAllByName(host): + if len([f for f in filter_fns if f(a)]): + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.class] + # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses + results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) + return results + except java.lang.Exception, jlx: + raise _map_exception(jlx) -has_ipv6 = 1 - def getnameinfo(sock_addr, flags): raise NotImplementedError("getnameinfo not yet supported on jython.") @@ -609,13 +634,22 @@ def _get_jsocket(self): return self.sock_impl.jsocket -def _unpack_address_tuple(address_tuple): +def _unpack_address_tuple(address_tuple, for_tx=False): + # TODO: Upgrade to support the 4-tuples used for IPv6 addresses + # which include flowinfo and scope_id. + # To be upgraded in synch with getaddrinfo error_message = "Address must be a tuple of (hostname, port)" if type(address_tuple) is not type( () ) \ or type(address_tuple[0]) is not type("") \ or type(address_tuple[1]) is not type(0): raise TypeError(error_message) - return address_tuple[0], address_tuple[1] + hostname = address_tuple[0].strip() + if hostname == "<broadcast>": + if for_tx: + hostname = "255.255.255.255" + else: + hostname = "0.0.0.0" + return hostname, address_tuple[1] class _tcpsocket(_nonblocking_api_mixin): @@ -632,7 +666,7 @@ assert not self.sock_impl assert not self.local_addr # Do the address format check - host, port = _unpack_address_tuple(addr) + _unpack_address_tuple(addr) self.local_addr = addr def listen(self, backlog=50): @@ -641,7 +675,7 @@ assert not self.sock_impl self.server = 1 if self.local_addr: - host, port = self.local_addr + host, port = _unpack_address_tuple(self.local_addr) else: host, port = "", 0 self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[SO_REUSEADDR]) @@ -678,7 +712,7 @@ host, port = self._get_host_port(addr) self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = self.local_addr + bind_host, bind_port = _unpack_address_tuple(self.local_addr) self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) @@ -836,8 +870,9 @@ if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() + host, port = _unpack_address_tuple(addr, True) byte_array = java.lang.String(data).getBytes('iso-8859-1') - result = self.sock_impl.sendto(byte_array, addr, flags) + result = self.sock_impl.sendto(byte_array, host, port, flags) return result except java.lang.Exception, jlx: raise _map_exception(jlx) Modified: branches/asm/Lib/test/test_socket.py =================================================================== --- branches/asm/Lib/test/test_socket.py 2008-07-15 21:24:55 UTC (rev 4948) +++ branches/asm/Lib/test/test_socket.py 2008-07-15 21:33:35 UTC (rev 4949) @@ -801,6 +801,21 @@ self.cli.settimeout(10) self.cli.sendto(EIGHT_BIT_MSG, 0, (HOST, PORT)) +class UDPBroadcastTest(ThreadedUDPSocketTest): + + def setUp(self): + self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + def testBroadcast(self): + self.serv.bind( ("<broadcast>", PORT) ) + msg = self.serv.recv(len(EIGHT_BIT_MSG)) + self.assertEqual(msg, EIGHT_BIT_MSG) + + def _testBroadcast(self): + self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + self.cli.sendto(EIGHT_BIT_MSG, ("<broadcast>", PORT) ) + class BasicSocketPairTest(SocketPairTest): def __init__(self, methodName='runTest'): @@ -1449,6 +1464,10 @@ if sys.platform[:4] == 'java': tests.append(TestJythonTCPExceptions) tests.append(TestJythonUDPExceptions) + # TODO: Broadcast requires permission, and is blocked by some firewalls + # Need some way to discover the network setup on the test machine + if False: + tests.append(UDPBroadcastTest) suites = [unittest.makeSuite(klass, 'test') for klass in tests] test_support.run_suite(unittest.TestSuite(suites)) Added: branches/asm/Lib/test/test_socket_ipv6.py =================================================================== --- branches/asm/Lib/test/test_socket_ipv6.py (rev 0) +++ branches/asm/Lib/test/test_socket_ipv6.py 2008-07-15 21:33:35 UTC (rev 4949) @@ -0,0 +1,61 @@ +""" +AMAK: 20080714: +This module contains IPv6 related tests. +I have placed them in a separate module from the rest of the socket tests, because +1. The tests pass on my IPv6 enabled windows box, on JVMs >= 1.5 +2. They don't pass on Ubuntu, on any JVM version. The equivalent java code to lookup + IPv6 addresses doesn't work either, so I need to research how to configure Ubuntu + so that java.net.Inet6Address.getAllByName() actually returns IPv6 addresses. +3. I don't want to include these tests with the standard socket tests until + the network status and config of the various test environments, e.g. Mac, BSD, Solaris, etc, + are known. +""" + +import unittest +import test_support + +import socket + +class NameLookupTests(unittest.TestCase): + + def testLocalhostV4Lookup(self): + results = socket.getaddrinfo("localhost", 80, socket.AF_INET, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('127.0.0.1', results[0][4][0]) + + def testRemoteV4Lookup(self): + results = socket.getaddrinfo("www.python.org", 80, socket.AF_INET, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('82.94.237.218', results[0][4][0]) + + def testLocalhostV6Lookup(self): + results = socket.getaddrinfo("localhost", 80, socket.AF_INET6, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('0:0:0:0:0:0:0:1', results[0][4][0]) + + def testRemoteV6Lookup(self): + # This test relies on those nice Dutch folks at sixxs.org keeping the same IPv6 address for their gateway + results = socket.getaddrinfo("www.python.org.sixxs.org", 80, socket.AF_INET6, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('2001:838:2:1:2a0:24ff:feab:3b53', results[0][4][0]) + + def testLocalhostV4AndV6Lookup(self): + results = socket.getaddrinfo("localhost", 80, socket.AF_UNSPEC, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 2) + + def testRemoteV4AndV6Lookup(self): + # Need a remote host with both IPv4 and IPv6 addresses; pass for now + pass + + def testAI_PASSIVE(self): + pass + +def test_main(): + tests = [ + NameLookupTests, + ] + suites = [unittest.makeSuite(klass, 'test') for klass in tests] + test_support.run_suite(unittest.TestSuite(suites)) + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2008-07-15 21:24:59
|
Revision: 4948 http://jython.svn.sourceforge.net/jython/?rev=4948&view=rev Author: amak Date: 2008-07-15 14:24:55 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Merging forward IPv6 and UDP <broadcast> changes from Release 22 maint. Modified Paths: -------------- trunk/jython/Lib/socket.py trunk/jython/Lib/test/test_socket.py Added Paths: ----------- trunk/jython/Lib/test/test_socket_ipv6.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2008-07-15 21:21:30 UTC (rev 4947) +++ trunk/jython/Lib/socket.py 2008-07-15 21:24:55 UTC (rev 4948) @@ -147,8 +147,8 @@ SHUT_WR = 1 SHUT_RDWR = 2 -__all__ = [ 'AF_INET', 'SOCK_DGRAM', 'SOCK_RAW', - 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', +__all__ = ['AF_UNSPEC', 'AF_INET', 'AF_INET6', 'AI_PASSIVE', 'SOCK_DGRAM', + 'SOCK_RAW', 'SOCK_RDM', 'SOCK_SEQPACKET', 'SOCK_STREAM', 'SOL_SOCKET', 'SO_BROADCAST', 'SO_KEEPALIVE', 'SO_LINGER', 'SO_OOBINLINE', 'SO_RCVBUF', 'SO_REUSEADDR', 'SO_SNDBUF', 'SO_TIMEOUT', 'TCP_NODELAY', 'SocketType', 'error', 'herror', 'gaierror', 'timeout', @@ -158,8 +158,12 @@ 'SHUT_RD', 'SHUT_WR', 'SHUT_RDWR', ] +AF_UNSPEC = 0 AF_INET = 2 +AF_INET6 = 23 +AI_PASSIVE=1 + SOCK_DGRAM = 1 SOCK_STREAM = 2 SOCK_RAW = 3 # not supported @@ -372,8 +376,7 @@ bytes_sent = self.jchannel.send(byte_buf, socket_address) return bytes_sent - def sendto(self, byte_array, address, flags): - host, port = _unpack_address_tuple(address) + def sendto(self, byte_array, host, port, flags): socket_address = java.net.InetSocketAddress(host, port) if self.mode == MODE_TIMEOUT: return self._do_send_net(byte_array, socket_address, flags) @@ -430,6 +433,10 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# Name and address functions + +has_ipv6 = 1 + def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) @@ -495,11 +502,29 @@ else: return _udpsocket() -def getaddrinfo(host, port, family=0, socktype=SOCK_STREAM, proto=0, flags=0): - return ( (AF_INET, socktype, 0, "", (gethostbyname(host), port)), ) +def getaddrinfo(host, port, family=None, socktype=None, proto=None, flags=None): + try: + if not family in [AF_INET, AF_INET6, AF_UNSPEC]: + raise NotSupportedError() + filter_fns = [] + filter_fns.append({ + AF_INET: lambda x: isinstance(x, java.net.Inet4Address), + AF_INET6: lambda x: isinstance(x, java.net.Inet6Address), + AF_UNSPEC: lambda x: isinstance(x, java.net.InetAddress), + }[family]) + # Cant see a way to support AI_PASSIVE right now. + # if flags and flags & AI_PASSIVE: + # pass + results = [] + for a in java.net.InetAddress.getAllByName(host): + if len([f for f in filter_fns if f(a)]): + family = {java.net.Inet4Address: AF_INET, java.net.Inet6Address: AF_INET6}[a.class] + # TODO: Include flowinfo and scopeid in a 4-tuple for IPv6 addresses + results.append( (family, socktype, proto, a.getCanonicalHostName(), (a.getHostAddress(), port)) ) + return results + except java.lang.Exception, jlx: + raise _map_exception(jlx) -has_ipv6 = 1 - def getnameinfo(sock_addr, flags): raise NotImplementedError("getnameinfo not yet supported on jython.") @@ -609,13 +634,22 @@ def _get_jsocket(self): return self.sock_impl.jsocket -def _unpack_address_tuple(address_tuple): +def _unpack_address_tuple(address_tuple, for_tx=False): + # TODO: Upgrade to support the 4-tuples used for IPv6 addresses + # which include flowinfo and scope_id. + # To be upgraded in synch with getaddrinfo error_message = "Address must be a tuple of (hostname, port)" if type(address_tuple) is not type( () ) \ or type(address_tuple[0]) is not type("") \ or type(address_tuple[1]) is not type(0): raise TypeError(error_message) - return address_tuple[0], address_tuple[1] + hostname = address_tuple[0].strip() + if hostname == "<broadcast>": + if for_tx: + hostname = "255.255.255.255" + else: + hostname = "0.0.0.0" + return hostname, address_tuple[1] class _tcpsocket(_nonblocking_api_mixin): @@ -632,7 +666,7 @@ assert not self.sock_impl assert not self.local_addr # Do the address format check - host, port = _unpack_address_tuple(addr) + _unpack_address_tuple(addr) self.local_addr = addr def listen(self, backlog=50): @@ -641,7 +675,7 @@ assert not self.sock_impl self.server = 1 if self.local_addr: - host, port = self.local_addr + host, port = _unpack_address_tuple(self.local_addr) else: host, port = "", 0 self.sock_impl = _server_socket_impl(host, port, backlog, self.pending_options[SO_REUSEADDR]) @@ -678,7 +712,7 @@ host, port = self._get_host_port(addr) self.sock_impl = _client_socket_impl() if self.local_addr: # Has the socket been bound to a local address? - bind_host, bind_port = self.local_addr + bind_host, bind_port = _unpack_address_tuple(self.local_addr) self.sock_impl.bind(bind_host, bind_port, self.pending_options[SO_REUSEADDR]) self._config() # Configure timeouts, etc, now that the socket exists self.sock_impl.connect(host, port) @@ -836,8 +870,9 @@ if not self.sock_impl: self.sock_impl = _datagram_socket_impl() self._config() + host, port = _unpack_address_tuple(addr, True) byte_array = java.lang.String(data).getBytes('iso-8859-1') - result = self.sock_impl.sendto(byte_array, addr, flags) + result = self.sock_impl.sendto(byte_array, host, port, flags) return result except java.lang.Exception, jlx: raise _map_exception(jlx) Modified: trunk/jython/Lib/test/test_socket.py =================================================================== --- trunk/jython/Lib/test/test_socket.py 2008-07-15 21:21:30 UTC (rev 4947) +++ trunk/jython/Lib/test/test_socket.py 2008-07-15 21:24:55 UTC (rev 4948) @@ -801,6 +801,21 @@ self.cli.settimeout(10) self.cli.sendto(EIGHT_BIT_MSG, 0, (HOST, PORT)) +class UDPBroadcastTest(ThreadedUDPSocketTest): + + def setUp(self): + self.serv = socket.socket(socket.AF_INET, socket.SOCK_DGRAM) + self.serv.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + + def testBroadcast(self): + self.serv.bind( ("<broadcast>", PORT) ) + msg = self.serv.recv(len(EIGHT_BIT_MSG)) + self.assertEqual(msg, EIGHT_BIT_MSG) + + def _testBroadcast(self): + self.cli.setsockopt(socket.SOL_SOCKET, socket.SO_BROADCAST, 1) + self.cli.sendto(EIGHT_BIT_MSG, ("<broadcast>", PORT) ) + class BasicSocketPairTest(SocketPairTest): def __init__(self, methodName='runTest'): @@ -1449,6 +1464,10 @@ if sys.platform[:4] == 'java': tests.append(TestJythonTCPExceptions) tests.append(TestJythonUDPExceptions) + # TODO: Broadcast requires permission, and is blocked by some firewalls + # Need some way to discover the network setup on the test machine + if False: + tests.append(UDPBroadcastTest) suites = [unittest.makeSuite(klass, 'test') for klass in tests] test_support.run_suite(unittest.TestSuite(suites)) Added: trunk/jython/Lib/test/test_socket_ipv6.py =================================================================== --- trunk/jython/Lib/test/test_socket_ipv6.py (rev 0) +++ trunk/jython/Lib/test/test_socket_ipv6.py 2008-07-15 21:24:55 UTC (rev 4948) @@ -0,0 +1,61 @@ +""" +AMAK: 20080714: +This module contains IPv6 related tests. +I have placed them in a separate module from the rest of the socket tests, because +1. The tests pass on my IPv6 enabled windows box, on JVMs >= 1.5 +2. They don't pass on Ubuntu, on any JVM version. The equivalent java code to lookup + IPv6 addresses doesn't work either, so I need to research how to configure Ubuntu + so that java.net.Inet6Address.getAllByName() actually returns IPv6 addresses. +3. I don't want to include these tests with the standard socket tests until + the network status and config of the various test environments, e.g. Mac, BSD, Solaris, etc, + are known. +""" + +import unittest +import test_support + +import socket + +class NameLookupTests(unittest.TestCase): + + def testLocalhostV4Lookup(self): + results = socket.getaddrinfo("localhost", 80, socket.AF_INET, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('127.0.0.1', results[0][4][0]) + + def testRemoteV4Lookup(self): + results = socket.getaddrinfo("www.python.org", 80, socket.AF_INET, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('82.94.237.218', results[0][4][0]) + + def testLocalhostV6Lookup(self): + results = socket.getaddrinfo("localhost", 80, socket.AF_INET6, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('0:0:0:0:0:0:0:1', results[0][4][0]) + + def testRemoteV6Lookup(self): + # This test relies on those nice Dutch folks at sixxs.org keeping the same IPv6 address for their gateway + results = socket.getaddrinfo("www.python.org.sixxs.org", 80, socket.AF_INET6, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 1) + self.failUnlessEqual('2001:838:2:1:2a0:24ff:feab:3b53', results[0][4][0]) + + def testLocalhostV4AndV6Lookup(self): + results = socket.getaddrinfo("localhost", 80, socket.AF_UNSPEC, socket.SOCK_STREAM, 0) + self.failUnlessEqual(len(results), 2) + + def testRemoteV4AndV6Lookup(self): + # Need a remote host with both IPv4 and IPv6 addresses; pass for now + pass + + def testAI_PASSIVE(self): + pass + +def test_main(): + tests = [ + NameLookupTests, + ] + suites = [unittest.makeSuite(klass, 'test') for klass in tests] + test_support.run_suite(unittest.TestSuite(suites)) + +if __name__ == "__main__": + test_main() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <le...@us...> - 2008-07-15 21:21:39
|
Revision: 4947 http://jython.svn.sourceforge.net/jython/?rev=4947&view=rev Author: leosoto Date: 2008-07-15 14:21:30 -0700 (Tue, 15 Jul 2008) Log Message: ----------- Improvements to the zxJDBC default DataHandler: - Map DATE, TIME and TIMESTAMP columns to datetime.date, datetime.time and datetime.datetime respectively. Factory methods to create instances of datetime.* were added to Py.java. - Map VARCHAR columns to unicode instead of str. - Don't try to guess the precision of NUMERIC columns . - Use Py.True and Py.False instead of Py.One and Py.Zero. Some of this changes may cause backwards-incompatibility, so I've copied the old DataHandler logic into Jython22DataHandler. Then, old code should simply setup this datahandler on its connections if it is not going to be adapted to the new DataHandler default behaviour. Modified Paths: -------------- branches/asm/Lib/test/test_jy_internals.py branches/asm/src/com/ziclix/python/sql/DataHandler.java branches/asm/src/org/python/core/Py.java Added Paths: ----------- branches/asm/src/com/ziclix/python/sql/Jython22DataHandler.java Modified: branches/asm/Lib/test/test_jy_internals.py =================================================================== --- branches/asm/Lib/test/test_jy_internals.py 2008-07-15 21:05:06 UTC (rev 4946) +++ branches/asm/Lib/test/test_jy_internals.py 2008-07-15 21:21:30 UTC (rev 4947) @@ -3,11 +3,16 @@ """ import unittest import time -from test_support import run_suite +from test.test_support import run_suite import java import jarray +from org.python.core import Py +from java.sql import Date, Time, Timestamp +import datetime + + class WeakIdentityMapTests(unittest.TestCase): def test_functionality(self): @@ -44,7 +49,7 @@ time.sleep(1) assert widmap.get(i) == 'i' # triggers stale weak refs cleanup - assert widmap._internal_map_size() == 1 + assert widmap._internal_map_size() == 1 class LongAsScaledDoubleValueTests(unittest.TestCase): @@ -94,7 +99,7 @@ for d in range(8): for y in [0,255]: assert float((v+d)*256+y) == sdv(((v+d)*256+y)*256, e) - assert e[0] == 1 + assert e[0] == 1 class ExtraMathTests(unittest.TestCase): def test_epsilon(self): @@ -115,6 +120,28 @@ ExtraMath.closeFloor(3.0 - 3.0 * ExtraMath.CLOSE), 2.0) self.assertEquals(ExtraMath.closeFloor(math.log10(10**3)), 3.0) +class DatetimeTypeMappingTest(unittest.TestCase): + def test_date(self): + self.assertEquals(datetime.date(2008, 5, 29), + Py.newDate(Date(108, 4, 29))) + self.assertEquals(datetime.date(1999, 1, 1), + Py.newDate(Date(99, 0, 1))) + + def test_time(self): + self.assertEquals(datetime.time(0, 0, 0), + Py.newTime(Time(0, 0, 0))) + self.assertEquals(datetime.time(23, 59, 59), + Py.newTime(Time(23, 59, 59))) + + def test_datetime(self): + self.assertEquals(datetime.datetime(2008, 1, 1), + Py.newDatetime(Timestamp(108, 0, 1, 0, 0, 0, 0))) + self.assertEquals(datetime.datetime(2008, 5, 29, 16, 50, 0), + Py.newDatetime(Timestamp(108, 4, 29, 16, 50, 0, 0))) + self.assertEquals(datetime.datetime(2008, 5, 29, 16, 50, 1, 1), + Py.newDatetime(Timestamp(108, 4, 29, 16, 50, 1, 1000))) + + def test_main(): test_suite = unittest.TestSuite() test_loader = unittest.TestLoader() @@ -123,6 +150,7 @@ suite_add(WeakIdentityMapTests) suite_add(LongAsScaledDoubleValueTests) suite_add(ExtraMathTests) + suite_add(DatetimeTypeMappingTest) run_suite(test_suite) if __name__ == "__main__": Modified: branches/asm/src/com/ziclix/python/sql/DataHandler.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/DataHandler.java 2008-07-15 21:05:06 UTC (rev 4946) +++ branches/asm/src/com/ziclix/python/sql/DataHandler.java 2008-07-15 21:21:30 UTC (rev 4947) @@ -10,7 +10,6 @@ import org.python.core.Py; import org.python.core.PyFile; -import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyList; import org.python.core.PyString; @@ -151,7 +150,6 @@ * @throws SQLException */ public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { - try { if (checkNull(stmt, index, object, type)) { return; @@ -236,7 +234,7 @@ case Types.VARCHAR: String string = set.getString(col); - obj = (string == null) ? Py.None : Py.newString(string); + obj = (string == null) ? Py.None : Py.newUnicode(string); break; case Types.LONGVARCHAR: @@ -251,7 +249,7 @@ byte[] bytes = DataHandler.read(longvarchar); if (bytes != null) { - obj = Py.newString(StringUtil.fromBytes(bytes)); + obj = Py.newUnicode(StringUtil.fromBytes(bytes)); } } finally { try { @@ -263,19 +261,12 @@ case Types.NUMERIC: case Types.DECIMAL: - BigDecimal bd = null; - - try { - bd = set.getBigDecimal(col, set.getMetaData().getPrecision(col)); - } catch (Throwable t) { - bd = set.getBigDecimal(col, 10); - } - + BigDecimal bd = set.getBigDecimal(col); obj = (bd == null) ? Py.None : Py.newFloat(bd.doubleValue()); break; case Types.BIT: - obj = set.getBoolean(col) ? Py.One : Py.Zero; + obj = set.getBoolean(col) ? Py.True : Py.False; break; case Types.INTEGER: @@ -285,7 +276,7 @@ break; case Types.BIGINT: - obj = new PyLong(set.getLong(col)); + obj = Py.newLong(set.getLong(col)); break; case Types.FLOAT: @@ -298,15 +289,15 @@ break; case Types.TIME: - obj = Py.java2py(set.getTime(col)); + obj = Py.newTime(set.getTime(col)); break; case Types.TIMESTAMP: - obj = Py.java2py(set.getTimestamp(col)); + obj = Py.newDatetime(set.getTimestamp(col)); break; case Types.DATE: - obj = Py.java2py(set.getDate(col)); + obj = Py.newDate(set.getDate(col)); break; case Types.NULL: @@ -353,18 +344,18 @@ case Types.LONGVARCHAR: String string = stmt.getString(col); - obj = (string == null) ? Py.None : Py.newString(string); + obj = (string == null) ? Py.None : Py.newUnicode(string); break; case Types.NUMERIC: case Types.DECIMAL: - BigDecimal bd = stmt.getBigDecimal(col, 10); + BigDecimal bd = stmt.getBigDecimal(col); obj = (bd == null) ? Py.None : Py.newFloat(bd.doubleValue()); break; case Types.BIT: - obj = stmt.getBoolean(col) ? Py.One : Py.Zero; + obj = stmt.getBoolean(col) ? Py.True : Py.False; break; case Types.INTEGER: @@ -374,7 +365,7 @@ break; case Types.BIGINT: - obj = new PyLong(stmt.getLong(col)); + obj = Py.newLong(stmt.getLong(col)); break; case Types.FLOAT: @@ -387,15 +378,15 @@ break; case Types.TIME: - obj = Py.java2py(stmt.getTime(col)); + obj = Py.newTime(stmt.getTime(col)); break; case Types.TIMESTAMP: - obj = Py.java2py(stmt.getTimestamp(col)); + obj = Py.newDatetime(stmt.getTimestamp(col)); break; case Types.DATE: - obj = Py.java2py(stmt.getDate(col)); + obj = Py.newDate(stmt.getDate(col)); break; case Types.NULL: Added: branches/asm/src/com/ziclix/python/sql/Jython22DataHandler.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/Jython22DataHandler.java (rev 0) +++ branches/asm/src/com/ziclix/python/sql/Jython22DataHandler.java 2008-07-15 21:21:30 UTC (rev 4947) @@ -0,0 +1,452 @@ +/* + * Jython Database Specification API 2.0 + * + * $Id: DataHandler.java 3708 2007-11-20 20:03:46Z pjenvey $ + * + * Copyright (c) 2001 brian zimmer <bz...@zi...> + * + */ +package com.ziclix.python.sql; + +import org.python.core.Py; +import org.python.core.PyFile; +import org.python.core.PyLong; +import org.python.core.PyObject; +import org.python.core.PyList; +import org.python.core.PyString; +import org.python.core.util.StringUtil; + +import java.io.BufferedInputStream; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.Reader; +import java.io.StringReader; +import java.math.BigDecimal; +import java.sql.CallableStatement; +import java.sql.Date; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; +import java.sql.Time; +import java.sql.Timestamp; +import java.sql.Types; + +/** + * A copy of the DataHandler class as it was before Jython 2.5. By that version, + * some backward-incompatible changes was made, as returning datetime.* + * objects for DATE, TIME and TIMESTAMP columns, instead of java.sql.* classes. + * + * @author brian zimmer + * @author last revised by $Author: pjenvey $ + * @version $Revision: 3708 $ + */ +public class Jython22DataHandler extends DataHandler { + /** + * Handle most generic Java data types. + */ + public Jython22DataHandler() {} + + /** + * Some database vendors are case sensitive on calls to DatabaseMetaData, + * most notably Oracle. This callback allows a DataHandler to affect the + * name. + */ + public String getMetaDataName(PyObject name) { + return ((name == Py.None) ? null : name.__str__().toString()); + } + + /** + * A factory method for determing the correct procedure class to use + * per the cursor type. + * @param cursor an open cursor + * @param name the name of the procedure to invoke + * @return an instance of a Procedure + * @throws SQLException + */ + public Procedure getProcedure(PyCursor cursor, PyObject name) throws SQLException { + return new Procedure(cursor, name); + } + + /** + * Returns the row id of the last executed statement. + * + * @param stmt the current statement + * @return the row id of the last executed statement or None + * @throws SQLException thrown if an exception occurs + * + */ + public PyObject getRowId(Statement stmt) throws SQLException { + return Py.None; + } + + /** + * A callback prior to each execution of the statement. If the statement is + * a PreparedStatement, all the parameters will have been set. + */ + public void preExecute(Statement stmt) throws SQLException { + return; + } + + /** + * A callback after successfully executing the statement. + */ + public void postExecute(Statement stmt) throws SQLException { + return; + } + + /** + * Any .execute() which uses prepared statements will receive a callback for deciding + * how to map the PyObject to the appropriate JDBC type. + * + * @param stmt the current PreparedStatement + * @param index the index for which this object is bound + * @param object the PyObject in question + * @throws SQLException + */ + public void setJDBCObject(PreparedStatement stmt, int index, PyObject object) throws SQLException { + + try { + stmt.setObject(index, object.__tojava__(Object.class)); + } catch (Exception e) { + SQLException cause = null, ex = new SQLException("error setting index [" + index + "]"); + + if (e instanceof SQLException) { + cause = (SQLException) e; + } else { + cause = new SQLException(e.getMessage()); + } + + ex.setNextException(cause); + + throw ex; + } + } + + /** + * Any .execute() which uses prepared statements will receive a callback for deciding + * how to map the PyObject to the appropriate JDBC type. The <i>type</i> is the JDBC + * type as obtained from <i>java.sql.Types</i>. + * + * @param stmt the current PreparedStatement + * @param index the index for which this object is bound + * @param object the PyObject in question + * @param type the <i>java.sql.Types</i> for which this PyObject should be bound + * @throws SQLException + */ + public void setJDBCObject(PreparedStatement stmt, int index, PyObject object, int type) throws SQLException { + + try { + if (checkNull(stmt, index, object, type)) { + return; + } + + switch (type) { + + case Types.DATE: + Date date = (Date) object.__tojava__(Date.class); + + stmt.setDate(index, date); + break; + + case Types.TIME: + Time time = (Time) object.__tojava__(Time.class); + + stmt.setTime(index, time); + break; + + case Types.TIMESTAMP: + Timestamp timestamp = (Timestamp) object.__tojava__(Timestamp.class); + + stmt.setTimestamp(index, timestamp); + break; + + case Types.LONGVARCHAR: + if (object instanceof PyFile) { + object = new PyString(((PyFile) object).read()); + } + + String varchar = (String) object.__tojava__(String.class); + Reader reader = new BufferedReader(new StringReader(varchar)); + + stmt.setCharacterStream(index, reader, varchar.length()); + break; + + case Types.BIT: + stmt.setBoolean(index, object.__nonzero__()); + break; + + default : + if (object instanceof PyFile) { + object = new PyString(((PyFile) object).read()); + } + + stmt.setObject(index, object.__tojava__(Object.class), type); + break; + } + } catch (Exception e) { + SQLException cause = null, ex = new SQLException("error setting index [" + index + "], type [" + type + "]"); + + if (e instanceof SQLException) { + cause = (SQLException) e; + } else { + cause = new SQLException(e.getMessage()); + } + + ex.setNextException(cause); + + throw ex; + } + } + + /** + * Given a ResultSet, column and type, return the appropriate + * Jython object. + * + * <p>Note: DO NOT iterate the ResultSet. + * + * @param set the current ResultSet set to the current row + * @param col the column number (adjusted properly for JDBC) + * @param type the column type + * @throws SQLException if the type is unmappable + */ + public PyObject getPyObject(ResultSet set, int col, int type) throws SQLException { + + PyObject obj = Py.None; + + switch (type) { + + case Types.CHAR: + case Types.VARCHAR: + String string = set.getString(col); + + obj = (string == null) ? Py.None : Py.newString(string); + break; + + case Types.LONGVARCHAR: + InputStream longvarchar = set.getAsciiStream(col); + + if (longvarchar == null) { + obj = Py.None; + } else { + try { + longvarchar = new BufferedInputStream(longvarchar); + + byte[] bytes = Jython22DataHandler.read(longvarchar); + + if (bytes != null) { + obj = Py.newString(StringUtil.fromBytes(bytes)); + } + } finally { + try { + longvarchar.close(); + } catch (Throwable t) {} + } + } + break; + + case Types.NUMERIC: + case Types.DECIMAL: + BigDecimal bd = null; + + try { + bd = set.getBigDecimal(col, set.getMetaData().getPrecision(col)); + } catch (Throwable t) { + bd = set.getBigDecimal(col, 10); + } + + obj = (bd == null) ? Py.None : Py.newFloat(bd.doubleValue()); + break; + + case Types.BIT: + obj = set.getBoolean(col) ? Py.One : Py.Zero; + break; + + case Types.INTEGER: + case Types.TINYINT: + case Types.SMALLINT: + obj = Py.newInteger(set.getInt(col)); + break; + + case Types.BIGINT: + obj = new PyLong(set.getLong(col)); + break; + + case Types.FLOAT: + case Types.REAL: + obj = Py.newFloat(set.getFloat(col)); + break; + + case Types.DOUBLE: + obj = Py.newFloat(set.getDouble(col)); + break; + + case Types.TIME: + obj = Py.java2py(set.getTime(col)); + break; + + case Types.TIMESTAMP: + obj = Py.java2py(set.getTimestamp(col)); + break; + + case Types.DATE: + obj = Py.java2py(set.getDate(col)); + break; + + case Types.NULL: + obj = Py.None; + break; + + case Types.OTHER: + obj = Py.java2py(set.getObject(col)); + break; + + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + obj = Py.java2py(set.getBytes(col)); + break; + + default : + Integer[] vals = {new Integer(col), new Integer(type)}; + String msg = zxJDBC.getString("errorGettingIndex", vals); + + throw new SQLException(msg); + } + + return (set.wasNull() || (obj == null)) ? Py.None : obj; + } + + /** + * Given a CallableStatement, column and type, return the appropriate + * Jython object. + * + * @param stmt the CallableStatement + * @param col the column number (adjusted properly for JDBC) + * @param type the column type + * @throws SQLException if the type is unmappable + */ + public PyObject getPyObject(CallableStatement stmt, int col, int type) throws SQLException { + + PyObject obj = Py.None; + + switch (type) { + + case Types.CHAR: + case Types.VARCHAR: + case Types.LONGVARCHAR: + String string = stmt.getString(col); + + obj = (string == null) ? Py.None : Py.newString(string); + break; + + case Types.NUMERIC: + case Types.DECIMAL: + BigDecimal bd = stmt.getBigDecimal(col, 10); + + obj = (bd == null) ? Py.None : Py.newFloat(bd.doubleValue()); + break; + + case Types.BIT: + obj = stmt.getBoolean(col) ? Py.One : Py.Zero; + break; + + case Types.INTEGER: + case Types.TINYINT: + case Types.SMALLINT: + obj = Py.newInteger(stmt.getInt(col)); + break; + + case Types.BIGINT: + obj = new PyLong(stmt.getLong(col)); + break; + + case Types.FLOAT: + case Types.REAL: + obj = Py.newFloat(stmt.getFloat(col)); + break; + + case Types.DOUBLE: + obj = Py.newFloat(stmt.getDouble(col)); + break; + + case Types.TIME: + obj = Py.java2py(stmt.getTime(col)); + break; + + case Types.TIMESTAMP: + obj = Py.java2py(stmt.getTimestamp(col)); + break; + + case Types.DATE: + obj = Py.java2py(stmt.getDate(col)); + break; + + case Types.NULL: + obj = Py.None; + break; + + case Types.OTHER: + obj = Py.java2py(stmt.getObject(col)); + break; + + case Types.BINARY: + case Types.VARBINARY: + case Types.LONGVARBINARY: + obj = Py.java2py(stmt.getBytes(col)); + break; + + default : + Integer[] vals = {new Integer(col), new Integer(type)}; + String msg = zxJDBC.getString("errorGettingIndex", vals); + + throw new SQLException(msg); + } + + return (stmt.wasNull() || (obj == null)) ? Py.None : obj; + } + + /** + * Called when a stored procedure or function is executed and OUT parameters + * need to be registered with the statement. + * + * @param statement + * @param index the JDBC offset column number + * @param colType the column as from DatabaseMetaData (eg, procedureColumnOut) + * @param dataType the JDBC datatype from Types + * @param dataTypeName the JDBC datatype name + * + * @throws SQLException + * + */ + public void registerOut(CallableStatement statement, int index, int colType, int dataType, String dataTypeName) throws SQLException { + + try { + statement.registerOutParameter(index, dataType); + } catch (Throwable t) { + SQLException cause = null; + SQLException ex = new SQLException("error setting index [" + + index + "], coltype [" + colType + "], datatype [" + dataType + + "], datatypename [" + dataTypeName + "]"); + + if (t instanceof SQLException) { + cause = (SQLException)t; + } else { + cause = new SQLException(t.getMessage()); + } + ex.setNextException(cause); + throw ex; + } + } + + /** + * Returns a list of datahandlers chained together through the use of delegation. + * + * @return a list of datahandlers + */ + public PyObject __chain__() { + return new PyList(new PyObject[] { Py.java2py(this) }); + } + +} + Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-15 21:05:06 UTC (rev 4946) +++ branches/asm/src/org/python/core/Py.java 2008-07-15 21:21:30 UTC (rev 4947) @@ -12,6 +12,10 @@ import java.io.Serializable; import java.io.StreamCorruptedException; import java.lang.reflect.InvocationTargetException; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.util.Calendar; import java.util.HashSet; import java.util.Set; @@ -580,6 +584,54 @@ return t ? Py.True : Py.False; } + public static PyObject newDate(Date date) { + if (date == null) { + return Py.None; + } + PyObject datetimeModule = __builtin__.__import__("datetime"); + PyObject dateClass = datetimeModule.__getattr__("date"); + Calendar cal = Calendar.getInstance(); + cal.setTime(date); + + return dateClass.__call__(newInteger(cal.get(Calendar.YEAR)), + newInteger(cal.get(Calendar.MONTH) + 1), + newInteger(cal.get(Calendar.DAY_OF_MONTH))); + + } + + public static PyObject newTime(Time time) { + if (time == null) { + return Py.None; + } + PyObject datetimeModule = __builtin__.__import__("datetime"); + PyObject timeClass = datetimeModule.__getattr__("time"); + Calendar cal = Calendar.getInstance(); + cal.setTime(time); + return timeClass.__call__(newInteger(cal.get(Calendar.HOUR_OF_DAY)), + newInteger(cal.get(Calendar.MINUTE)), + newInteger(cal.get(Calendar.SECOND)), + newInteger(cal.get(Calendar.MILLISECOND) * + 1000)); + } + + public static PyObject newDatetime(Timestamp timestamp) { + if (timestamp == null) { + return Py.None; + } + PyObject datetimeModule = __builtin__.__import__("datetime"); + PyObject datetimeClass = datetimeModule.__getattr__("datetime"); + Calendar cal = Calendar.getInstance(); + cal.setTime(timestamp); + return datetimeClass.__call__(new PyObject[] { + newInteger(cal.get(Calendar.YEAR)), + newInteger(cal.get(Calendar.MONTH) + 1), + newInteger(cal.get(Calendar.DAY_OF_MONTH)), + newInteger(cal.get(Calendar.HOUR_OF_DAY)), + newInteger(cal.get(Calendar.MINUTE)), + newInteger(cal.get(Calendar.SECOND)), + newInteger(timestamp.getNanos() / 1000)}); + } + public static PyCode newCode(int argcount, String varnames[], String filename, String name, boolean args, boolean keywords, This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |