You can subscribe to this list here.
2000 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
(1) |
Nov
(107) |
Dec
(67) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2001 |
Jan
(76) |
Feb
(125) |
Mar
(72) |
Apr
(13) |
May
(18) |
Jun
(12) |
Jul
(129) |
Aug
(47) |
Sep
(1) |
Oct
(36) |
Nov
(128) |
Dec
(124) |
2002 |
Jan
(59) |
Feb
|
Mar
(14) |
Apr
(14) |
May
(72) |
Jun
(9) |
Jul
(3) |
Aug
(5) |
Sep
(18) |
Oct
(65) |
Nov
(28) |
Dec
(12) |
2003 |
Jan
(10) |
Feb
(2) |
Mar
(4) |
Apr
(33) |
May
(21) |
Jun
(9) |
Jul
(29) |
Aug
(34) |
Sep
(4) |
Oct
(8) |
Nov
(15) |
Dec
(4) |
2004 |
Jan
(26) |
Feb
(12) |
Mar
(11) |
Apr
(9) |
May
(7) |
Jun
|
Jul
(5) |
Aug
|
Sep
(3) |
Oct
(7) |
Nov
(1) |
Dec
(10) |
2005 |
Jan
(2) |
Feb
(72) |
Mar
(16) |
Apr
(39) |
May
(48) |
Jun
(97) |
Jul
(57) |
Aug
(13) |
Sep
(16) |
Oct
(24) |
Nov
(100) |
Dec
(24) |
2006 |
Jan
(15) |
Feb
(34) |
Mar
(33) |
Apr
(31) |
May
(79) |
Jun
(64) |
Jul
(41) |
Aug
(64) |
Sep
(31) |
Oct
(46) |
Nov
(55) |
Dec
(37) |
2007 |
Jan
(32) |
Feb
(61) |
Mar
(11) |
Apr
(58) |
May
(46) |
Jun
(30) |
Jul
(94) |
Aug
(93) |
Sep
(86) |
Oct
(69) |
Nov
(125) |
Dec
(177) |
2008 |
Jan
(169) |
Feb
(97) |
Mar
(74) |
Apr
(113) |
May
(120) |
Jun
(334) |
Jul
(215) |
Aug
(237) |
Sep
(72) |
Oct
(189) |
Nov
(126) |
Dec
(160) |
2009 |
Jan
(180) |
Feb
(45) |
Mar
(98) |
Apr
(140) |
May
(151) |
Jun
(71) |
Jul
(107) |
Aug
(119) |
Sep
(73) |
Oct
(121) |
Nov
(14) |
Dec
(6) |
2010 |
Jan
(13) |
Feb
(9) |
Mar
(10) |
Apr
(64) |
May
(3) |
Jun
(16) |
Jul
(7) |
Aug
(23) |
Sep
(17) |
Oct
(37) |
Nov
(5) |
Dec
(8) |
2011 |
Jan
(10) |
Feb
(11) |
Mar
(77) |
Apr
(11) |
May
(2) |
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
|
From: <fwi...@us...> - 2008-07-24 16:58:26
|
Revision: 4996 http://jython.svn.sourceforge.net/jython/?rev=4996&view=rev Author: fwierzbicki Date: 2008-07-24 16:58:24 +0000 (Thu, 24 Jul 2008) Log Message: ----------- Fix for wrong line numbers in func.co_firstlineno. Modified Paths: -------------- branches/asm/src/org/python/compiler/CodeCompiler.java Modified: branches/asm/src/org/python/compiler/CodeCompiler.java =================================================================== --- branches/asm/src/org/python/compiler/CodeCompiler.java 2008-07-24 13:51:47 UTC (rev 4995) +++ branches/asm/src/org/python/compiler/CodeCompiler.java 2008-07-24 16:58:24 UTC (rev 4996) @@ -397,7 +397,7 @@ scope.dump(); module.PyCode(new Suite(node, node.body), name, true, className, false, false, - node.getTokenStartIndex(), scope, cflags).get(code); + node.getLine(), scope, cflags).get(code); getDocString(node.body); @@ -1738,7 +1738,7 @@ scope.setup_closure(); scope.dump(); module.PyCode(retSuite, name, true, className, - false, false, node.getTokenStartIndex(), scope, cflags).get(code); + false, false, node.getLine(), scope, cflags).get(code); if (!makeClosure(scope)) { code.invokespecial("org/python/core/PyFunction", "<init>", "(" + $pyObj + $pyObjArr + $pyCode + ")V"); @@ -1781,7 +1781,7 @@ scope.dump(); //Make code object out of suite module.PyCode(new Suite(node, node.body), name, false, name, - true, false, node.getTokenStartIndex(), scope, cflags).get(code); + true, false, node.getLine(), scope, cflags).get(code); //Get doc string (if there) getDocString(node.body); @@ -1980,7 +1980,7 @@ module.PyCode(new Suite(node, new stmtType[]{n}), tmp_append, true, className, false, false, - node.getTokenStartIndex(), scope, cflags).get(code); + node.getLine(), scope, cflags).get(code); code.aconst_null(); if (!makeClosure(scope)) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-24 13:51:50
|
Revision: 4995 http://jython.svn.sourceforge.net/jython/?rev=4995&view=rev Author: fwierzbicki Date: 2008-07-24 13:51:47 +0000 (Thu, 24 Jul 2008) Log Message: ----------- Make stopCharIndex consistent. Modified Paths: -------------- branches/asm/src/org/python/antlr/PythonTreeAdaptor.java Modified: branches/asm/src/org/python/antlr/PythonTreeAdaptor.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-07-24 07:29:54 UTC (rev 4994) +++ branches/asm/src/org/python/antlr/PythonTreeAdaptor.java 2008-07-24 13:51:47 UTC (rev 4995) @@ -29,9 +29,9 @@ //XXX: instanceof is necessary because of the use of ClassicToken // for leading whitespace lexing. if (stopToken instanceof CommonToken) { - stopChar = ((CommonToken)stopToken).getStopIndex(); + stopChar = ((CommonToken)stopToken).getStopIndex() + 1; } else if (stopToken instanceof ImaginaryToken) { - stopChar = ((ImaginaryToken)stopToken).getStopIndex(); + stopChar = ((ImaginaryToken)stopToken).getStopIndex() + 1; } } PythonTree pt = (PythonTree)t; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-24 07:29:56
|
Revision: 4994 http://jython.svn.sourceforge.net/jython/?rev=4994&view=rev Author: pjenvey Date: 2008-07-24 07:29:54 +0000 (Thu, 24 Jul 2008) Log Message: ----------- add codecs.charmap_build which builds optimized encoding maps now used by the charmap encoder Modified Paths: -------------- branches/asm/CoreExposed.includes branches/asm/src/org/python/modules/_codecs.java Modified: branches/asm/CoreExposed.includes =================================================================== --- branches/asm/CoreExposed.includes 2008-07-24 07:22:38 UTC (rev 4993) +++ branches/asm/CoreExposed.includes 2008-07-24 07:29:54 UTC (rev 4994) @@ -35,6 +35,7 @@ org/python/core/PyType.class org/python/core/PyUnicode.class org/python/core/PyXRange.class +org/python/modules/_codecs$EncodingMap.class org/python/modules/_weakref/CallableProxyType.class org/python/modules/_weakref/ReferenceType.class org/python/modules/_weakref/ProxyType.class Modified: branches/asm/src/org/python/modules/_codecs.java =================================================================== --- branches/asm/src/org/python/modules/_codecs.java 2008-07-24 07:22:38 UTC (rev 4993) +++ branches/asm/src/org/python/modules/_codecs.java 2008-07-24 07:29:54 UTC (rev 4994) @@ -11,6 +11,7 @@ import java.nio.charset.Charset; import org.python.core.Py; +import org.python.core.PyDictionary; import org.python.core.PyInteger; import org.python.core.PyNone; import org.python.core.PyObject; @@ -19,6 +20,7 @@ import org.python.core.PyTuple; import org.python.core.PyUnicode; import org.python.core.codecs; +import org.python.expose.ExposedType; public class _codecs { @@ -38,6 +40,10 @@ codecs.register_error(name, errorHandler); } + public static PyObject charmap_build(PyUnicode map) { + return EncodingMap.buildEncodingMap(map); + } + private static PyTuple decode_tuple(String s, int len) { return new PyTuple(new PyUnicode(s), Py.newInteger(len)); } @@ -247,11 +253,21 @@ PyObject mapping, StringBuilder v, boolean letLookupHandleError) { + EncodingMap encodingMap = mapping instanceof EncodingMap ? (EncodingMap)mapping : null; int size = str.length(); for (int i = 0; i < size; i++) { char ch = str.charAt(i); - PyObject w = Py.newInteger(ch); - PyObject x = mapping.__finditem__(w); + PyObject x; + if (encodingMap != null) { + int result = encodingMap.lookup(ch); + if (result == -1) { + x = null; + } else { + x = Py.newInteger(result); + } + } else { + x = mapping.__finditem__(Py.newInteger(ch)); + } if (x == null) { if (letLookupHandleError) { i = handleBadMapping(str, errors, mapping, v, size, i); @@ -626,5 +642,155 @@ public static PyTuple unicode_internal_decode(String str, String errors) { return decode_tuple(str, str.length()); } + + /** + * Optimized charmap encoder mapping. + * + * Uses a trie structure instead of a dictionary; the speedup primarily comes from not + * creating integer objects in the process. The trie is created by inverting the + * encoding map. + */ + @ExposedType(name = "EncodingMap") + public static class EncodingMap extends PyObject { + + char[] level1; + + char[] level23; + + int count2; + + int count3; + + private EncodingMap(char[] level1, char[] level23, int count2, int count3) { + this.level1 = level1; + this.level23 = level23; + this.count2 = count2; + this.count3 = count3; + } + + /** + * Create and populate an EncodingMap from a 256 length PyUnicode char. Returns a + * PyDictionary if the mapping isn't easily optimized. + * + * @param string a 256 length unicode mapping + * @return an encoder mapping + */ + public static PyObject buildEncodingMap(PyObject string) { + if (!(string instanceof PyUnicode) || string.__len__() != 256) { + throw Py.TypeError("bad argument type for built-in operation"); + } + + boolean needDict = false; + char[] level1 = new char[32]; + char[] level23 = new char[512]; + int i; + int count2 = 0; + int count3 = 0; + String decode = string.toString(); + for (i = 0; i < level1.length; i++) { + level1[i] = 0xFF; + } + for (i = 0; i < level23.length; i++) { + level23[i] = 0xFF; + } + if (decode.charAt(0) != 0) { + needDict = true; + } + for (i = 1; i < 256; i++) { + int l1, l2; + char charAt = decode.charAt(i); + if (charAt == 0) { + needDict = true; + } + if (charAt == 0xFFFE) { + // unmapped character + continue; + } + l1 = charAt >> 11; + l2 = charAt >> 7; + if (level1[l1] == 0xFF) { + level1[l1] = (char)count2++; + } + if (level23[l2] == 0xFF) { + level23[l2] = (char)count3++; + } + } + + if (count2 > 0xFF || count3 > 0xFF) { + needDict = true; + } + + if (needDict) { + PyObject result = new PyDictionary(); + for (i = 0; i < 256; i++) { + result.__setitem__(Py.newInteger(decode.charAt(i)), Py.newInteger(i)); + } + return result; + } + + // Create a three-level trie + int length2 = 16 * count2; + int length3 = 128 * count3; + level23 = new char[length2 + length3]; + PyObject result = new EncodingMap(level1, level23, count2, count3); + for (i = 0; i < length2; i++) { + level23[i] = 0xFF; + } + for (i = length2; i < length2 + length3; i++) { + level23[i] = 0; + } + count3 = 0; + for (i = 1; i < 256; i++) { + int o1, o2, o3, i2, i3; + char charAt = decode.charAt(i); + if (charAt == 0xFFFE) { + // unmapped character + continue; + } + o1 = charAt >> 11; + o2 = (charAt >> 7) & 0xF; + i2 = 16 * level1[o1] + o2; + if (level23[i2] == 0xFF) { + level23[i2] = (char)count3++; + } + o3 = charAt & 0x7F; + i3 = 128 * level23[i2] + o3; + level23[length2 + i3] = (char)i; + } + return result; + } + + /** + * Lookup a char in the EncodingMap. + * + * @param c a char + * @return an int, -1 for failure + */ + public int lookup(char c) { + int l1 = c >> 11; + int l2 = (c >> 7) & 0xF; + int l3 = c & 0x7F; + int i; + if (c == 0) { + return 0; + } + // level 1 + i = level1[l1]; + if (i == 0xFF) { + return -1; + } + // level 2 + i = level23[16 * i + l2]; + if (i == 0xFF) { + return -1; + } + // level 3 + i = level23[16 * count2 + 128 * i + l3]; + if (i == 0) { + return -1; + } + return i; + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-24 07:22:42
|
Revision: 4993 http://jython.svn.sourceforge.net/jython/?rev=4993&view=rev Author: pjenvey Date: 2008-07-24 07:22:38 +0000 (Thu, 24 Jul 2008) Log Message: ----------- fix a regression from the bug 1140 fix Modified Paths: -------------- branches/asm/Lib/test/test_re_jy.py branches/asm/src/org/python/modules/sre/PatternObject.java Modified: branches/asm/Lib/test/test_re_jy.py =================================================================== --- branches/asm/Lib/test/test_re_jy.py 2008-07-23 20:55:03 UTC (rev 4992) +++ branches/asm/Lib/test/test_re_jy.py 2008-07-24 07:22:38 UTC (rev 4993) @@ -4,6 +4,11 @@ class ReTest(unittest.TestCase): + def test_bug_1140_addendum(self): + result = re.sub('', lambda match : None, 'foo') + self.assertEqual(result, 'foo') + self.assert_(isinstance(result, str)) + def test_unkown_groupname(self): self.assertRaises(IndexError, re.match("(?P<int>\d+)\.(\d*)", '3.14').group, Modified: branches/asm/src/org/python/modules/sre/PatternObject.java =================================================================== --- branches/asm/src/org/python/modules/sre/PatternObject.java 2008-07-23 20:55:03 UTC (rev 4992) +++ branches/asm/src/org/python/modules/sre/PatternObject.java 2008-07-24 07:22:38 UTC (rev 4993) @@ -170,22 +170,20 @@ appended = true; } - // XXX - does this break derived types? anyway, following rule enumerated in - // test_re.test_bug_1140 - + // Follows rules enumerated in test_re.test_bug_1140 PyString outstring; - if (__builtin__.isinstance(instring, PyString.TYPE) && - (buf.length() == 0 || __builtin__.isinstance(template, PyString.TYPE))) { - outstring = new PyString(buf.toString()); + if (buf.length() == 0) { + outstring = instring.createInstance(buf.toString()); + } else if (template instanceof PyUnicode || instring instanceof PyUnicode) { + outstring = Py.newUnicode(buf.toString()); + } else { + outstring = Py.newString(buf.toString()); } - else { - outstring = new PyUnicode(buf.toString()); - } - if (subn) + if (subn) { return new PyTuple(outstring, Py.newInteger(n)); - else - return outstring; + } + return outstring; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-23 20:55:05
|
Revision: 4992 http://jython.svn.sourceforge.net/jython/?rev=4992&view=rev Author: pjenvey Date: 2008-07-23 20:55:03 +0000 (Wed, 23 Jul 2008) Log Message: ----------- support the new float.__get/setformat__ classmethods -- they just claim our formats are 'unknown' Modified Paths: -------------- branches/asm/src/org/python/core/PyFloat.java Modified: branches/asm/src/org/python/core/PyFloat.java =================================================================== --- branches/asm/src/org/python/core/PyFloat.java 2008-07-23 20:36:42 UTC (rev 4991) +++ branches/asm/src/org/python/core/PyFloat.java 2008-07-23 20:55:03 UTC (rev 4992) @@ -4,6 +4,7 @@ import java.io.Serializable; import java.math.BigDecimal; +import org.python.expose.ExposedClassMethod; import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; import org.python.expose.ExposedType; @@ -579,6 +580,28 @@ return float___getnewargs__(); } + @ExposedClassMethod + public static String float___getformat__(PyType type, String typestr) { + if (!"double".equals(typestr) && !"float".equals(typestr)) { + throw Py.ValueError("__getformat__() argument 1 must be 'double' or 'float'"); + } + return "unknown"; + } + + @ExposedClassMethod + public static void float___setformat__(PyType type, String typestr, String format) { + if (!"double".equals(typestr) && !"float".equals(typestr)) { + throw Py.ValueError("__setformat__() argument 1 must be 'double' or 'float'"); + } + if ("IEEE, little-endian".equals(format) || "IEEE, big-endian".equals(format)) { + throw Py.ValueError(String.format("can only set %s format to 'unknown' or the " + + "detected platform value", typestr)); + } else if (!"unknown".equals(format)) { + throw Py.ValueError("__setformat__() argument 2 must be 'unknown', " + + "'IEEE, little-endian' or 'IEEE, big-endian'"); + } + } + public boolean isMappingType() { return false; } public boolean isSequenceType() { return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-23 20:36:44
|
Revision: 4991 http://jython.svn.sourceforge.net/jython/?rev=4991&view=rev Author: pjenvey Date: 2008-07-23 20:36:42 +0000 (Wed, 23 Jul 2008) Log Message: ----------- o fix passing chars > 256 to Py.makeCharacter o make struct.error a class and raise struct.errors instead of OverflowErrors Modified Paths: -------------- branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-23 19:13:04 UTC (rev 4990) +++ branches/asm/src/org/python/core/Py.java 2008-07-23 20:36:42 UTC (rev 4991) @@ -1444,6 +1444,11 @@ static final PyString makeCharacter(int codepoint, boolean toUnicode) { if (toUnicode) { return new PyUnicode(codepoint); + } else if (codepoint > 65536) { + throw new IllegalArgumentException(String.format("Codepoint > 65536 (%d) requires " + + "toUnicode argument", codepoint)); + } else if (codepoint > 256) { + return new PyString((char)codepoint); } if (letters == null) { Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-23 19:13:04 UTC (rev 4990) +++ branches/asm/src/org/python/modules/struct.java 2008-07-23 20:36:42 UTC (rev 4991) @@ -16,6 +16,7 @@ import org.python.core.PyLong; import org.python.core.PyObject; import org.python.core.PyString; +import org.python.core.PyStringMap; import org.python.core.PyTuple; import java.math.BigInteger; @@ -257,7 +258,7 @@ * Exception raised on various occasions; argument is a * string describing what is wrong. */ - public static PyString error = new PyString("struct.error"); + public static final PyObject error = Py.makeClass("error", Py.Exception, exceptionNamespace()); public static String __doc__ = "Functions to convert between Python values and C structs.\n" + @@ -330,8 +331,9 @@ long get_long(PyObject value) { if (value instanceof PyLong){ Object v = value.__tojava__(Long.TYPE); - if (v == Py.NoConversion) - throw Py.OverflowError("long int too long to convert"); + if (v == Py.NoConversion) { + throw StructError("long int too long to convert"); + } return ((Long) v).longValue(); } else return get_int(value); @@ -341,7 +343,7 @@ if (value instanceof PyLong){ BigInteger v = (BigInteger)value.__tojava__(BigInteger.class); if (v.compareTo(PyLong.maxULong) > 0){ - throw Py.OverflowError("unsigned long int too long to convert"); + throw StructError("unsigned long int too long to convert"); } return v; } else @@ -1041,4 +1043,10 @@ private static PyException StructError(String explanation) { return new PyException(error, explanation); } + + private static PyObject exceptionNamespace() { + PyObject dict = new PyStringMap(); + dict.__setitem__("__module__", new PyString("struct")); + return dict; + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-23 19:13:07
|
Revision: 4990 http://jython.svn.sourceforge.net/jython/?rev=4990&view=rev Author: fwierzbicki Date: 2008-07-23 19:13:04 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Made except blocks optional in PythonPartial.g since: try: Is a valid partial parse. Modified Paths: -------------- branches/asm/grammar/PythonPartial.g Modified: branches/asm/grammar/PythonPartial.g =================================================================== --- branches/asm/grammar/PythonPartial.g 2008-07-23 18:39:09 UTC (rev 4989) +++ branches/asm/grammar/PythonPartial.g 2008-07-23 19:13:04 UTC (rev 4990) @@ -376,7 +376,7 @@ try_stmt : 'try' COLON suite ( except_clause+ ('else' COLON suite)? ('finally' COLON suite)? | 'finally' COLON suite - ) + )? ; with_stmt: 'with' test (with_var)? COLON suite This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-23 18:39:12
|
Revision: 4989 http://jython.svn.sourceforge.net/jython/?rev=4989&view=rev Author: fwierzbicki Date: 2008-07-23 18:39:09 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Offset fixes for Try/Catch and Call. Modified Paths: -------------- branches/asm/grammar/Python.g branches/asm/grammar/PythonWalker.g Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-23 01:58:01 UTC (rev 4988) +++ branches/asm/grammar/Python.g 2008-07-23 18:39:09 UTC (rev 4989) @@ -818,11 +818,11 @@ // ['else' ':' suite] // ['finally' ':' suite] | // 'finally' ':' suite)) -try_stmt : 'try' COLON trysuite=suite +try_stmt : TRY COLON trysuite=suite ( (except_clause+ (ORELSE COLON elsesuite=suite)? (FINALLY COLON finalsuite=suite)? - -> ^(TryExcept 'try' ^(Body $trysuite) except_clause+ ^(ORELSE $elsesuite)? ^(FINALLY $finalsuite)?)) + -> ^(TryExcept[$TRY] ^(Body $trysuite) except_clause+ ^(ORELSE $elsesuite)? ^(FINALLY $finalsuite)?)) | (FINALLY COLON finalsuite=suite - -> ^(TryFinally 'try' ^(Body $trysuite) ^(FINALLY $finalsuite))) + -> ^(TryFinally[$TRY] ^(Body $trysuite) ^(FINALLY $finalsuite))) ) ; @@ -1158,6 +1158,7 @@ ASSERT : 'assert' ; FINALLY : 'finally' ; DELETE : 'del' ; +TRY : 'try' ; LPAREN : '(' {implicitLineJoiningLevel++;} ; Modified: branches/asm/grammar/PythonWalker.g =================================================================== --- branches/asm/grammar/PythonWalker.g 2008-07-23 01:58:01 UTC (rev 4988) +++ branches/asm/grammar/PythonWalker.g 2008-07-23 18:39:09 UTC (rev 4989) @@ -389,6 +389,7 @@ } else { c = makeCall($Call, $dotted_attr.etype, $arglist.args, $arglist.keywords, $arglist.starargs, $arglist.kwargs); } + c.setCharStopIndex($Call.getCharStopIndex()); decs.add(c); } } @@ -470,6 +471,7 @@ } else { c = makeCall($test.marker, $test.etype, $arglist.args, $arglist.keywords, $arglist.starargs, $arglist.kwargs); } + c.setCharStopIndex($Call.getCharStopIndex()); $etype = c; } ; @@ -814,7 +816,7 @@ @init { List handlers = new ArrayList(); } - : ^(TryExcept tok='try' ^(Body body=stmts) except_clause[handlers]+ (^(ORELSE orelse=stmts))? (^(FINALLY fin=stmts))?) { + : ^(TryExcept ^(Body body=stmts) except_clause[handlers]+ (^(ORELSE orelse=stmts))? (^(FINALLY fin=stmts))?) { List o = null; List f = null; if ($ORELSE != null) { @@ -823,11 +825,11 @@ if ($FINALLY != null) { f = $fin.stypes; } - stmtType te = makeTryExcept($tok, $body.stypes, handlers, o, f); + stmtType te = makeTryExcept($TryExcept, $body.stypes, handlers, o, f); $stmts::statements.add(te); } - | ^(TryFinally tok='try' ^(Body body=stmts) ^(FINALLY fin=stmts)) { - TryFinally tf = makeTryFinally($tok, $body.stypes, $fin.stypes); + | ^(TryFinally ^(Body body=stmts) ^(FINALLY fin=stmts)) { + TryFinally tf = makeTryFinally($TryFinally, $body.stypes, $fin.stypes); $stmts::statements.add(tf); } ; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-23 01:58:04
|
Revision: 4988 http://jython.svn.sourceforge.net/jython/?rev=4988&view=rev Author: fwierzbicki Date: 2008-07-23 01:58:01 +0000 (Wed, 23 Jul 2008) Log Message: ----------- Made Str offsets better match CPython. PythonTree now extends BaseTree (too much of CommonTree was getting changed anyway). astdump.py repaired so that it is a useful testing ground for ast comparisons. Modified Paths: -------------- branches/asm/ast/astdump.py branches/asm/grammar/Python.g branches/asm/src/org/python/antlr/PythonTree.java Modified: branches/asm/ast/astdump.py =================================================================== --- branches/asm/ast/astdump.py 2008-07-23 01:21:32 UTC (rev 4987) +++ branches/asm/ast/astdump.py 2008-07-23 01:58:01 UTC (rev 4988) @@ -29,9 +29,11 @@ pyfiles = [code_path] for pyfile in pyfiles: - print "%s to %s" % (pyfile, output_dir) import pprint - fh = open(makepath(os.path.join(output_dir, pyfile)), 'w') + path = pyfile.split(os.path.sep) + print "%s to %s: %s" % (pyfile, output_dir, os.path.join(output_dir, *path)) + fh = open(makepath(os.path.join(output_dir, *path)), 'w') + print fh pprint.pprint(astview.tree(pyfile), fh) if __name__ == '__main__': Modified: branches/asm/grammar/Python.g =================================================================== --- branches/asm/grammar/Python.g 2008-07-23 01:21:32 UTC (rev 4987) +++ branches/asm/grammar/Python.g 2008-07-23 01:58:01 UTC (rev 4988) @@ -393,8 +393,7 @@ } Token extractStringToken(List s) { - //XXX: really we want the *last* one. - return (Token)s.get(0); + return (Token)s.get(s.size() - 1); } @@ -956,7 +955,7 @@ | LONGINT -> ^(NumTok<Num>[$LONGINT, makeInt($LONGINT)]) | FLOAT -> ^(NumTok<Num>[$FLOAT, makeFloat($FLOAT)]) | COMPLEX -> ^(NumTok<Num>[$COMPLEX, makeComplex($COMPLEX)]) - | (S+=STRING)+ {debug("S+: " + $S);} + | (S+=STRING)+ -> ^(StrTok<Str>[extractStringToken($S), extractStrings($S)]) ; @@ -1299,7 +1298,12 @@ | '"""' (options {greedy=false;}:TRIQUOTE)* '"""' | '"' (ESC|~('\\'|'\n'|'"'))* '"' | '\'' (ESC|~('\\'|'\n'|'\''))* '\'' - ) + ) { + if (state.tokenStartLine != input.getLine()) { + state.tokenStartLine = input.getLine(); + state.tokenStartCharPositionInLine = -2; + } + } ; /** the two '"'? cause a warning -- is there a way to avoid that? */ Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-07-23 01:21:32 UTC (rev 4987) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-07-23 01:58:01 UTC (rev 4988) @@ -1,7 +1,7 @@ package org.python.antlr; import org.antlr.runtime.tree.BaseTree; -import org.antlr.runtime.tree.CommonTree; +import org.antlr.runtime.tree.Tree; import org.antlr.runtime.CommonToken; import org.antlr.runtime.Token; @@ -10,14 +10,27 @@ import org.python.antlr.ast.VisitorIF; -public class PythonTree extends CommonTree implements AST { +public class PythonTree extends BaseTree implements AST { public boolean from_future_checked = false; private int charStartIndex = -1; private int charStopIndex = -1; + /** A single token is the payload */ + public Token token; + + /** What token indexes bracket all tokens associated with this node + * and below? + */ + protected int startIndex=-1, stopIndex=-1; + + /** Who is the parent node of this node; if null, implies node is root */ + public PythonTree parent; + + /** What index is this node in the child list? Range: 0..n-1 */ + public int childIndex = -1; + public PythonTree(int ttype, Token t) { - super(); CommonToken c = new CommonToken(ttype, t.getText()); c.setLine(t.getLine()); c.setTokenIndex(t.getTokenIndex()); @@ -28,16 +41,109 @@ token = c; } - public PythonTree(Token token) { - super(token); + public PythonTree(Token t) { + this.token = t; } public PythonTree(PythonTree node) { - super(node); + super(node); + token = node.token; + startIndex = node.startIndex; + stopIndex = node.stopIndex; charStartIndex = node.getCharStartIndex(); charStopIndex = node.getCharStopIndex(); } + + public Token getToken() { + return token; + } + public Tree dupNode() { + return new PythonTree(this); + } + + public boolean isNil() { + return token==null; + } + + public int getType() { + if (token==null) { + return Token.INVALID_TOKEN_TYPE; + } + return token.getType(); + } + + public String getText() { + if (token==null) { + return null; + } + return token.getText(); + } + + public int getLine() { + if (token==null || token.getLine()==0) { + if ( getChildCount()>0 ) { + return getChild(0).getLine(); + } + return 0; + } + return token.getLine(); + } + + public int getCharPositionInLine() { + if (token==null || token.getCharPositionInLine()==-1) { + if (getChildCount()>0) { + return getChild(0).getCharPositionInLine(); + } + return 0; + } else if (token != null && token.getCharPositionInLine() == -2) { + //XXX: yucky fix because CPython's ast uses -1 as a real value + // for char pos in certain circumstances (for example, the + // char pos of multi-line strings. I would just use -1, + // but ANTLR is using -1 in special ways also. + return -1; + } + return token.getCharPositionInLine(); + } + + public int getTokenStartIndex() { + if ( startIndex==-1 && token!=null ) { + return token.getTokenIndex(); + } + return startIndex; + } + + public void setTokenStartIndex(int index) { + startIndex = index; + } + + public int getTokenStopIndex() { + if ( stopIndex==-1 && token!=null ) { + return token.getTokenIndex(); + } + return stopIndex; + } + + public void setTokenStopIndex(int index) { + stopIndex = index; + } + + public int getChildIndex() { + return childIndex; + } + + public Tree getParent() { + return parent; + } + + public void setParent(Tree t) { + this.parent = (PythonTree)t; + } + + public void setChildIndex(int index) { + this.childIndex = index; + } + public int getCharStartIndex() { if (charStartIndex == -1 && token != null) { if (token instanceof CommonToken) { @@ -54,13 +160,23 @@ charStartIndex = index; } + /* + * Adding one to stopIndex from Tokens. ANTLR defines the char position as + * being the array index of the actual characters. Most tools these days + * define document offsets as the positions between the characters. If you + * imagine drawing little boxes around each character and think of the + * numbers as pointing to either the left or right side of a character's + * box, then 0 is before the first character - and in a Document of 10 + * characters, position 10 is after the last character. + */ public int getCharStopIndex() { + if (charStopIndex == -1 && token != null) { if (token instanceof CommonToken) { - return ((CommonToken)token).getStopIndex(); + return ((CommonToken)token).getStopIndex() + 1; } if (token instanceof ImaginaryToken) { - return ((ImaginaryToken)token).getStopIndex(); + return ((ImaginaryToken)token).getStopIndex() + 1; } } return charStopIndex; @@ -74,6 +190,13 @@ if (isNil()) { return "None"; } + if ( getType()==Token.INVALID_TOKEN_TYPE ) { + return "<errornode>"; + } + if ( token==null ) { + return null; + } + return token.getText() + "(" + this.getLine() + "," + this.getCharPositionInLine() + ")"; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-23 01:21:35
|
Revision: 4987 http://jython.svn.sourceforge.net/jython/?rev=4987&view=rev Author: pjenvey Date: 2008-07-23 01:21:32 +0000 (Wed, 23 Jul 2008) Log Message: ----------- many various PyArray fixes for 2.5 test_array Modified Paths: -------------- branches/asm/Lib/test/test_array.py branches/asm/src/org/python/core/PyArray.java Modified: branches/asm/Lib/test/test_array.py =================================================================== --- branches/asm/Lib/test/test_array.py 2008-07-23 01:19:34 UTC (rev 4986) +++ branches/asm/Lib/test/test_array.py 2008-07-23 01:21:32 UTC (rev 4987) @@ -9,6 +9,10 @@ import array, cStringIO, math from cPickle import loads, dumps +if test_support.is_jython: + import operator + from test_weakref import extra_collect + class ArraySubclass(array.array): pass @@ -308,7 +312,10 @@ array.array(self.typecode) ) - self.assertRaises(TypeError, a.__mul__, "bad") + if test_support.is_jython: + self.assertRaises(TypeError, operator.mul, a, "bad") + else: + self.assertRaises(TypeError, a.__mul__, "bad") def test_imul(self): a = array.array(self.typecode, self.example) @@ -337,7 +344,10 @@ a *= -1 self.assertEqual(a, array.array(self.typecode)) - self.assertRaises(TypeError, a.__imul__, "bad") + if test_support.is_jython: + self.assertRaises(TypeError, operator.imul, a, "bad") + else: + self.assertRaises(TypeError, a.__imul__, "bad") def test_getitem(self): a = array.array(self.typecode, self.example) @@ -690,6 +700,8 @@ p = proxy(s) self.assertEqual(p.tostring(), s.tostring()) s = None + if test_support.is_jython: + extra_collect() self.assertRaises(ReferenceError, len, p) def test_bug_782369(self): @@ -898,7 +910,13 @@ def test_overflow(self): a = array.array(self.typecode) lower = 0 - upper = long(pow(2, a.itemsize * 8)) - 1L + itemsize = a.itemsize + if test_support.is_jython: + # XXX: unsigned itemsizes are larger than would be expected + # in CPython + itemsize /= 2 + #upper = long(pow(2, a.itemsize * 8)) - 1L + upper = long(pow(2, itemsize * 8)) - 1L self.check_overflow(lower, upper) @@ -980,6 +998,13 @@ def test_main(verbose=None): import sys + if test_support.is_jython: + # CPython specific; returns a memory address + del BaseTest.test_buffer_info + + # No buffers in Jython + del BaseTest.test_buffer + test_support.run_unittest(*tests) # verify reference counting Modified: branches/asm/src/org/python/core/PyArray.java =================================================================== --- branches/asm/src/org/python/core/PyArray.java 2008-07-23 01:19:34 UTC (rev 4986) +++ branches/asm/src/org/python/core/PyArray.java 2008-07-23 01:21:32 UTC (rev 4987) @@ -27,88 +27,104 @@ * <p> * See also the jarray module. */ -@ExposedType(name = "array", base = PyObject.class) +@ExposedType(name = "array.array", base = PyObject.class) public class PyArray extends PySequence implements Cloneable { public static final PyType TYPE = PyType.fromClass(PyArray.class); - + + /** The underlying Java array. */ private Object data; + /** The Java array class. */ private Class type; + /** The Python style typecode of the array. */ private String typecode; private ArrayDelegate delegate; - // PyArray can't extend anymore, so delegate - private class ArrayDelegate extends AbstractArray { + public PyArray(PyType type) { + super(type); + } + public PyArray(Class type, Object data) { + this(TYPE); + setup(type, data); + } - private ArrayDelegate() { - super(data == null ? 0 : Array.getLength(data)); - } - - protected Object getArray() { - return data; - } - - protected void setArray(Object array) { - data = array; - } - - @Override - protected Object createArray(int size) { - Class baseType = data.getClass().getComponentType(); - return Array.newInstance(baseType, size); - } + public PyArray(Class type, int n) { + this(type, Array.newInstance(type, n)); } - - public PyArray(PyType type){ - super(type); - } public PyArray(PyArray toCopy) { - data = toCopy.delegate.copyArray(); - delegate = new ArrayDelegate(); - type = toCopy.type; + this(toCopy.type, toCopy.delegate.copyArray()); + typecode = toCopy.typecode; } - public PyArray(Class type, Object data) { + private void setup(Class type, Object data) { this.type = type; - this.data = data; + typecode = class2char(type); + if (data == null) { + this.data = Array.newInstance(type, 0); + } else { + this.data = data; + } delegate = new ArrayDelegate(); } - public PyArray(Class type, int n) { - this(type, Array.newInstance(type, n)); - } - - @ExposedMethod @ExposedNew - final void array_init(PyObject[] args, String[] kwds) { - ArgParser ap = new ArgParser("array", args, kwds, new String[] {"typecode", "seq"}, 1); + static final PyObject array_new(PyNewWrapper new_, boolean init, PyType subtype, + PyObject[] args, String[] keywords) { + if (new_.for_type != subtype && keywords.length > 0) { + int argc = args.length - keywords.length; + PyObject[] justArgs = new PyObject[argc]; + System.arraycopy(args, 0, justArgs, 0, argc); + args = justArgs; + } + ArgParser ap = new ArgParser("array", args, Py.NoKeywords, new String[] {"typecode", "initializer"}, + 1); + ap.noKeywords(); PyObject obj = ap.getPyObject(0); - if (obj instanceof PyString) { - String code = obj.toString(); - if (code.length() != 1) { + PyObject initial = ap.getPyObject(1, null); + + Class type; + String typecode; + if (obj instanceof PyString && !(obj instanceof PyUnicode)) { + if (obj.__len__() != 1) { throw Py.TypeError("array() argument 1 must be char, not str"); } - type = char2class(code.charAt(0)); - typecode = code; + typecode = obj.toString(); + type = char2class(typecode.charAt(0)); } else if (obj instanceof PyJavaClass) { type = ((PyJavaClass)obj).proxyClass; typecode = type.getName(); } else { - throw Py.TypeError("array() argument 1 must be char, not " + - obj.getType().fastGetName()); + throw Py.TypeError("array() argument 1 must be char, not " + obj.getType().fastGetName()); } - data = Array.newInstance(type, 0); - delegate = new ArrayDelegate(); - PyObject seq = ap.getPyObject(1, null); - if (seq == null) { - return; + + PyArray self; + if (new_.for_type == subtype) { + self = new PyArray(subtype); + } else { + self = new PyArrayDerived(subtype); } - extendInternal(seq); + // Initialize the typecode (and validate type) before creating the backing Array + class2char(type); + self.setup(type, Array.newInstance(type, 0)); + self.typecode = typecode; + if (initial == null) { + return self; + } + if (initial instanceof PyList) { + self.fromlist(initial); + } else if (initial instanceof PyString && !(initial instanceof PyUnicode)) { + self.fromstring(initial.toString()); + } else if (initial instanceof PyUnicode && "u".equals(typecode)) { + self.fromunicode(initial.toString()); + } else { + self.extendInternal(initial); + } + return self; } public static PyArray zeros(int n, char typecode) { @@ -230,6 +246,74 @@ seq___delslice__(start, stop, step); } + public PyObject __imul__(PyObject o) { + return array___imul__(o); + } + + @ExposedMethod(type = MethodType.BINARY) + final PyObject array___imul__(PyObject o) { + if(!(o instanceof PyInteger || o instanceof PyLong)) { + return null; + } + if (delegate.getSize() > 0) { + int count = o.asInt(); + if (count <= 0) { + delegate.clear(); + return this; + } + Object copy = delegate.copyArray(); + delegate.ensureCapacity(delegate.getSize() * count); + for (int i = 1; i < count; i++) { + delegate.appendArray(copy); + } + } + return this; + } + + public PyObject __mul__(PyObject o) { + return array___mul__(o); + } + + @ExposedMethod(type = MethodType.BINARY) + final PyObject array___mul__(PyObject o) { + if(!(o instanceof PyInteger || o instanceof PyLong)) { + return null; + } + return repeat(o.asInt()); + } + + public PyObject __rmul__(PyObject o) { + return array___rmul__(o); + } + + @ExposedMethod(type = MethodType.BINARY) + final PyObject array___rmul__(PyObject o) { + if(!(o instanceof PyInteger || o instanceof PyLong)) { + return null; + } + return repeat(o.asInt()); + } + + public PyObject __iadd__(PyObject other) { + return array___iadd__(other); + } + + @ExposedMethod + final PyObject array___iadd__(PyObject other) { + PyArray otherArr = null; + if (!(other instanceof PyArray)) { + throw Py.TypeError(String.format("can only append array (not \"%.200s\") to array", + other.getType().fastGetName())); + } + otherArr = (PyArray)other; + if (!otherArr.typecode.equals(this.typecode)) { + throw Py.TypeError("can only append arrays of the same type, " + + "expected '" + this.type + ", found " + otherArr.type); + } + delegate.appendArray(otherArr.delegate.copyArray()); + return this; + } + public PyObject __add__(PyObject other) { return array___add__(other); } @@ -248,7 +332,7 @@ throw Py.TypeError("can only append another array to an array"); } otherArr = (PyArray)other; - if(!otherArr.type.equals(this.type)) { + if(!otherArr.typecode.equals(this.typecode)) { throw Py.TypeError("can only append arrays of the same type, " + "expected '" + this.type + ", found " + otherArr.type); } @@ -266,25 +350,38 @@ return delegate.getSize(); } - /** - * String representation of PyArray - * - * @return string representation of PyArray - */ - public PyString __repr__() { - StringBuffer buf = new StringBuffer(128); - buf.append("array(").append(class2char(type)).append(",["); - for(int i = 0; i < __len__() - 1; i++) { - buf.append(pyget(i).__repr__().toString()); - buf.append(", "); + public PyObject __reduce__() { + return array___reduce__(); + } + + @ExposedMethod + final PyObject array___reduce__() { + PyObject dict = __findattr__("__dict__"); + if (dict == null) { + dict = Py.None; } - if(__len__() > 0) { - buf.append(pyget(__len__() - 1).__repr__().toString()); + if (__len__() > 0) { + return new PyTuple(getType(), new PyTuple(Py.newString(typecode), + Py.newString(tostring())), dict); + } else { + return new PyTuple(getType(), new PyTuple(Py.newString(typecode)), dict); } - buf.append("]) "); - return new PyString(buf.toString()); } + @Override + public String toString() { + if (__len__() == 0) { + return String.format("array('%s')", typecode); + } + String value; + if ("c".equals(typecode)) { + value = tostring(); + } else { + value = tolist().toString(); + } + return String.format("array('%s', %s)", typecode, value); + } + /** * * @param c @@ -340,8 +437,7 @@ * written on a machine with a different byte order. */ public void byteswap() { - // unknown type - throw RuntimeError - if(getItemsize() == 0) { + if (getItemsize() == 0) { throw Py.RuntimeError("don't know how to byteswap this array type"); } ByteSwapper.swap(data); @@ -431,7 +527,7 @@ case 'l': return Long.TYPE; case 'L': - return PyLong.class; + return Long.TYPE; case 'f': return Float.TYPE; case 'd': @@ -443,21 +539,21 @@ private static String class2char(Class cls) { if(cls.equals(Boolean.TYPE)) - return "'z'"; + return "z"; else if(cls.equals(Character.TYPE)) - return "'c'"; + return "c"; else if(cls.equals(Byte.TYPE)) - return "'b'"; + return "b"; else if(cls.equals(Short.TYPE)) - return "'h'"; + return "h"; else if(cls.equals(Integer.TYPE)) - return "'i'"; + return "i"; else if(cls.equals(Long.TYPE)) - return "'l'"; + return "l"; else if(cls.equals(Float.TYPE)) - return "'f'"; + return "f"; else if(cls.equals(Double.TYPE)) - return "'d'"; + return "d"; else return cls.getName(); } @@ -508,17 +604,18 @@ * stepping increment between start and stop */ protected void delRange(int start, int stop, int step) { - // Now the AbstractArray can support this: - // throw Py.TypeError("can't remove from array"); - if(step > 0 && stop < start) - stop = start; - if(step == 1) { + if (step == 1) { delegate.remove(start, stop); - } else { - int n = sliceLength(start, stop, step); - for(int i = start, j = 0; j < n; i += step, j++) { + } else if (step > 1) { + for (int i = start; i < stop; i += step) { delegate.remove(i); + i--; + stop--; } + } else if (step < 0) { + for (int i = start; i >= 0 && i >= stop; i += step) { + delegate.remove(i); + } } } @@ -554,13 +651,13 @@ */ private void extendInternal(PyObject iterable) { // string input - if(iterable instanceof PyString) { + if (iterable instanceof PyString) { fromstring(((PyString)iterable).toString()); // PyArray input - } else if(iterable instanceof PyArray) { + } else if (iterable instanceof PyArray) { PyArray source = (PyArray)iterable; - if(!source.type.equals(this.type)) { - throw Py.TypeError("can only extend with an array of the same kind"); + if (!source.typecode.equals(typecode)) { + throw Py.TypeError("can only extend with array of same kind"); } delegate.appendArray(source.delegate.copyArray()); } else { @@ -647,9 +744,9 @@ * input list object that will be appended to the array */ public void fromlist(PyObject obj) { - // check for list - if(!(obj instanceof PyList)) - throw Py.TypeError("expected list argument"); + if(!(obj instanceof PyList)) { + throw Py.TypeError("arg must be list"); + } // store the current size of the internal array int size = delegate.getSize(); try { @@ -714,7 +811,7 @@ } } else if(type == Character.TYPE) { for(int i = 0; i < count; i++, index++) { - Array.setChar(data, index, (char)dis.readByte()); + Array.setChar(data, index, (char)(dis.readByte() & 0xff)); delegate.size++; } } else if(type == Integer.TYPE) { @@ -748,6 +845,10 @@ return (index - origsize); } + public void fromstring(String input) { + array_fromstring(input); + } + /** * Appends items from the string, interpreting the string as an array of * machine values (as if it had been read from a file using the @@ -756,7 +857,8 @@ * @param input * string of bytes containing array data */ - public void fromstring(String input) { + @ExposedMethod + final void array_fromstring(String input) { int itemsize = getItemsize(); int strlen = input.length(); if((strlen % itemsize) != 0) { @@ -776,6 +878,18 @@ } } + public void fromunicode(String input) { + array_fromunicode(input); + } + + @ExposedMethod + final void array_fromunicode(String input) { + if (!"u".equals(typecode)) { + throw Py.ValueError("fromunicode() may only be called on type 'u' arrays"); + } + array_fromstring(input); + } + /** * Get the element at position <em>i</em> from the array * @@ -888,15 +1002,18 @@ * @return A new PyArray object containing the described slice */ protected PyObject getslice(int start, int stop, int step) { - if(step > 0 && stop < start) + if (step > 0 && stop < start) { stop = start; + } int n = sliceLength(start, stop, step); PyArray ret = new PyArray(type, n); - if(step == 1) { + // XXX: + ret.typecode = typecode; + if (step == 1) { System.arraycopy(data, start, ret.data, 0, n); return ret; } - for(int i = start, j = 0; j < n; i += step, j++) { + for (int i = start, j = 0; j < n; i += step, j++) { Array.set(ret.data, j, Array.get(data, i)); } return ret; @@ -969,6 +1086,7 @@ * value to be inserted into array */ public void insert(int index, PyObject value) { + index = calculateIndex(index); delegate.makeInsertSpace(index); Array.set(data, index, Py.tojava(value, type)); } @@ -997,8 +1115,13 @@ * @return array element popped from index */ public PyObject pop(int index) { - // todo: python-style error handling - index = (index < 0) ? delegate.getSize() + index : index; + if (delegate.getSize() == 0) { + throw Py.IndexError("pop from empty array"); + } + index = fixindex(index); + if (index == -1) { + throw Py.IndexError("pop index out of range"); + } PyObject ret = Py.java2py(Array.get(data, index)); delegate.remove(index); return ret; @@ -1036,6 +1159,8 @@ protected PyObject repeat(int count) { Object arraycopy = delegate.copyArray(); PyArray ret = new PyArray(type, 0); + // XXX: + ret.typecode = typecode; for(int i = 0; i < count; i++) { ret.delegate.appendArray(arraycopy); } @@ -1085,9 +1210,9 @@ } catch(ClassCastException e) { throw Py.TypeError("Type not compatible with array type"); } - if(val < Byte.MIN_VALUE) { + if(val < (isSigned() ? 0 : Byte.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > Byte.MAX_VALUE) { + } else if(val > (isSigned() ? Byte.MAX_VALUE * 2 + 1 : Byte.MAX_VALUE)) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Short.TYPE) { @@ -1097,9 +1222,9 @@ } catch(ClassCastException e) { throw Py.TypeError("Type not compatible with array type"); } - if(val < Short.MIN_VALUE) { + if(val < (isSigned() ? 0 : Short.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > Short.MAX_VALUE) { + } else if(val > (isSigned() ? Byte.MAX_VALUE * 2 + 1 : Short.MAX_VALUE)) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Integer.TYPE) { @@ -1109,21 +1234,30 @@ } catch(ClassCastException e) { throw Py.TypeError("Type not compatible with array type"); } - if(val < Integer.MIN_VALUE) { + if(val < (isSigned() ? 0 : Integer.MIN_VALUE)) { throw Py.OverflowError("value too small for " + type.getName()); - } else if(val > Integer.MAX_VALUE) { + } else if(val > (isSigned() ? Short.MAX_VALUE * 2 + 1 : Integer.MAX_VALUE)) { throw Py.OverflowError("value too large for " + type.getName()); } } else if(type == Long.TYPE) { - Object o; - try { - o = value.__tojava__(Long.TYPE); - } catch(ClassCastException e) { - throw Py.TypeError("Type not compatible with array type"); + if (isSigned() && value instanceof PyInteger) { + if (((PyInteger)value).getValue() < 0) { + throw Py.OverflowError("value too small for " + type.getName()); + } + } else if (value instanceof PyLong) { + ((PyLong)value).getLong(isSigned() ? 0 : Long.MIN_VALUE, + Long.MAX_VALUE); + } else { + Object o; + try { + o = value.__tojava__(Long.TYPE); + } catch(ClassCastException e) { + throw Py.TypeError("Type not compatible with array type"); + } + if(o == Py.NoConversion) { + throw Py.TypeError("Type not compatible with array type"); + } } - if(o == Py.NoConversion) { - throw Py.OverflowError("value out of range for long"); - } } Object o = Py.tojava(value, type); if(o == Py.NoConversion) { @@ -1132,6 +1266,10 @@ Array.set(data, i, o); } + private boolean isSigned() { + return typecode.length() == 1 && typecode.equals(typecode.toUpperCase()); + } + /** * Sets a slice of the array. <em>value</em> can be a string (for * <code>byte</code> and <code>char</code> types) or PyArray. If a @@ -1146,6 +1284,9 @@ * stepping increment of the slice */ protected void setslice(int start, int stop, int step, PyObject value) { + if (stop < start) { + stop = start; + } if(type == Character.TYPE && value instanceof PyString) { char[] chars = null; // if (value instanceof PyString) { @@ -1153,20 +1294,7 @@ throw Py.ValueError("invalid bounds for setting from string"); } chars = value.toString().toCharArray(); - // } - // else if (value instanceof PyArray && - // ((PyArray)value).type == Character.TYPE) { - // PyArray other = (PyArray)value; - // chars = (char[])other.delegate.copyArray(); - // } - int insertSpace = chars.length - (stop - start); - // adjust the array, either adding space or removing space - if(insertSpace > 0) { - delegate.makeInsertSpace(start, insertSpace); - } else if(insertSpace < 0) { - delegate.remove(start, -insertSpace + start - 1); - } - delegate.replaceSubArray(chars, start); + delegate.replaceSubArray(start, stop, chars, 0, chars.length); } else { if(value instanceof PyString && type == Byte.TYPE) { byte[] chars = ((PyString)value).toBytes(); @@ -1177,22 +1305,40 @@ } } else if(value instanceof PyArray) { PyArray array = (PyArray)value; - int insertSpace = array.delegate.getSize() - (stop - start); - // adjust the array, either adding space or removing space - // ...snapshot in case "value" is "this" - Object arrayCopy = array.delegate.copyArray(); - if(insertSpace > 0) { - delegate.makeInsertSpace(start, insertSpace); - } else if(insertSpace < 0) { - delegate.remove(start, -insertSpace + start - 1); + if (!array.typecode.equals(typecode)) { + throw Py.TypeError("bad argument type for built-in operation|" + array.typecode + "|" + typecode); } - try { - delegate.replaceSubArray(arrayCopy, start); - } catch(IllegalArgumentException e) { - throw Py.TypeError("Slice typecode '" + array.typecode - + "' is not compatible with this array (typecode '" - + this.typecode + "')"); + if (step == 1) { + Object arrayDelegate; + if (array == this) { + arrayDelegate = array.delegate.copyArray(); + } else { + arrayDelegate = array.delegate.getArray(); + } + try { + delegate.replaceSubArray(start, stop, arrayDelegate, 0, array.delegate.getSize()); + } catch(IllegalArgumentException e) { + throw Py.TypeError("Slice typecode '" + array.typecode + + "' is not compatible with this array (typecode '" + + this.typecode + "')"); + } + } else if (step > 1) { + int len = array.__len__(); + for (int i = 0, j = 0; i < len; i++, j += step) { + Array.set(data, j + start, Array.get(array.data, i)); + } + } else if (step < 0) { + if (array == this) { + array = (PyArray)array.clone(); + } + int len = array.__len__(); + for (int i = 0, j = delegate.getSize() - 1; i < len; i++, j += step) { + Array.set(data, j, Array.get(array.data, i)); + } } + } else { + throw Py.TypeError(String.format("can only assign array (not \"%.200s\") to array " + + "slice", value.getType().fastGetName())); } } } @@ -1304,4 +1450,34 @@ } return StringUtil.fromBytes(bos.toByteArray()); } + + @ExposedMethod + public final PyObject array_tounicode() { + if (!"u".equals(typecode)) { + throw Py.ValueError("tounicode() may only be called on type 'u' arrays"); + } + return new PyUnicode(tostring()); + } + + // PyArray can't extend anymore, so delegate + private class ArrayDelegate extends AbstractArray { + + private ArrayDelegate() { + super(data == null ? 0 : Array.getLength(data)); + } + + protected Object getArray() { + return data; + } + + protected void setArray(Object array) { + data = array; + } + + @Override + protected Object createArray(int size) { + Class baseType = data.getClass().getComponentType(); + return Array.newInstance(baseType, size); + } + } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-23 01:19:38
|
Revision: 4986 http://jython.svn.sourceforge.net/jython/?rev=4986&view=rev Author: pjenvey Date: 2008-07-23 01:19:34 +0000 (Wed, 23 Jul 2008) Log Message: ----------- from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_array.py@60839 Added Paths: ----------- branches/asm/Lib/test/test_array.py Added: branches/asm/Lib/test/test_array.py =================================================================== --- branches/asm/Lib/test/test_array.py (rev 0) +++ branches/asm/Lib/test/test_array.py 2008-07-23 01:19:34 UTC (rev 4986) @@ -0,0 +1,996 @@ +#! /usr/bin/env python +"""Test the arraymodule. + Roger E. Masse +""" + +import unittest +from test import test_support +from weakref import proxy +import array, cStringIO, math +from cPickle import loads, dumps + +class ArraySubclass(array.array): + pass + +class ArraySubclassWithKwargs(array.array): + def __init__(self, typecode, newarg=None): + array.array.__init__(typecode) + +tests = [] # list to accumulate all tests +typecodes = "cubBhHiIlLfd" + +class BadConstructorTest(unittest.TestCase): + + def test_constructor(self): + self.assertRaises(TypeError, array.array) + self.assertRaises(TypeError, array.array, spam=42) + self.assertRaises(TypeError, array.array, 'xx') + self.assertRaises(ValueError, array.array, 'x') + +tests.append(BadConstructorTest) + +class BaseTest(unittest.TestCase): + # Required class attributes (provided by subclasses + # typecode: the typecode to test + # example: an initializer usable in the constructor for this type + # smallerexample: the same length as example, but smaller + # biggerexample: the same length as example, but bigger + # outside: An entry that is not in example + # minitemsize: the minimum guaranteed itemsize + + def assertEntryEqual(self, entry1, entry2): + self.assertEqual(entry1, entry2) + + def badtypecode(self): + # Return a typecode that is different from our own + return typecodes[(typecodes.index(self.typecode)+1) % len(typecodes)] + + def test_constructor(self): + a = array.array(self.typecode) + self.assertEqual(a.typecode, self.typecode) + self.assert_(a.itemsize>=self.minitemsize) + self.assertRaises(TypeError, array.array, self.typecode, None) + + def test_len(self): + a = array.array(self.typecode) + a.append(self.example[0]) + self.assertEqual(len(a), 1) + + a = array.array(self.typecode, self.example) + self.assertEqual(len(a), len(self.example)) + + def test_buffer_info(self): + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.buffer_info, 42) + bi = a.buffer_info() + self.assert_(isinstance(bi, tuple)) + self.assertEqual(len(bi), 2) + self.assert_(isinstance(bi[0], (int, long))) + self.assert_(isinstance(bi[1], int)) + self.assertEqual(bi[1], len(a)) + + def test_byteswap(self): + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.byteswap, 42) + if a.itemsize in (1, 2, 4, 8): + b = array.array(self.typecode, self.example) + b.byteswap() + if a.itemsize==1: + self.assertEqual(a, b) + else: + self.assertNotEqual(a, b) + b.byteswap() + self.assertEqual(a, b) + + def test_copy(self): + import copy + a = array.array(self.typecode, self.example) + b = copy.copy(a) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + + def test_deepcopy(self): + import copy + a = array.array(self.typecode, self.example) + b = copy.deepcopy(a) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + + def test_pickle(self): + for protocol in (0, 1, 2): + a = array.array(self.typecode, self.example) + b = loads(dumps(a, protocol)) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + + a = ArraySubclass(self.typecode, self.example) + a.x = 10 + b = loads(dumps(a, protocol)) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + self.assertEqual(a.x, b.x) + self.assertEqual(type(a), type(b)) + + def test_pickle_for_empty_array(self): + for protocol in (0, 1, 2): + a = array.array(self.typecode) + b = loads(dumps(a, protocol)) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + + a = ArraySubclass(self.typecode) + a.x = 10 + b = loads(dumps(a, protocol)) + self.assertNotEqual(id(a), id(b)) + self.assertEqual(a, b) + self.assertEqual(a.x, b.x) + self.assertEqual(type(a), type(b)) + + def test_insert(self): + a = array.array(self.typecode, self.example) + a.insert(0, self.example[0]) + self.assertEqual(len(a), 1+len(self.example)) + self.assertEqual(a[0], a[1]) + self.assertRaises(TypeError, a.insert) + self.assertRaises(TypeError, a.insert, None) + self.assertRaises(TypeError, a.insert, 0, None) + + a = array.array(self.typecode, self.example) + a.insert(-1, self.example[0]) + self.assertEqual( + a, + array.array( + self.typecode, + self.example[:-1] + self.example[:1] + self.example[-1:] + ) + ) + + a = array.array(self.typecode, self.example) + a.insert(-1000, self.example[0]) + self.assertEqual( + a, + array.array(self.typecode, self.example[:1] + self.example) + ) + + a = array.array(self.typecode, self.example) + a.insert(1000, self.example[0]) + self.assertEqual( + a, + array.array(self.typecode, self.example + self.example[:1]) + ) + + def test_tofromfile(self): + a = array.array(self.typecode, 2*self.example) + self.assertRaises(TypeError, a.tofile) + self.assertRaises(TypeError, a.tofile, cStringIO.StringIO()) + f = open(test_support.TESTFN, 'wb') + try: + a.tofile(f) + f.close() + b = array.array(self.typecode) + f = open(test_support.TESTFN, 'rb') + self.assertRaises(TypeError, b.fromfile) + self.assertRaises( + TypeError, + b.fromfile, + cStringIO.StringIO(), len(self.example) + ) + b.fromfile(f, len(self.example)) + self.assertEqual(b, array.array(self.typecode, self.example)) + self.assertNotEqual(a, b) + b.fromfile(f, len(self.example)) + self.assertEqual(a, b) + self.assertRaises(EOFError, b.fromfile, f, 1) + f.close() + finally: + if not f.closed: + f.close() + test_support.unlink(test_support.TESTFN) + + def test_tofromlist(self): + a = array.array(self.typecode, 2*self.example) + b = array.array(self.typecode) + self.assertRaises(TypeError, a.tolist, 42) + self.assertRaises(TypeError, b.fromlist) + self.assertRaises(TypeError, b.fromlist, 42) + self.assertRaises(TypeError, b.fromlist, [None]) + b.fromlist(a.tolist()) + self.assertEqual(a, b) + + def test_tofromstring(self): + a = array.array(self.typecode, 2*self.example) + b = array.array(self.typecode) + self.assertRaises(TypeError, a.tostring, 42) + self.assertRaises(TypeError, b.fromstring) + self.assertRaises(TypeError, b.fromstring, 42) + b.fromstring(a.tostring()) + self.assertEqual(a, b) + if a.itemsize>1: + self.assertRaises(ValueError, b.fromstring, "x") + + def test_repr(self): + a = array.array(self.typecode, 2*self.example) + self.assertEqual(a, eval(repr(a), {"array": array.array})) + + a = array.array(self.typecode) + self.assertEqual(repr(a), "array('%s')" % self.typecode) + + def test_str(self): + a = array.array(self.typecode, 2*self.example) + str(a) + + def test_cmp(self): + a = array.array(self.typecode, self.example) + self.assert_((a == 42) is False) + self.assert_((a != 42) is True) + + self.assert_((a == a) is True) + self.assert_((a != a) is False) + self.assert_((a < a) is False) + self.assert_((a <= a) is True) + self.assert_((a > a) is False) + self.assert_((a >= a) is True) + + al = array.array(self.typecode, self.smallerexample) + ab = array.array(self.typecode, self.biggerexample) + + self.assert_((a == 2*a) is False) + self.assert_((a != 2*a) is True) + self.assert_((a < 2*a) is True) + self.assert_((a <= 2*a) is True) + self.assert_((a > 2*a) is False) + self.assert_((a >= 2*a) is False) + + self.assert_((a == al) is False) + self.assert_((a != al) is True) + self.assert_((a < al) is False) + self.assert_((a <= al) is False) + self.assert_((a > al) is True) + self.assert_((a >= al) is True) + + self.assert_((a == ab) is False) + self.assert_((a != ab) is True) + self.assert_((a < ab) is True) + self.assert_((a <= ab) is True) + self.assert_((a > ab) is False) + self.assert_((a >= ab) is False) + + def test_add(self): + a = array.array(self.typecode, self.example) \ + + array.array(self.typecode, self.example[::-1]) + self.assertEqual( + a, + array.array(self.typecode, self.example + self.example[::-1]) + ) + + b = array.array(self.badtypecode()) + self.assertRaises(TypeError, a.__add__, b) + + self.assertRaises(TypeError, a.__add__, "bad") + + def test_iadd(self): + a = array.array(self.typecode, self.example[::-1]) + b = a + a += array.array(self.typecode, 2*self.example) + self.assert_(a is b) + self.assertEqual( + a, + array.array(self.typecode, self.example[::-1]+2*self.example) + ) + + b = array.array(self.badtypecode()) + self.assertRaises(TypeError, a.__add__, b) + + self.assertRaises(TypeError, a.__iadd__, "bad") + + def test_mul(self): + a = 5*array.array(self.typecode, self.example) + self.assertEqual( + a, + array.array(self.typecode, 5*self.example) + ) + + a = array.array(self.typecode, self.example)*5 + self.assertEqual( + a, + array.array(self.typecode, self.example*5) + ) + + a = 0*array.array(self.typecode, self.example) + self.assertEqual( + a, + array.array(self.typecode) + ) + + a = (-1)*array.array(self.typecode, self.example) + self.assertEqual( + a, + array.array(self.typecode) + ) + + self.assertRaises(TypeError, a.__mul__, "bad") + + def test_imul(self): + a = array.array(self.typecode, self.example) + b = a + + a *= 5 + self.assert_(a is b) + self.assertEqual( + a, + array.array(self.typecode, 5*self.example) + ) + + a *= 0 + self.assert_(a is b) + self.assertEqual(a, array.array(self.typecode)) + + a *= 1000 + self.assert_(a is b) + self.assertEqual(a, array.array(self.typecode)) + + a *= -1 + self.assert_(a is b) + self.assertEqual(a, array.array(self.typecode)) + + a = array.array(self.typecode, self.example) + a *= -1 + self.assertEqual(a, array.array(self.typecode)) + + self.assertRaises(TypeError, a.__imul__, "bad") + + def test_getitem(self): + a = array.array(self.typecode, self.example) + self.assertEntryEqual(a[0], self.example[0]) + self.assertEntryEqual(a[0L], self.example[0]) + self.assertEntryEqual(a[-1], self.example[-1]) + self.assertEntryEqual(a[-1L], self.example[-1]) + self.assertEntryEqual(a[len(self.example)-1], self.example[-1]) + self.assertEntryEqual(a[-len(self.example)], self.example[0]) + self.assertRaises(TypeError, a.__getitem__) + self.assertRaises(IndexError, a.__getitem__, len(self.example)) + self.assertRaises(IndexError, a.__getitem__, -len(self.example)-1) + + def test_setitem(self): + a = array.array(self.typecode, self.example) + a[0] = a[-1] + self.assertEntryEqual(a[0], a[-1]) + + a = array.array(self.typecode, self.example) + a[0L] = a[-1] + self.assertEntryEqual(a[0], a[-1]) + + a = array.array(self.typecode, self.example) + a[-1] = a[0] + self.assertEntryEqual(a[0], a[-1]) + + a = array.array(self.typecode, self.example) + a[-1L] = a[0] + self.assertEntryEqual(a[0], a[-1]) + + a = array.array(self.typecode, self.example) + a[len(self.example)-1] = a[0] + self.assertEntryEqual(a[0], a[-1]) + + a = array.array(self.typecode, self.example) + a[-len(self.example)] = a[-1] + self.assertEntryEqual(a[0], a[-1]) + + self.assertRaises(TypeError, a.__setitem__) + self.assertRaises(TypeError, a.__setitem__, None) + self.assertRaises(TypeError, a.__setitem__, 0, None) + self.assertRaises( + IndexError, + a.__setitem__, + len(self.example), self.example[0] + ) + self.assertRaises( + IndexError, + a.__setitem__, + -len(self.example)-1, self.example[0] + ) + + def test_delitem(self): + a = array.array(self.typecode, self.example) + del a[0] + self.assertEqual( + a, + array.array(self.typecode, self.example[1:]) + ) + + a = array.array(self.typecode, self.example) + del a[-1] + self.assertEqual( + a, + array.array(self.typecode, self.example[:-1]) + ) + + a = array.array(self.typecode, self.example) + del a[len(self.example)-1] + self.assertEqual( + a, + array.array(self.typecode, self.example[:-1]) + ) + + a = array.array(self.typecode, self.example) + del a[-len(self.example)] + self.assertEqual( + a, + array.array(self.typecode, self.example[1:]) + ) + + self.assertRaises(TypeError, a.__delitem__) + self.assertRaises(TypeError, a.__delitem__, None) + self.assertRaises(IndexError, a.__delitem__, len(self.example)) + self.assertRaises(IndexError, a.__delitem__, -len(self.example)-1) + + def test_getslice(self): + a = array.array(self.typecode, self.example) + self.assertEqual(a[:], a) + + self.assertEqual( + a[1:], + array.array(self.typecode, self.example[1:]) + ) + + self.assertEqual( + a[:1], + array.array(self.typecode, self.example[:1]) + ) + + self.assertEqual( + a[:-1], + array.array(self.typecode, self.example[:-1]) + ) + + self.assertEqual( + a[-1:], + array.array(self.typecode, self.example[-1:]) + ) + + self.assertEqual( + a[-1:-1], + array.array(self.typecode) + ) + + self.assertEqual( + a[2:1], + array.array(self.typecode) + ) + + self.assertEqual( + a[1000:], + array.array(self.typecode) + ) + self.assertEqual(a[-1000:], a) + self.assertEqual(a[:1000], a) + self.assertEqual( + a[:-1000], + array.array(self.typecode) + ) + self.assertEqual(a[-1000:1000], a) + self.assertEqual( + a[2000:1000], + array.array(self.typecode) + ) + + def test_setslice(self): + a = array.array(self.typecode, self.example) + a[:1] = a + self.assertEqual( + a, + array.array(self.typecode, self.example + self.example[1:]) + ) + + a = array.array(self.typecode, self.example) + a[:-1] = a + self.assertEqual( + a, + array.array(self.typecode, self.example + self.example[-1:]) + ) + + a = array.array(self.typecode, self.example) + a[-1:] = a + self.assertEqual( + a, + array.array(self.typecode, self.example[:-1] + self.example) + ) + + a = array.array(self.typecode, self.example) + a[1:] = a + self.assertEqual( + a, + array.array(self.typecode, self.example[:1] + self.example) + ) + + a = array.array(self.typecode, self.example) + a[1:-1] = a + self.assertEqual( + a, + array.array( + self.typecode, + self.example[:1] + self.example + self.example[-1:] + ) + ) + + a = array.array(self.typecode, self.example) + a[1000:] = a + self.assertEqual( + a, + array.array(self.typecode, 2*self.example) + ) + + a = array.array(self.typecode, self.example) + a[-1000:] = a + self.assertEqual( + a, + array.array(self.typecode, self.example) + ) + + a = array.array(self.typecode, self.example) + a[:1000] = a + self.assertEqual( + a, + array.array(self.typecode, self.example) + ) + + a = array.array(self.typecode, self.example) + a[:-1000] = a + self.assertEqual( + a, + array.array(self.typecode, 2*self.example) + ) + + a = array.array(self.typecode, self.example) + a[1:0] = a + self.assertEqual( + a, + array.array(self.typecode, self.example[:1] + self.example + self.example[1:]) + ) + + a = array.array(self.typecode, self.example) + a[2000:1000] = a + self.assertEqual( + a, + array.array(self.typecode, 2*self.example) + ) + + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.__setslice__, 0, 0, None) + self.assertRaises(TypeError, a.__setitem__, slice(0, 1), None) + + b = array.array(self.badtypecode()) + self.assertRaises(TypeError, a.__setslice__, 0, 0, b) + self.assertRaises(TypeError, a.__setitem__, slice(0, 1), b) + + def test_index(self): + example = 2*self.example + a = array.array(self.typecode, example) + self.assertRaises(TypeError, a.index) + for x in example: + self.assertEqual(a.index(x), example.index(x)) + self.assertRaises(ValueError, a.index, None) + self.assertRaises(ValueError, a.index, self.outside) + + def test_count(self): + example = 2*self.example + a = array.array(self.typecode, example) + self.assertRaises(TypeError, a.count) + for x in example: + self.assertEqual(a.count(x), example.count(x)) + self.assertEqual(a.count(self.outside), 0) + self.assertEqual(a.count(None), 0) + + def test_remove(self): + for x in self.example: + example = 2*self.example + a = array.array(self.typecode, example) + pos = example.index(x) + example2 = example[:pos] + example[pos+1:] + a.remove(x) + self.assertEqual(a, array.array(self.typecode, example2)) + + a = array.array(self.typecode, self.example) + self.assertRaises(ValueError, a.remove, self.outside) + + self.assertRaises(ValueError, a.remove, None) + + def test_pop(self): + a = array.array(self.typecode) + self.assertRaises(IndexError, a.pop) + + a = array.array(self.typecode, 2*self.example) + self.assertRaises(TypeError, a.pop, 42, 42) + self.assertRaises(TypeError, a.pop, None) + self.assertRaises(IndexError, a.pop, len(a)) + self.assertRaises(IndexError, a.pop, -len(a)-1) + + self.assertEntryEqual(a.pop(0), self.example[0]) + self.assertEqual( + a, + array.array(self.typecode, self.example[1:]+self.example) + ) + self.assertEntryEqual(a.pop(1), self.example[2]) + self.assertEqual( + a, + array.array(self.typecode, self.example[1:2]+self.example[3:]+self.example) + ) + self.assertEntryEqual(a.pop(0), self.example[1]) + self.assertEntryEqual(a.pop(), self.example[-1]) + self.assertEqual( + a, + array.array(self.typecode, self.example[3:]+self.example[:-1]) + ) + + def test_reverse(self): + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.reverse, 42) + a.reverse() + self.assertEqual( + a, + array.array(self.typecode, self.example[::-1]) + ) + + def test_extend(self): + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.extend) + a.extend(array.array(self.typecode, self.example[::-1])) + self.assertEqual( + a, + array.array(self.typecode, self.example+self.example[::-1]) + ) + + b = array.array(self.badtypecode()) + self.assertRaises(TypeError, a.extend, b) + + a = array.array(self.typecode, self.example) + a.extend(self.example[::-1]) + self.assertEqual( + a, + array.array(self.typecode, self.example+self.example[::-1]) + ) + + def test_constructor_with_iterable_argument(self): + a = array.array(self.typecode, iter(self.example)) + b = array.array(self.typecode, self.example) + self.assertEqual(a, b) + + # non-iterable argument + self.assertRaises(TypeError, array.array, self.typecode, 10) + + # pass through errors raised in __iter__ + class A: + def __iter__(self): + raise UnicodeError + self.assertRaises(UnicodeError, array.array, self.typecode, A()) + + # pass through errors raised in next() + def B(): + raise UnicodeError + yield None + self.assertRaises(UnicodeError, array.array, self.typecode, B()) + + def test_coveritertraverse(self): + try: + import gc + except ImportError: + return + a = array.array(self.typecode) + l = [iter(a)] + l.append(l) + gc.collect() + + def test_buffer(self): + a = array.array(self.typecode, self.example) + b = buffer(a) + self.assertEqual(b[0], a.tostring()[0]) + + def test_weakref(self): + s = array.array(self.typecode, self.example) + p = proxy(s) + self.assertEqual(p.tostring(), s.tostring()) + s = None + self.assertRaises(ReferenceError, len, p) + + def test_bug_782369(self): + import sys + if hasattr(sys, "getrefcount"): + for i in range(10): + b = array.array('B', range(64)) + rc = sys.getrefcount(10) + for i in range(10): + b = array.array('B', range(64)) + self.assertEqual(rc, sys.getrefcount(10)) + + def test_subclass_with_kwargs(self): + # SF bug #1486663 -- this used to erroneously raise a TypeError + ArraySubclassWithKwargs('b', newarg=1) + + +class StringTest(BaseTest): + + def test_setitem(self): + super(StringTest, self).test_setitem() + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.__setitem__, 0, self.example[:2]) + +class CharacterTest(StringTest): + typecode = 'c' + example = '\x01azAZ\x00\xfe' + smallerexample = '\x01azAY\x00\xfe' + biggerexample = '\x01azAZ\x00\xff' + outside = '\x33' + minitemsize = 1 + + def test_subbclassing(self): + class EditableString(array.array): + def __new__(cls, s, *args, **kwargs): + return array.array.__new__(cls, 'c', s) + + def __init__(self, s, color='blue'): + array.array.__init__(self, 'c', s) + self.color = color + + def strip(self): + self[:] = array.array('c', self.tostring().strip()) + + def __repr__(self): + return 'EditableString(%r)' % self.tostring() + + s = EditableString("\ttest\r\n") + s.strip() + self.assertEqual(s.tostring(), "test") + + self.assertEqual(s.color, "blue") + s.color = "red" + self.assertEqual(s.color, "red") + self.assertEqual(s.__dict__.keys(), ["color"]) + + def test_nounicode(self): + a = array.array(self.typecode, self.example) + self.assertRaises(ValueError, a.fromunicode, unicode('')) + self.assertRaises(ValueError, a.tounicode) + +tests.append(CharacterTest) + +if test_support.have_unicode: + class UnicodeTest(StringTest): + typecode = 'u' + example = unicode(r'\x01\u263a\x00\ufeff', 'unicode-escape') + smallerexample = unicode(r'\x01\u263a\x00\ufefe', 'unicode-escape') + biggerexample = unicode(r'\x01\u263a\x01\ufeff', 'unicode-escape') + outside = unicode('\x33') + minitemsize = 2 + + def test_unicode(self): + self.assertRaises(TypeError, array.array, 'b', unicode('foo', 'ascii')) + + a = array.array('u', unicode(r'\xa0\xc2\u1234', 'unicode-escape')) + a.fromunicode(unicode(' ', 'ascii')) + a.fromunicode(unicode('', 'ascii')) + a.fromunicode(unicode('', 'ascii')) + a.fromunicode(unicode(r'\x11abc\xff\u1234', 'unicode-escape')) + s = a.tounicode() + self.assertEqual( + s, + unicode(r'\xa0\xc2\u1234 \x11abc\xff\u1234', 'unicode-escape') + ) + + s = unicode(r'\x00="\'a\\b\x80\xff\u0000\u0001\u1234', 'unicode-escape') + a = array.array('u', s) + self.assertEqual( + repr(a), + r"""array('u', u'\x00="\'a\\b\x80\xff\x00\x01\u1234')""" + ) + + self.assertRaises(TypeError, a.fromunicode) + + tests.append(UnicodeTest) + +class NumberTest(BaseTest): + + def test_extslice(self): + a = array.array(self.typecode, range(5)) + self.assertEqual(a[::], a) + self.assertEqual(a[::2], array.array(self.typecode, [0,2,4])) + self.assertEqual(a[1::2], array.array(self.typecode, [1,3])) + self.assertEqual(a[::-1], array.array(self.typecode, [4,3,2,1,0])) + self.assertEqual(a[::-2], array.array(self.typecode, [4,2,0])) + self.assertEqual(a[3::-2], array.array(self.typecode, [3,1])) + self.assertEqual(a[-100:100:], a) + self.assertEqual(a[100:-100:-1], a[::-1]) + self.assertEqual(a[-100L:100L:2L], array.array(self.typecode, [0,2,4])) + self.assertEqual(a[1000:2000:2], array.array(self.typecode, [])) + self.assertEqual(a[-1000:-2000:-2], array.array(self.typecode, [])) + + def test_delslice(self): + a = array.array(self.typecode, range(5)) + del a[::2] + self.assertEqual(a, array.array(self.typecode, [1,3])) + a = array.array(self.typecode, range(5)) + del a[1::2] + self.assertEqual(a, array.array(self.typecode, [0,2,4])) + a = array.array(self.typecode, range(5)) + del a[1::-2] + self.assertEqual(a, array.array(self.typecode, [0,2,3,4])) + a = array.array(self.typecode, range(10)) + del a[::1000] + self.assertEqual(a, array.array(self.typecode, [1,2,3,4,5,6,7,8,9])) + + def test_assignment(self): + a = array.array(self.typecode, range(10)) + a[::2] = array.array(self.typecode, [42]*5) + self.assertEqual(a, array.array(self.typecode, [42, 1, 42, 3, 42, 5, 42, 7, 42, 9])) + a = array.array(self.typecode, range(10)) + a[::-4] = array.array(self.typecode, [10]*3) + self.assertEqual(a, array.array(self.typecode, [0, 10, 2, 3, 4, 10, 6, 7, 8 ,10])) + a = array.array(self.typecode, range(4)) + a[::-1] = a + self.assertEqual(a, array.array(self.typecode, [3, 2, 1, 0])) + a = array.array(self.typecode, range(10)) + b = a[:] + c = a[:] + ins = array.array(self.typecode, range(2)) + a[2:3] = ins + b[slice(2,3)] = ins + c[2:3:] = ins + + def test_iterationcontains(self): + a = array.array(self.typecode, range(10)) + self.assertEqual(list(a), range(10)) + b = array.array(self.typecode, [20]) + self.assertEqual(a[-1] in a, True) + self.assertEqual(b[0] not in a, True) + + def check_overflow(self, lower, upper): + # method to be used by subclasses + + # should not overflow assigning lower limit + a = array.array(self.typecode, [lower]) + a[0] = lower + # should overflow assigning less than lower limit + self.assertRaises(OverflowError, array.array, self.typecode, [lower-1]) + self.assertRaises(OverflowError, a.__setitem__, 0, lower-1) + # should not overflow assigning upper limit + a = array.array(self.typecode, [upper]) + a[0] = upper + # should overflow assigning more than upper limit + self.assertRaises(OverflowError, array.array, self.typecode, [upper+1]) + self.assertRaises(OverflowError, a.__setitem__, 0, upper+1) + + def test_subclassing(self): + typecode = self.typecode + class ExaggeratingArray(array.array): + __slots__ = ['offset'] + + def __new__(cls, typecode, data, offset): + return array.array.__new__(cls, typecode, data) + + def __init__(self, typecode, data, offset): + self.offset = offset + + def __getitem__(self, i): + return array.array.__getitem__(self, i) + self.offset + + a = ExaggeratingArray(self.typecode, [3, 6, 7, 11], 4) + self.assertEntryEqual(a[0], 7) + + self.assertRaises(AttributeError, setattr, a, "color", "blue") + +class SignedNumberTest(NumberTest): + example = [-1, 0, 1, 42, 0x7f] + smallerexample = [-1, 0, 1, 42, 0x7e] + biggerexample = [-1, 0, 1, 43, 0x7f] + outside = 23 + + def test_overflow(self): + a = array.array(self.typecode) + lower = -1 * long(pow(2, a.itemsize * 8 - 1)) + upper = long(pow(2, a.itemsize * 8 - 1)) - 1L + self.check_overflow(lower, upper) + +class UnsignedNumberTest(NumberTest): + example = [0, 1, 17, 23, 42, 0xff] + smallerexample = [0, 1, 17, 23, 42, 0xfe] + biggerexample = [0, 1, 17, 23, 43, 0xff] + outside = 0xaa + + def test_overflow(self): + a = array.array(self.typecode) + lower = 0 + upper = long(pow(2, a.itemsize * 8)) - 1L + self.check_overflow(lower, upper) + + +class ByteTest(SignedNumberTest): + typecode = 'b' + minitemsize = 1 +tests.append(ByteTest) + +class UnsignedByteTest(UnsignedNumberTest): + typecode = 'B' + minitemsize = 1 +tests.append(UnsignedByteTest) + +class ShortTest(SignedNumberTest): + typecode = 'h' + minitemsize = 2 +tests.append(ShortTest) + +class UnsignedShortTest(UnsignedNumberTest): + typecode = 'H' + minitemsize = 2 +tests.append(UnsignedShortTest) + +class IntTest(SignedNumberTest): + typecode = 'i' + minitemsize = 2 +tests.append(IntTest) + +class UnsignedIntTest(UnsignedNumberTest): + typecode = 'I' + minitemsize = 2 +tests.append(UnsignedIntTest) + +class LongTest(SignedNumberTest): + typecode = 'l' + minitemsize = 4 +tests.append(LongTest) + +class UnsignedLongTest(UnsignedNumberTest): + typecode = 'L' + minitemsize = 4 +tests.append(UnsignedLongTest) + +class FPTest(NumberTest): + example = [-42.0, 0, 42, 1e5, -1e10] + smallerexample = [-42.0, 0, 42, 1e5, -2e10] + biggerexample = [-42.0, 0, 42, 1e5, 1e10] + outside = 23 + + def assertEntryEqual(self, entry1, entry2): + self.assertAlmostEqual(entry1, entry2) + + def test_byteswap(self): + a = array.array(self.typecode, self.example) + self.assertRaises(TypeError, a.byteswap, 42) + if a.itemsize in (1, 2, 4, 8): + b = array.array(self.typecode, self.example) + b.byteswap() + if a.itemsize==1: + self.assertEqual(a, b) + else: + # On alphas treating the byte swapped bit patters as + # floats/doubles results in floating point exceptions + # => compare the 8bit string values instead + self.assertNotEqual(a.tostring(), b.tostring()) + b.byteswap() + self.assertEqual(a, b) + +class FloatTest(FPTest): + typecode = 'f' + minitemsize = 4 +tests.append(FloatTest) + +class DoubleTest(FPTest): + typecode = 'd' + minitemsize = 8 +tests.append(DoubleTest) + +def test_main(verbose=None): + import sys + + test_support.run_unittest(*tests) + + # verify reference counting + if verbose and hasattr(sys, "gettotalrefcount"): + import gc + counts = [None] * 5 + for i in xrange(len(counts)): + test_support.run_unittest(*tests) + gc.collect() + counts[i] = sys.gettotalrefcount() + print counts + +if __name__ == "__main__": + test_main(verbose=True) Property changes on: branches/asm/Lib/test/test_array.py ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-23 01:18:55
|
Revision: 4985 http://jython.svn.sourceforge.net/jython/?rev=4985&view=rev Author: pjenvey Date: 2008-07-23 01:18:53 +0000 (Wed, 23 Jul 2008) Log Message: ----------- o make Py.makeCharacter consisitent in never returning unicode unless it was asked for o move calculateIndex into PySequence for PyArray o allow PyLong.getLong access for PyArray Modified Paths: -------------- branches/asm/src/org/python/core/Py.java branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PyLong.java branches/asm/src/org/python/core/PySequence.java Modified: branches/asm/src/org/python/core/Py.java =================================================================== --- branches/asm/src/org/python/core/Py.java 2008-07-21 19:48:17 UTC (rev 4984) +++ branches/asm/src/org/python/core/Py.java 2008-07-23 01:18:53 UTC (rev 4985) @@ -1441,8 +1441,8 @@ return makeCharacter(c, false); } - static final PyString makeCharacter(int codepoint, boolean explicitUnicode) { - if (explicitUnicode || codepoint > 255) { + static final PyString makeCharacter(int codepoint, boolean toUnicode) { + if (toUnicode) { return new PyUnicode(codepoint); } Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-21 19:48:17 UTC (rev 4984) +++ branches/asm/src/org/python/core/PyList.java 2008-07-23 01:18:53 UTC (rev 4985) @@ -528,25 +528,6 @@ throw Py.ValueError(message); } - // This is closely related to fixindex in PySequence, but less strict - // fixindex returns -1 if index += length < 0 or if index >= length - // where this function returns 0 in former case and length in the latter. - // I think both are needed in different cases, but if this method turns - // out to be needed in other sequence subclasses, it should be moved to - // PySequence. - private int calculateIndex(int index) { - int length = size(); - if(index < 0) { - index = index += length; - if(index < 0) { - index = 0; - } - } else if(index > length) { - index = length; - } - return index; - } - /** * Insert the argument element into the list at the specified index. <br> * Same as <code>s[index:index] = [o] if index >= 0</code>. Modified: branches/asm/src/org/python/core/PyLong.java =================================================================== --- branches/asm/src/org/python/core/PyLong.java 2008-07-21 19:48:17 UTC (rev 4984) +++ branches/asm/src/org/python/core/PyLong.java 2008-07-23 01:18:53 UTC (rev 4985) @@ -182,11 +182,11 @@ } - private long getLong(long min, long max) { + public long getLong(long min, long max) { return getLong(min, max, "long int too large to convert"); } - private long getLong(long min, long max, String overflowMsg) { + public long getLong(long min, long max, String overflowMsg) { if (value.compareTo(maxLong) <= 0 && value.compareTo(minLong) >= 0) { long v = value.longValue(); if (v >= min && v <= max) Modified: branches/asm/src/org/python/core/PySequence.java =================================================================== --- branches/asm/src/org/python/core/PySequence.java 2008-07-21 19:48:17 UTC (rev 4984) +++ branches/asm/src/org/python/core/PySequence.java 2008-07-23 01:18:53 UTC (rev 4985) @@ -256,6 +256,20 @@ } } + // XXX: more appropriate naming of this vs fixindex + protected int calculateIndex(int index) { + int length = __len__(); + if(index < 0) { + index = index += length; + if(index < 0) { + index = 0; + } + } else if(index > length) { + index = length; + } + return index; + } + public PyObject __finditem__(int index) { return seq___finditem__(index); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 19:48:20
|
Revision: 4984 http://jython.svn.sourceforge.net/jython/?rev=4984&view=rev Author: pjenvey Date: 2008-07-21 19:48:17 +0000 (Mon, 21 Jul 2008) Log Message: ----------- make the failure verbose because test_site_flag occasionally fails on the buildbot mysteriously Modified Paths: -------------- branches/asm/Lib/test/test_cmd_line.py Modified: branches/asm/Lib/test/test_cmd_line.py =================================================================== --- branches/asm/Lib/test/test_cmd_line.py 2008-07-21 19:45:12 UTC (rev 4983) +++ branches/asm/Lib/test/test_cmd_line.py 2008-07-21 19:48:17 UTC (rev 4984) @@ -22,7 +22,7 @@ def verify_valid_flag(self, cmd_line): data = self.start_python(cmd_line) - self.assertTrue(data == '' or data.endswith('\n')) + self.assertTrue(data == '' or data.endswith('\n'), repr(data)) self.assertTrue('Traceback' not in data) def test_environment(self): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 19:45:15
|
Revision: 4983 http://jython.svn.sourceforge.net/jython/?rev=4983&view=rev Author: pjenvey Date: 2008-07-21 19:45:12 +0000 (Mon, 21 Jul 2008) Log Message: ----------- o fix filter to pass test_builtin.test_filter and test_filter_subclasses o remove the unnecessary __builtin__.tuple Modified Paths: -------------- branches/asm/src/com/ziclix/python/sql/Fetch.java branches/asm/src/org/python/core/__builtin__.java branches/asm/src/org/python/modules/struct.java Modified: branches/asm/src/com/ziclix/python/sql/Fetch.java =================================================================== --- branches/asm/src/com/ziclix/python/sql/Fetch.java 2008-07-21 19:11:48 UTC (rev 4982) +++ branches/asm/src/com/ziclix/python/sql/Fetch.java 2008-07-21 19:45:12 UTC (rev 4983) @@ -14,7 +14,6 @@ import org.python.core.PyList; import org.python.core.PyObject; import org.python.core.PyTuple; -import org.python.core.__builtin__; import java.sql.CallableStatement; import java.sql.DatabaseMetaData; @@ -401,7 +400,7 @@ PyList ret = new PyList(); - ret.append(__builtin__.tuple(results)); + ret.append(PyTuple.fromIterable(results)); return ret; } Modified: branches/asm/src/org/python/core/__builtin__.java =================================================================== --- branches/asm/src/org/python/core/__builtin__.java 2008-07-21 19:11:48 UTC (rev 4982) +++ branches/asm/src/org/python/core/__builtin__.java 2008-07-21 19:45:12 UTC (rev 4983) @@ -551,46 +551,120 @@ execfile(name, null, null); } - public static PyObject filter(PyObject f, PyString s) { - if (f == Py.None) { - return s; - } - PyObject[] args = new PyObject[1]; - char[] chars = s.toString().toCharArray(); - int i; - int j; - int n = chars.length; - for (i = 0, j = 0; i < n; i++) { - args[0] = Py.makeCharacter(chars[i]); - if (!f.__call__(args).__nonzero__()) { - continue; + public static PyObject filter(PyObject func, PyObject seq) { + if (seq instanceof PyString) { + if (seq instanceof PyUnicode) { + return filterunicode(func, (PyUnicode)seq); } - chars[j++] = chars[i]; + return filterstring(func, (PyString)seq); } - return new PyString(new String(chars, 0, j)); - } + if (seq instanceof PyTuple) { + return filtertuple(func, (PyTuple)seq); + } - public static PyObject filter(PyObject f, PyObject l) { - if (l instanceof PyString) { - return filter(f, (PyString) l); - } PyList list = new PyList(); - for (PyObject item : l.asIterable()) { - if (f == Py.None) { + for (PyObject item : seq.asIterable()) { + if (func == PyBoolean.TYPE || func == Py.None) { if (!item.__nonzero__()) { continue; } - } else if (!f.__call__(item).__nonzero__()) { + } else if (!func.__call__(item).__nonzero__()) { continue; } list.append(item); } - if (l instanceof PyTuple) { - return tuple(list); - } return list; } + public static PyObject filterstring(PyObject func, PyString seq) { + if (func == Py.None && seq.getType() == PyString.TYPE) { + // If it's a real string we can return the original, as no character is ever + // false and __getitem__ does return this character. If it's a subclass we + // must go through the __getitem__ loop + return seq; + } + + StringBuilder builder = new StringBuilder(); + boolean ok; + for (PyObject item : seq.asIterable()) { + ok = false; + if (func == Py.None) { + if (item.__nonzero__()) { + ok = true; + } + } else if (func.__call__(item).__nonzero__()) { + ok = true; + } + if (ok) { + if (!(item instanceof PyString) || item instanceof PyUnicode) { + throw Py.TypeError("can't filter str to str: __getitem__ returned different " + + "type"); + } + builder.append(item.toString()); + } + } + return new PyString(builder.toString()); + } + + public static PyObject filterunicode(PyObject func, PyUnicode seq) { + if (func == Py.None && seq.getType() == PyUnicode.TYPE) { + // If it's a real string we can return the original, as no character is ever + // false and __getitem__ does return this character. If it's a subclass we + // must go through the __getitem__ loop + return seq; + } + + StringBuilder builder = new StringBuilder(); + boolean ok; + for (PyObject item : seq.asIterable()) { + ok = false; + if (func == Py.None) { + if (item.__nonzero__()) { + ok = true; + } + } else if (func.__call__(item).__nonzero__()) { + ok = true; + } + if (ok) { + if (!(item instanceof PyUnicode)) { + throw Py.TypeError("can't filter unicode to unicode: __getitem__ returned " + + "different type"); + } + builder.append(item.toString()); + } + } + return new PyUnicode(builder.toString()); + } + + public static PyObject filtertuple(PyObject func, PyTuple seq) { + int len = seq.__len__(); + if (len == 0) { + if (seq.getType() != PyTuple.TYPE) { + seq = new PyTuple(); + } + return seq; + } + + PyList list = new PyList(); + PyObject item; + boolean ok; + for (int i = 0; i < len; i++) { + ok = false; + item = seq.__finditem__(i); + if (func == Py.None) { + if (item.__nonzero__()) { + ok = true; + } + } else if (func.__call__(item).__nonzero__()) { + ok = true; + } + if (ok) { + list.append(item); + } + } + return PyTuple.fromIterable(list); + } + public static PyObject getattr(PyObject obj, PyObject name) { return getattr(obj, name, null); } @@ -1027,22 +1101,6 @@ return sum(seq, Py.Zero); } - public static PyTuple tuple(PyObject o) { - if (o instanceof PyTuple) { - return (PyTuple) o; - } - if (o instanceof PyList) { - // always make a copy, otherwise the tuple will share the - // underlying data structure with the list object, which - // renders the tuple mutable! - PyList l = (PyList) o; - PyObject[] a = new PyObject[l.size()]; - System.arraycopy(l.getArray(), 0, a, 0, a.length); - return new PyTuple(a); - } - return new PyTuple(Py.make_array(o)); - } - public static PyType type(PyObject o) { return o.getType(); } Modified: branches/asm/src/org/python/modules/struct.java =================================================================== --- branches/asm/src/org/python/modules/struct.java 2008-07-21 19:11:48 UTC (rev 4982) +++ branches/asm/src/org/python/modules/struct.java 2008-07-21 19:45:12 UTC (rev 4983) @@ -17,7 +17,6 @@ import org.python.core.PyObject; import org.python.core.PyString; import org.python.core.PyTuple; -import org.python.core.__builtin__; import java.math.BigInteger; @@ -1034,7 +1033,7 @@ e.doUnpack(str, num, res); } - return __builtin__.tuple(res); + return PyTuple.fromIterable(res); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 19:11:52
|
Revision: 4982 http://jython.svn.sourceforge.net/jython/?rev=4982&view=rev Author: pjenvey Date: 2008-07-21 19:11:48 +0000 (Mon, 21 Jul 2008) Log Message: ----------- fix exposed __getitem__ possibly returning null Modified Paths: -------------- branches/asm/src/org/python/core/PyString.java branches/asm/src/org/python/core/PyUnicode.java Modified: branches/asm/src/org/python/core/PyString.java =================================================================== --- branches/asm/src/org/python/core/PyString.java 2008-07-21 19:10:02 UTC (rev 4981) +++ branches/asm/src/org/python/core/PyString.java 2008-07-21 19:11:48 UTC (rev 4982) @@ -468,7 +468,11 @@ @ExposedMethod final PyObject str___getitem__(PyObject index) { - return seq___finditem__(index); + PyObject ret = seq___finditem__(index); + if (ret == null) { + throw Py.IndexError("string index out of range"); + } + return ret; } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyUnicode.java =================================================================== --- branches/asm/src/org/python/core/PyUnicode.java 2008-07-21 19:10:02 UTC (rev 4981) +++ branches/asm/src/org/python/core/PyUnicode.java 2008-07-21 19:11:48 UTC (rev 4982) @@ -245,12 +245,12 @@ } @ExposedMethod - public PyObject unicode___getitem__(PyObject index) { - return seq___finditem__(index); + final PyObject unicode___getitem__(PyObject index) { + return str___getitem__(index); } @ExposedMethod(defaults = "null") - public PyObject unicode___getslice__(PyObject start, PyObject stop, PyObject step) { + final PyObject unicode___getslice__(PyObject start, PyObject stop, PyObject step) { return seq___getslice__(start, stop, step); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 19:10:06
|
Revision: 4981 http://jython.svn.sourceforge.net/jython/?rev=4981&view=rev Author: pjenvey Date: 2008-07-21 19:10:02 +0000 (Mon, 21 Jul 2008) Log Message: ----------- we want the final seq___finditem__ here Modified Paths: -------------- trunk/jython/src/org/python/core/PySequence.java Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2008-07-21 05:00:49 UTC (rev 4980) +++ trunk/jython/src/org/python/core/PySequence.java 2008-07-21 19:10:02 UTC (rev 4981) @@ -143,7 +143,7 @@ if(i < 0) { return (i == -1) ? Py.True : Py.False; } - return __finditem__(i)._lt(o.__finditem__(i)); + return seq___finditem__(i)._lt(((PySequence)o).seq___finditem__(i)); } final synchronized PyObject seq___lt__(PyObject o) { @@ -158,7 +158,7 @@ if(i < 0) { return (i == -1 || i == -2) ? Py.True : Py.False; } - return __finditem__(i)._le(o.__finditem__(i)); + return seq___finditem__(i)._le(((PySequence)o).seq___finditem__(i)); } final synchronized PyObject seq___le__(PyObject o) { @@ -172,7 +172,7 @@ int i = cmp(this, -1, o, -1); if(i < 0) return (i == -3) ? Py.True : Py.False; - return __finditem__(i)._gt(o.__finditem__(i)); + return seq___finditem__(i)._gt(((PySequence)o).seq___finditem__(i)); } final synchronized PyObject seq___gt__(PyObject o) { @@ -187,7 +187,7 @@ if(i < 0) { return (i == -3 || i == -2) ? Py.True : Py.False; } - return __finditem__(i)._ge(o.__finditem__(i)); + return seq___finditem__(i)._ge(((PySequence)o).seq___finditem__(i)); } final synchronized PyObject seq___ge__(PyObject o) { @@ -289,7 +289,7 @@ } final PyObject seq___getitem__(PyObject index) { - PyObject ret = __finditem__(index); + PyObject ret = seq___finditem__(index); if(ret == null) { throw Py.IndexError("index out of range: " + index); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 05:00:53
|
Revision: 4980 http://jython.svn.sourceforge.net/jython/?rev=4980&view=rev Author: pjenvey Date: 2008-07-21 05:00:49 +0000 (Mon, 21 Jul 2008) Log Message: ----------- integrate the sink state conditions Modified Paths: -------------- branches/asm/src/org/python/core/PyFastSequenceIter.java Modified: branches/asm/src/org/python/core/PyFastSequenceIter.java =================================================================== --- branches/asm/src/org/python/core/PyFastSequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) +++ branches/asm/src/org/python/core/PyFastSequenceIter.java 2008-07-21 05:00:49 UTC (rev 4980) @@ -15,13 +15,23 @@ } public PyObject __iternext__() { + if (seq == null) { + return null; + } + + PyObject result; try { - return seq.seq___finditem__(index++); + result = seq.seq___finditem__(index++); } catch (PyException exc) { if (Py.matchException(exc, Py.StopIteration)) { + seq = null; return null; } throw exc; } + if (result == null) { + seq = null; + } + return result; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 04:59:19
|
Revision: 4979 http://jython.svn.sourceforge.net/jython/?rev=4979&view=rev Author: pjenvey Date: 2008-07-21 04:59:03 +0000 (Mon, 21 Jul 2008) Log Message: ----------- Merged revisions 4962-4978 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r4966 | pjenvey | 2008-07-17 14:25:44 -0700 (Thu, 17 Jul 2008) | 3 lines fix loading of 0L in cPickle proto 2 and match cPickle's dumps(0L, 2) to pickle's ........ r4975 | pjenvey | 2008-07-19 16:23:25 -0700 (Sat, 19 Jul 2008) | 1 line reintegrate r3069: don't abspath __classpath__ in sys.path ........ r4976 | pjenvey | 2008-07-20 18:38:17 -0700 (Sun, 20 Jul 2008) | 1 line small cleanup ........ r4977 | pjenvey | 2008-07-20 18:43:14 -0700 (Sun, 20 Jul 2008) | 4 lines add PyFastSequenceIter (for list and tuple) which calls final seq___finditem__. whereas PySequenceIter calls __finditem__ which may be overridden by subclasses ........ r4978 | pjenvey | 2008-07-20 18:59:47 -0700 (Sun, 20 Jul 2008) | 3 lines fix __finditem__(int) not trying subclasses' __getitem__ if the parent overrode it (like PySequence does) ........ Modified Paths: -------------- branches/asm/Lib/site.py branches/asm/src/org/python/core/PyArrayDerived.java branches/asm/src/org/python/core/PyBooleanDerived.java branches/asm/src/org/python/core/PyClassMethodDerived.java branches/asm/src/org/python/core/PyComplexDerived.java branches/asm/src/org/python/core/PyDictionaryDerived.java branches/asm/src/org/python/core/PyEnumerateDerived.java branches/asm/src/org/python/core/PyFileDerived.java branches/asm/src/org/python/core/PyFloatDerived.java branches/asm/src/org/python/core/PyFrozenSetDerived.java branches/asm/src/org/python/core/PyIntegerDerived.java branches/asm/src/org/python/core/PyList.java branches/asm/src/org/python/core/PyListDerived.java branches/asm/src/org/python/core/PyLongDerived.java branches/asm/src/org/python/core/PyModuleDerived.java branches/asm/src/org/python/core/PyObjectDerived.java branches/asm/src/org/python/core/PyPropertyDerived.java branches/asm/src/org/python/core/PySequence.java branches/asm/src/org/python/core/PySequenceIter.java branches/asm/src/org/python/core/PySetDerived.java branches/asm/src/org/python/core/PySliceDerived.java branches/asm/src/org/python/core/PyStringDerived.java branches/asm/src/org/python/core/PySuperDerived.java branches/asm/src/org/python/core/PyTuple.java branches/asm/src/org/python/core/PyTupleDerived.java branches/asm/src/org/python/core/PyTypeDerived.java branches/asm/src/org/python/core/PyUnicodeDerived.java branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java branches/asm/src/org/python/modules/cPickle.java branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java branches/asm/src/org/python/modules/collections/PyDequeDerived.java branches/asm/src/org/python/modules/random/PyRandomDerived.java branches/asm/src/org/python/modules/thread/PyLocalDerived.java branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java branches/asm/src/templates/object.derived Added Paths: ----------- branches/asm/Lib/test/test_cpickle_jy.py branches/asm/Lib/test/test_iter_jy.py branches/asm/src/org/python/core/PyFastSequenceIter.java Property Changed: ---------------- branches/asm/ Property changes on: branches/asm ___________________________________________________________________ Modified: svnmerge-integrated - /trunk/jython:1-4961 + /trunk/jython:1-4978 Modified: branches/asm/Lib/site.py =================================================================== --- branches/asm/Lib/site.py 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/Lib/site.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -64,7 +64,10 @@ def makepath(*paths): - dir = os.path.abspath(os.path.join(*paths)) + dir = os.path.join(*paths) + if dir == '__classpath__': + return dir, dir + dir = os.path.abspath(dir) return dir, os.path.normcase(dir) def abs__file__(): Copied: branches/asm/Lib/test/test_cpickle_jy.py (from rev 4978, trunk/jython/Lib/test/test_cpickle_jy.py) =================================================================== --- branches/asm/Lib/test/test_cpickle_jy.py (rev 0) +++ branches/asm/Lib/test/test_cpickle_jy.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -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() Copied: branches/asm/Lib/test/test_iter_jy.py (from rev 4978, trunk/jython/Lib/test/test_iter_jy.py) =================================================================== --- branches/asm/Lib/test/test_iter_jy.py (rev 0) +++ branches/asm/Lib/test/test_iter_jy.py 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,32 @@ +"""Misc iterator tests. + +Made for Jython. +""" +import test_support +import unittest + +class IterTestCase(unittest.TestCase): + + def test_fastiter(self): + class MyList(list): + def __getitem__(self, index): + return str(index) + '!' + class MyTuple(tuple): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyList(['a', 'b'])).next(), 'a') + self.assertEqual(iter(MyTuple(['a', 'b'])).next(), 'a') + + def test_slowiter(self): + class MyStr(str): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyStr('ab')).next(), '0!') + + +def test_main(): + test_support.run_unittest(IterTestCase) + + +if __name__ == '__main__': + test_main() Modified: branches/asm/src/org/python/core/PyArrayDerived.java =================================================================== --- branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyArrayDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyBooleanDerived.java =================================================================== --- branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyBooleanDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyClassMethodDerived.java =================================================================== --- branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyClassMethodDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyComplexDerived.java =================================================================== --- branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyComplexDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyDictionaryDerived.java =================================================================== --- branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyDictionaryDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyEnumerateDerived.java =================================================================== --- branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyEnumerateDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Copied: branches/asm/src/org/python/core/PyFastSequenceIter.java (from rev 4978, trunk/jython/src/org/python/core/PyFastSequenceIter.java) =================================================================== --- branches/asm/src/org/python/core/PyFastSequenceIter.java (rev 0) +++ branches/asm/src/org/python/core/PyFastSequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -0,0 +1,27 @@ +/* Copyright (c) Jython Developers */ +package org.python.core; + +/** + * Sequence iterator specialized for accessing the underlying sequence directly. + */ +public class PyFastSequenceIter extends PyIterator { + + private PySequence seq; + + private int index = 0; + + public PyFastSequenceIter(PySequence seq) { + this.seq = seq; + } + + public PyObject __iternext__() { + try { + return seq.seq___finditem__(index++); + } catch (PyException exc) { + if (Py.matchException(exc, Py.StopIteration)) { + return null; + } + throw exc; + } + } +} Modified: branches/asm/src/org/python/core/PyFileDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFileDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFileDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyFloatDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFloatDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyIntegerDerived.java =================================================================== --- branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyIntegerDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyList.java =================================================================== --- branches/asm/src/org/python/core/PyList.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyList.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -380,9 +380,13 @@ return seq___nonzero__(); } + public PyObject __iter__() { + return list___iter__(); + } + @ExposedMethod public PyObject list___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyListDerived.java =================================================================== --- branches/asm/src/org/python/core/PyListDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyListDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyLongDerived.java =================================================================== --- branches/asm/src/org/python/core/PyLongDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyLongDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyModuleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyModuleDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyObjectDerived.java =================================================================== --- branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyObjectDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyPropertyDerived.java =================================================================== --- branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyPropertyDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySequence.java =================================================================== --- branches/asm/src/org/python/core/PySequence.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySequence.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -256,7 +256,11 @@ } } - public synchronized PyObject __finditem__(int index) { + public PyObject __finditem__(int index) { + return seq___finditem__(index); + } + + final synchronized PyObject seq___finditem__(int index) { index = fixindex(index); if(index == -1) { return null; @@ -271,7 +275,7 @@ final PyObject seq___finditem__(PyObject index) { if(index instanceof PyInteger || index instanceof PyLong) { - return __finditem__(index.asInt()); + return seq___finditem__(index.asInt()); } else if(index instanceof PySlice) { PySlice s = (PySlice)index; return __getslice__(s.start, s.stop, s.step); Modified: branches/asm/src/org/python/core/PySequenceIter.java =================================================================== --- branches/asm/src/org/python/core/PySequenceIter.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySequenceIter.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -1,12 +1,17 @@ +/* Copyright (c) Jython Developers */ package org.python.core; +/** + * General sequence iterator. + */ public class PySequenceIter extends PyIterator { + private PyObject seq; - private int idx; + private int index = 0; + public PySequenceIter(PyObject seq) { this.seq = seq; - this.idx = 0; } public PyObject __iternext__() { @@ -16,7 +21,7 @@ PyObject result; try { - result = seq.__finditem__(idx++); + result = seq.__finditem__(index++); } catch (PyException exc) { if (Py.matchException(exc, Py.StopIteration)) { seq = null; @@ -30,4 +35,3 @@ return result; } } - Modified: branches/asm/src/org/python/core/PySetDerived.java =================================================================== --- branches/asm/src/org/python/core/PySetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySetDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySliceDerived.java =================================================================== --- branches/asm/src/org/python/core/PySliceDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySliceDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyStringDerived.java =================================================================== --- branches/asm/src/org/python/core/PyStringDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyStringDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PySuperDerived.java =================================================================== --- branches/asm/src/org/python/core/PySuperDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PySuperDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyTuple.java =================================================================== --- branches/asm/src/org/python/core/PyTuple.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTuple.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -191,9 +191,13 @@ return repeat(count); } + public PyObject __iter__() { + return tuple___iter__(); + } + @ExposedMethod public PyObject tuple___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: branches/asm/src/org/python/core/PyTupleDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTupleDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyTypeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyTypeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -830,6 +830,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/core/PyUnicodeDerived.java =================================================================== --- branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/core/PyUnicodeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -854,6 +854,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/cPickle.java =================================================================== --- branches/asm/src/org/python/modules/cPickle.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/cPickle.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -1130,9 +1130,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 { @@ -1905,6 +1913,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 Modified: branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/collections/PyDequeDerived.java =================================================================== --- branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -856,6 +856,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -832,6 +832,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 04:59:03 UTC (rev 4979) @@ -832,6 +832,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: branches/asm/src/templates/object.derived =================================================================== --- branches/asm/src/templates/object.derived 2008-07-21 01:59:47 UTC (rev 4978) +++ branches/asm/src/templates/object.derived 2008-07-21 04:59:03 UTC (rev 4979) @@ -188,6 +188,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type = getType(); + PyObject impl = self_type.lookup("__getitem__"); + if (impl != null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc, Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 02:00:41
|
Revision: 4978 http://jython.svn.sourceforge.net/jython/?rev=4978&view=rev Author: pjenvey Date: 2008-07-21 01:59:47 +0000 (Mon, 21 Jul 2008) Log Message: ----------- fix __finditem__(int) not trying subclasses' __getitem__ if the parent overrode it (like PySequence does) Modified Paths: -------------- trunk/jython/src/org/python/core/PyArrayDerived.java trunk/jython/src/org/python/core/PyBooleanDerived.java trunk/jython/src/org/python/core/PyClassMethodDerived.java trunk/jython/src/org/python/core/PyComplexDerived.java trunk/jython/src/org/python/core/PyDictionaryDerived.java trunk/jython/src/org/python/core/PyEnumerateDerived.java trunk/jython/src/org/python/core/PyFileDerived.java trunk/jython/src/org/python/core/PyFloatDerived.java trunk/jython/src/org/python/core/PyFrozenSetDerived.java trunk/jython/src/org/python/core/PyIntegerDerived.java trunk/jython/src/org/python/core/PyListDerived.java trunk/jython/src/org/python/core/PyLongDerived.java trunk/jython/src/org/python/core/PyModuleDerived.java trunk/jython/src/org/python/core/PyObjectDerived.java trunk/jython/src/org/python/core/PyPropertyDerived.java trunk/jython/src/org/python/core/PySetDerived.java trunk/jython/src/org/python/core/PySliceDerived.java trunk/jython/src/org/python/core/PyStringDerived.java trunk/jython/src/org/python/core/PySuperDerived.java trunk/jython/src/org/python/core/PyTupleDerived.java trunk/jython/src/org/python/core/PyTypeDerived.java trunk/jython/src/org/python/core/PyUnicodeDerived.java trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java trunk/jython/src/org/python/modules/collections/PyDefaultDictDerived.java trunk/jython/src/org/python/modules/collections/PyDequeDerived.java trunk/jython/src/org/python/modules/random/PyRandomDerived.java trunk/jython/src/org/python/modules/thread/PyLocalDerived.java trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java trunk/jython/src/templates/object.derived Added Paths: ----------- trunk/jython/Lib/test/test_iter_jy.py Added: trunk/jython/Lib/test/test_iter_jy.py =================================================================== --- trunk/jython/Lib/test/test_iter_jy.py (rev 0) +++ trunk/jython/Lib/test/test_iter_jy.py 2008-07-21 01:59:47 UTC (rev 4978) @@ -0,0 +1,32 @@ +"""Misc iterator tests. + +Made for Jython. +""" +import test_support +import unittest + +class IterTestCase(unittest.TestCase): + + def test_fastiter(self): + class MyList(list): + def __getitem__(self, index): + return str(index) + '!' + class MyTuple(tuple): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyList(['a', 'b'])).next(), 'a') + self.assertEqual(iter(MyTuple(['a', 'b'])).next(), 'a') + + def test_slowiter(self): + class MyStr(str): + def __getitem__(self, index): + return str(index) + '!' + self.assertEqual(iter(MyStr('ab')).next(), '0!') + + +def test_main(): + test_support.run_unittest(IterTestCase) + + +if __name__ == '__main__': + test_main() Modified: trunk/jython/src/org/python/core/PyArrayDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyArrayDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyArrayDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyBooleanDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyBooleanDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyBooleanDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyClassMethodDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyClassMethodDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyClassMethodDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyComplexDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyComplexDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyComplexDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyDictionaryDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyDictionaryDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyDictionaryDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyEnumerateDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyEnumerateDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyEnumerateDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyFileDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFileDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyFileDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyFloatDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFloatDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyFloatDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyFrozenSetDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyFrozenSetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyIntegerDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyIntegerDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyIntegerDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyListDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyListDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyListDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyLongDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyLongDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyLongDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyModuleDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyModuleDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyModuleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -767,6 +767,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyObjectDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyObjectDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyObjectDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyPropertyDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyPropertyDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyPropertyDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PySetDerived.java =================================================================== --- trunk/jython/src/org/python/core/PySetDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PySetDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PySliceDerived.java =================================================================== --- trunk/jython/src/org/python/core/PySliceDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PySliceDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyStringDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyStringDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyStringDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PySuperDerived.java =================================================================== --- trunk/jython/src/org/python/core/PySuperDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PySuperDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyTupleDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyTupleDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyTupleDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyTypeDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyTypeDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -767,6 +767,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/core/PyUnicodeDerived.java =================================================================== --- trunk/jython/src/org/python/core/PyUnicodeDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/core/PyUnicodeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -791,6 +791,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java =================================================================== --- trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/modules/_weakref/ReferenceTypeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -793,6 +793,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/modules/collections/PyDefaultDictDerived.java =================================================================== --- trunk/jython/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/modules/collections/PyDefaultDictDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -793,6 +793,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/modules/collections/PyDequeDerived.java =================================================================== --- trunk/jython/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/modules/collections/PyDequeDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -793,6 +793,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/modules/random/PyRandomDerived.java =================================================================== --- trunk/jython/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/modules/random/PyRandomDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -793,6 +793,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/modules/thread/PyLocalDerived.java =================================================================== --- trunk/jython/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/modules/thread/PyLocalDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -769,6 +769,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java =================================================================== --- trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/org/python/modules/zipimport/zipimporterDerived.java 2008-07-21 01:59:47 UTC (rev 4978) @@ -769,6 +769,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type=getType(); + PyObject impl=self_type.lookup("__getitem__"); + if (impl!=null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc,Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom Modified: trunk/jython/src/templates/object.derived =================================================================== --- trunk/jython/src/templates/object.derived 2008-07-21 01:43:14 UTC (rev 4977) +++ trunk/jython/src/templates/object.derived 2008-07-21 01:59:47 UTC (rev 4978) @@ -179,6 +179,20 @@ return super.__finditem__(key); } + public PyObject __finditem__(int key) { + PyType self_type = getType(); + PyObject impl = self_type.lookup("__getitem__"); + if (impl != null) + try { + return impl.__get__(this,self_type).__call__(new PyInteger(key)); + } catch (PyException exc) { + if (Py.matchException(exc, Py.LookupError)) + return null; + throw exc; + } + return super.__finditem__(key); + } + public PyObject __getitem__(PyObject key) { // Same as __finditem__, without swallowing LookupErrors. This allows // __getitem__ implementations written in Python to raise custom This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 01:43:27
|
Revision: 4977 http://jython.svn.sourceforge.net/jython/?rev=4977&view=rev Author: pjenvey Date: 2008-07-21 01:43:14 +0000 (Mon, 21 Jul 2008) Log Message: ----------- add PyFastSequenceIter (for list and tuple) which calls final seq___finditem__. whereas PySequenceIter calls __finditem__ which may be overridden by subclasses Modified Paths: -------------- trunk/jython/src/org/python/core/PyList.java trunk/jython/src/org/python/core/PySequenceIter.java trunk/jython/src/org/python/core/PyTuple.java Added Paths: ----------- trunk/jython/src/org/python/core/PyFastSequenceIter.java Added: trunk/jython/src/org/python/core/PyFastSequenceIter.java =================================================================== --- trunk/jython/src/org/python/core/PyFastSequenceIter.java (rev 0) +++ trunk/jython/src/org/python/core/PyFastSequenceIter.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -0,0 +1,27 @@ +/* Copyright (c) Jython Developers */ +package org.python.core; + +/** + * Sequence iterator specialized for accessing the underlying sequence directly. + */ +public class PyFastSequenceIter extends PyIterator { + + private PySequence seq; + + private int index = 0; + + public PyFastSequenceIter(PySequence seq) { + this.seq = seq; + } + + public PyObject __iternext__() { + try { + return seq.seq___finditem__(index++); + } catch (PyException exc) { + if (Py.matchException(exc, Py.StopIteration)) { + return null; + } + throw exc; + } + } +} Modified: trunk/jython/src/org/python/core/PyList.java =================================================================== --- trunk/jython/src/org/python/core/PyList.java 2008-07-21 01:38:17 UTC (rev 4976) +++ trunk/jython/src/org/python/core/PyList.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -391,9 +391,13 @@ return seq___nonzero__(); } + public PyObject __iter__() { + return list___iter__(); + } + @ExposedMethod public PyObject list___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") Modified: trunk/jython/src/org/python/core/PySequenceIter.java =================================================================== --- trunk/jython/src/org/python/core/PySequenceIter.java 2008-07-21 01:38:17 UTC (rev 4976) +++ trunk/jython/src/org/python/core/PySequenceIter.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -1,23 +1,27 @@ +/* Copyright (c) Jython Developers */ package org.python.core; +/** + * General sequence iterator. + */ public class PySequenceIter extends PyIterator { + private PyObject seq; - private int idx; + private int index = 0; + public PySequenceIter(PyObject seq) { this.seq = seq; - this.idx = 0; } public PyObject __iternext__() { try { - return seq.__finditem__(idx++); + return seq.__finditem__(index++); } catch (PyException exc) { - if (Py.matchException(exc, Py.StopIteration)) + if (Py.matchException(exc, Py.StopIteration)) { return null; + } throw exc; } } - } - Modified: trunk/jython/src/org/python/core/PyTuple.java =================================================================== --- trunk/jython/src/org/python/core/PyTuple.java 2008-07-21 01:38:17 UTC (rev 4976) +++ trunk/jython/src/org/python/core/PyTuple.java 2008-07-21 01:43:14 UTC (rev 4977) @@ -191,9 +191,13 @@ return repeat(count); } + public PyObject __iter__() { + return tuple___iter__(); + } + @ExposedMethod public PyObject tuple___iter__() { - return seq___iter__(); + return new PyFastSequenceIter(this); } @ExposedMethod(defaults = "null") This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-21 01:38:49
|
Revision: 4976 http://jython.svn.sourceforge.net/jython/?rev=4976&view=rev Author: pjenvey Date: 2008-07-21 01:38:17 +0000 (Mon, 21 Jul 2008) Log Message: ----------- small cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/PySequence.java Modified: trunk/jython/src/org/python/core/PySequence.java =================================================================== --- trunk/jython/src/org/python/core/PySequence.java 2008-07-19 23:23:25 UTC (rev 4975) +++ trunk/jython/src/org/python/core/PySequence.java 2008-07-21 01:38:17 UTC (rev 4976) @@ -256,7 +256,11 @@ } } - public synchronized PyObject __finditem__(int index) { + public PyObject __finditem__(int index) { + return seq___finditem__(index); + } + + final synchronized PyObject seq___finditem__(int index) { index = fixindex(index); if(index == -1) { return null; @@ -271,7 +275,7 @@ final PyObject seq___finditem__(PyObject index) { if(index instanceof PyInteger || index instanceof PyLong) { - return __finditem__(index.asInt()); + return seq___finditem__(index.asInt()); } else if(index instanceof PySlice) { PySlice s = (PySlice)index; return __getslice__(s.start, s.stop, s.step); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2008-07-19 23:24:09
|
Revision: 4975 http://jython.svn.sourceforge.net/jython/?rev=4975&view=rev Author: pjenvey Date: 2008-07-19 23:23:25 +0000 (Sat, 19 Jul 2008) Log Message: ----------- reintegrate r3069: don't abspath __classpath__ in sys.path Modified Paths: -------------- trunk/jython/Lib/site.py Modified: trunk/jython/Lib/site.py =================================================================== --- trunk/jython/Lib/site.py 2008-07-19 22:48:21 UTC (rev 4974) +++ trunk/jython/Lib/site.py 2008-07-19 23:23:25 UTC (rev 4975) @@ -61,7 +61,10 @@ def makepath(*paths): - dir = os.path.abspath(os.path.join(*paths)) + dir = os.path.join(*paths) + if dir == '__classpath__': + return dir, dir + dir = os.path.abspath(dir) return dir, os.path.normcase(dir) for m in sys.modules.values(): This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2008-07-19 22:55:51
|
Revision: 4974 http://jython.svn.sourceforge.net/jython/?rev=4974&view=rev Author: fwierzbicki Date: 2008-07-19 22:48:21 +0000 (Sat, 19 Jul 2008) Log Message: ----------- Make PythonTree's toStringTree more easily comparable with ast/astview.py output. This will help with the walkerless Python.g, as it doesn't quite parse ast/astview.py yet. Modified Paths: -------------- branches/asm/ast/asdl_antlr.py branches/asm/src/org/python/antlr/PythonTree.java 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-19 05:54:20 UTC (rev 4973) +++ branches/asm/ast/asdl_antlr.py 2008-07-19 22:48:21 UTC (rev 4974) @@ -308,12 +308,13 @@ # The toStringTree() method self.emit("public String toStringTree() {", depth) - self.emit('StringBuffer sb = new StringBuffer("%s[");' % clsname, + 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("sb.append(dumpThis(%s));" % f.name, depth+1) + self.emit('sb.append(",");', depth+1) + self.emit('sb.append(")");', depth+1) self.emit("return sb.toString();", depth+1) self.emit("}", depth) self.emit("", 0) Modified: branches/asm/src/org/python/antlr/PythonTree.java =================================================================== --- branches/asm/src/org/python/antlr/PythonTree.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/PythonTree.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -83,13 +83,12 @@ public String toStringTree() { if (children == null || children.size() == 0) { - // System.out.println("Where are my children? -- asks " + token.getText()); - return this.toString() + "[" + this.info() + "]"; + return this.toString();// + "[" + this.info() + "]"; } StringBuffer buf = new StringBuffer(); if (!isNil()) { buf.append("("); - buf.append(this.toString() + "[" + this.info() + "]"); + buf.append(this.toString());// + "[" + this.info() + "]"); buf.append(' '); } for (int i = 0; children != null && i < children.size(); i++) { @@ -105,6 +104,34 @@ return buf.toString(); } + protected String dumpThis(String s) { + return s; + } + + protected String dumpThis(Object o) { + if (o instanceof PythonTree) { + return ((PythonTree)o).toStringTree(); + } + return String.valueOf(o); + } + + protected String dumpThis(Object[] s) { + StringBuffer sb = new StringBuffer(); + if (s == null) { + sb.append("null"); + } else { + sb.append("("); + for (int i = 0; i < s.length; i++) { + if (i > 0) + sb.append(", "); + sb.append(dumpThis(s[i])); + } + sb.append(")"); + } + + return sb.toString(); + } + public <R> R accept(VisitorIF<R> visitor) throws Exception { throw new RuntimeException("Unexpected node: " + this); } Modified: branches/asm/src/org/python/antlr/ast/Assert.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Assert.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Assert["); + StringBuffer sb = new StringBuffer("Assert("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("msg="); - sb.append(this.msg); - sb.append("]"); + sb.append(dumpThis(msg)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Assign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Assign.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -50,12 +50,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Assign["); + StringBuffer sb = new StringBuffer("Assign("); sb.append("targets="); - sb.append(this.targets); + sb.append(dumpThis(targets)); + sb.append(","); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Attribute.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Attribute.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Attribute["); + StringBuffer sb = new StringBuffer("Attribute("); sb.append("value="); - sb.append(this.value); + sb.append(dumpThis(value)); + sb.append(","); sb.append("attr="); - sb.append(this.attr); + sb.append(dumpThis(attr)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/AugAssign.java =================================================================== --- branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/AugAssign.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("AugAssign["); + StringBuffer sb = new StringBuffer("AugAssign("); sb.append("target="); - sb.append(this.target); + sb.append(dumpThis(target)); + sb.append(","); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/BinOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/BinOp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -41,14 +41,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("BinOp["); + StringBuffer sb = new StringBuffer("BinOp("); sb.append("left="); - sb.append(this.left); + sb.append(dumpThis(left)); + sb.append(","); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("right="); - sb.append(this.right); - sb.append("]"); + sb.append(dumpThis(right)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/BoolOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/BoolOp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -50,12 +50,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("BoolOp["); + StringBuffer sb = new StringBuffer("BoolOp("); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("values="); - sb.append(this.values); - sb.append("]"); + sb.append(dumpThis(values)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Break.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Break.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Break.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Break["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Break("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Call.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Call.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Call.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -81,18 +81,23 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Call["); + StringBuffer sb = new StringBuffer("Call("); sb.append("func="); - sb.append(this.func); + sb.append(dumpThis(func)); + sb.append(","); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("keywords="); - sb.append(this.keywords); + sb.append(dumpThis(keywords)); + sb.append(","); sb.append("starargs="); - sb.append(this.starargs); + sb.append(dumpThis(starargs)); + sb.append(","); sb.append("kwargs="); - sb.append(this.kwargs); - sb.append("]"); + sb.append(dumpThis(kwargs)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ClassDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ClassDef.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -72,14 +72,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ClassDef["); + StringBuffer sb = new StringBuffer("ClassDef("); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("bases="); - sb.append(this.bases); + sb.append(dumpThis(bases)); + sb.append(","); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Compare.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Compare.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -61,14 +61,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Compare["); + StringBuffer sb = new StringBuffer("Compare("); sb.append("left="); - sb.append(this.left); + sb.append(dumpThis(left)); + sb.append(","); sb.append("ops="); - sb.append(this.ops); + sb.append(dumpThis(ops)); + sb.append(","); sb.append("comparators="); - sb.append(this.comparators); - sb.append("]"); + sb.append(dumpThis(comparators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Continue.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Continue.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Continue["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Continue("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Delete.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Delete.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Delete["); + StringBuffer sb = new StringBuffer("Delete("); sb.append("targets="); - sb.append(this.targets); - sb.append("]"); + sb.append(dumpThis(targets)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Dict.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Dict.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -65,12 +65,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Dict["); + StringBuffer sb = new StringBuffer("Dict("); sb.append("keys="); - sb.append(this.keys); + sb.append(dumpThis(keys)); + sb.append(","); sb.append("values="); - sb.append(this.values); - sb.append("]"); + sb.append(dumpThis(values)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Ellipsis.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Ellipsis.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Ellipsis["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Ellipsis("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Exec.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Exec.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Exec["); + StringBuffer sb = new StringBuffer("Exec("); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("globals="); - sb.append(this.globals); + sb.append(dumpThis(globals)); + sb.append(","); sb.append("locals="); - sb.append(this.locals); - sb.append("]"); + sb.append(dumpThis(locals)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Expr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Expr.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Expr["); + StringBuffer sb = new StringBuffer("Expr("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Expression.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Expression.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Expression["); + StringBuffer sb = new StringBuffer("Expression("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ExtSlice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ExtSlice.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ExtSlice["); + StringBuffer sb = new StringBuffer("ExtSlice("); sb.append("dims="); - sb.append(this.dims); - sb.append("]"); + sb.append(dumpThis(dims)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/For.java =================================================================== --- branches/asm/src/org/python/antlr/ast/For.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/For.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -77,16 +77,20 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("For["); + StringBuffer sb = new StringBuffer("For("); sb.append("target="); - sb.append(this.target); + sb.append(dumpThis(target)); + sb.append(","); sb.append("iter="); - sb.append(this.iter); + sb.append(dumpThis(iter)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/FunctionDef.java =================================================================== --- branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/FunctionDef.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -77,16 +77,20 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("FunctionDef["); + StringBuffer sb = new StringBuffer("FunctionDef("); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("decorators="); - sb.append(this.decorators); - sb.append("]"); + sb.append(dumpThis(decorators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/GeneratorExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/GeneratorExp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -53,12 +53,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("GeneratorExp["); + StringBuffer sb = new StringBuffer("GeneratorExp("); sb.append("elt="); - sb.append(this.elt); + sb.append(dumpThis(elt)); + sb.append(","); sb.append("generators="); - sb.append(this.generators); - sb.append("]"); + sb.append(dumpThis(generators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Global.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Global.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Global.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Global["); + StringBuffer sb = new StringBuffer("Global("); sb.append("names="); - sb.append(this.names); - sb.append("]"); + sb.append(dumpThis(names)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/If.java =================================================================== --- branches/asm/src/org/python/antlr/ast/If.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/If.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -72,14 +72,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("If["); + StringBuffer sb = new StringBuffer("If("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/IfExp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/IfExp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("IfExp["); + StringBuffer sb = new StringBuffer("IfExp("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Import.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Import.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Import.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Import["); + StringBuffer sb = new StringBuffer("Import("); sb.append("names="); - sb.append(this.names); - sb.append("]"); + sb.append(dumpThis(names)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ImportFrom.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ImportFrom.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -58,14 +58,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ImportFrom["); + StringBuffer sb = new StringBuffer("ImportFrom("); sb.append("module="); - sb.append(this.module); + sb.append(dumpThis(module)); + sb.append(","); sb.append("names="); - sb.append(this.names); + sb.append(dumpThis(names)); + sb.append(","); sb.append("level="); - sb.append(this.level); - sb.append("]"); + sb.append(dumpThis(level)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Index.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Index.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Index.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Index["); + StringBuffer sb = new StringBuffer("Index("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Interactive.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Interactive.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Interactive["); + StringBuffer sb = new StringBuffer("Interactive("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Lambda.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Lambda.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Lambda["); + StringBuffer sb = new StringBuffer("Lambda("); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/List.java =================================================================== --- branches/asm/src/org/python/antlr/ast/List.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/List.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -50,12 +50,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("List["); + StringBuffer sb = new StringBuffer("List("); sb.append("elts="); - sb.append(this.elts); + sb.append(dumpThis(elts)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/ListComp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/ListComp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -52,12 +52,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("ListComp["); + StringBuffer sb = new StringBuffer("ListComp("); sb.append("elt="); - sb.append(this.elt); + sb.append(dumpThis(elt)); + sb.append(","); sb.append("generators="); - sb.append(this.generators); - sb.append("]"); + sb.append(dumpThis(generators)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Module.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Module.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Module.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Module["); + StringBuffer sb = new StringBuffer("Module("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Name.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Name.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Name.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Name["); + StringBuffer sb = new StringBuffer("Name("); sb.append("id="); - sb.append(this.id); + sb.append(dumpThis(id)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Num.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Num.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Num.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Num["); + StringBuffer sb = new StringBuffer("Num("); sb.append("n="); - sb.append(this.n); - sb.append("]"); + sb.append(dumpThis(n)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Pass.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Pass.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -27,8 +27,8 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Pass["); - sb.append("]"); + StringBuffer sb = new StringBuffer("Pass("); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Print.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Print.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Print.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -56,14 +56,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Print["); + StringBuffer sb = new StringBuffer("Print("); sb.append("dest="); - sb.append(this.dest); + sb.append(dumpThis(dest)); + sb.append(","); sb.append("values="); - sb.append(this.values); + sb.append(dumpThis(values)); + sb.append(","); sb.append("nl="); - sb.append(this.nl); - sb.append("]"); + sb.append(dumpThis(nl)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Raise.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Raise.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -41,14 +41,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Raise["); + StringBuffer sb = new StringBuffer("Raise("); sb.append("type="); - sb.append(this.type); + sb.append(dumpThis(type)); + sb.append(","); sb.append("inst="); - sb.append(this.inst); + sb.append(dumpThis(inst)); + sb.append(","); sb.append("tback="); - sb.append(this.tback); - sb.append("]"); + sb.append(dumpThis(tback)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Repr.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Repr.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Repr["); + StringBuffer sb = new StringBuffer("Repr("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Return.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Return.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Return.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Return["); + StringBuffer sb = new StringBuffer("Return("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Slice.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Slice.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Slice["); + StringBuffer sb = new StringBuffer("Slice("); sb.append("lower="); - sb.append(this.lower); + sb.append(dumpThis(lower)); + sb.append(","); sb.append("upper="); - sb.append(this.upper); + sb.append(dumpThis(upper)); + sb.append(","); sb.append("step="); - sb.append(this.step); - sb.append("]"); + sb.append(dumpThis(step)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Str.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Str.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Str.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Str["); + StringBuffer sb = new StringBuffer("Str("); sb.append("s="); - sb.append(this.s); - sb.append("]"); + sb.append(dumpThis(s)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Subscript.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Subscript.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -42,14 +42,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Subscript["); + StringBuffer sb = new StringBuffer("Subscript("); sb.append("value="); - sb.append(this.value); + sb.append(dumpThis(value)); + sb.append(","); sb.append("slice="); - sb.append(this.slice); + sb.append(dumpThis(slice)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Suite.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Suite.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -46,10 +46,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Suite["); + StringBuffer sb = new StringBuffer("Suite("); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/TryExcept.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/TryExcept.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -88,14 +88,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("TryExcept["); + StringBuffer sb = new StringBuffer("TryExcept("); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("handlers="); - sb.append(this.handlers); + sb.append(dumpThis(handlers)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/TryFinally.java =================================================================== --- branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/TryFinally.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -66,12 +66,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("TryFinally["); + StringBuffer sb = new StringBuffer("TryFinally("); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("finalbody="); - sb.append(this.finalbody); - sb.append("]"); + sb.append(dumpThis(finalbody)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Tuple.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Tuple.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -51,12 +51,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Tuple["); + StringBuffer sb = new StringBuffer("Tuple("); sb.append("elts="); - sb.append(this.elts); + sb.append(dumpThis(elts)); + sb.append(","); sb.append("ctx="); - sb.append(this.ctx); - sb.append("]"); + sb.append(dumpThis(ctx)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/UnaryOp.java =================================================================== --- branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/UnaryOp.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("UnaryOp["); + StringBuffer sb = new StringBuffer("UnaryOp("); sb.append("op="); - sb.append(this.op); + sb.append(dumpThis(op)); + sb.append(","); sb.append("operand="); - sb.append(this.operand); - sb.append("]"); + sb.append(dumpThis(operand)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Unicode.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Unicode.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Unicode["); + StringBuffer sb = new StringBuffer("Unicode("); sb.append("s="); - sb.append(this.s); - sb.append("]"); + sb.append(dumpThis(s)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/While.java =================================================================== --- branches/asm/src/org/python/antlr/ast/While.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/While.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -73,14 +73,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("While["); + StringBuffer sb = new StringBuffer("While("); sb.append("test="); - sb.append(this.test); + sb.append(dumpThis(test)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("orelse="); - sb.append(this.orelse); - sb.append("]"); + sb.append(dumpThis(orelse)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/With.java =================================================================== --- branches/asm/src/org/python/antlr/ast/With.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/With.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -58,14 +58,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("With["); + StringBuffer sb = new StringBuffer("With("); sb.append("context_expr="); - sb.append(this.context_expr); + sb.append(dumpThis(context_expr)); + sb.append(","); sb.append("optional_vars="); - sb.append(this.optional_vars); + sb.append(dumpThis(optional_vars)); + sb.append(","); sb.append("body="); - sb.append(this.body); - sb.append("]"); + sb.append(dumpThis(body)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/Yield.java =================================================================== --- branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/Yield.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -31,10 +31,11 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("Yield["); + StringBuffer sb = new StringBuffer("Yield("); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/aliasType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/aliasType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("alias["); + StringBuffer sb = new StringBuffer("alias("); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("asname="); - sb.append(this.asname); - sb.append("]"); + sb.append(dumpThis(asname)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/argumentsType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/argumentsType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -77,16 +77,20 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("arguments["); + StringBuffer sb = new StringBuffer("arguments("); sb.append("args="); - sb.append(this.args); + sb.append(dumpThis(args)); + sb.append(","); sb.append("vararg="); - sb.append(this.vararg); + sb.append(dumpThis(vararg)); + sb.append(","); sb.append("kwarg="); - sb.append(this.kwarg); + sb.append(dumpThis(kwarg)); + sb.append(","); sb.append("defaults="); - sb.append(this.defaults); - sb.append("]"); + sb.append(dumpThis(defaults)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/comprehensionType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/comprehensionType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -57,14 +57,17 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("comprehension["); + StringBuffer sb = new StringBuffer("comprehension("); sb.append("target="); - sb.append(this.target); + sb.append(dumpThis(target)); + sb.append(","); sb.append("iter="); - sb.append(this.iter); + sb.append(dumpThis(iter)); + sb.append(","); sb.append("ifs="); - sb.append(this.ifs); - sb.append("]"); + sb.append(dumpThis(ifs)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/excepthandlerType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/excepthandlerType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -66,18 +66,23 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("excepthandler["); + StringBuffer sb = new StringBuffer("excepthandler("); sb.append("type="); - sb.append(this.type); + sb.append(dumpThis(type)); + sb.append(","); sb.append("name="); - sb.append(this.name); + sb.append(dumpThis(name)); + sb.append(","); sb.append("body="); - sb.append(this.body); + sb.append(dumpThis(body)); + sb.append(","); sb.append("lineno="); - sb.append(this.lineno); + sb.append(dumpThis(lineno)); + sb.append(","); sb.append("col_offset="); - sb.append(this.col_offset); - sb.append("]"); + sb.append(dumpThis(col_offset)); + sb.append(","); + sb.append(")"); return sb.toString(); } Modified: branches/asm/src/org/python/antlr/ast/keywordType.java =================================================================== --- branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-19 05:54:20 UTC (rev 4973) +++ branches/asm/src/org/python/antlr/ast/keywordType.java 2008-07-19 22:48:21 UTC (rev 4974) @@ -35,12 +35,14 @@ } public String toStringTree() { - StringBuffer sb = new StringBuffer("keyword["); + StringBuffer sb = new StringBuffer("keyword("); sb.append("arg="); - sb.append(this.arg); + sb.append(dumpThis(arg)); + sb.append(","); sb.append("value="); - sb.append(this.value); - sb.append("]"); + sb.append(dumpThis(value)); + sb.append(","); + sb.append(")"); return sb.toString(); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-19 05:54:22
|
Revision: 4973 http://jython.svn.sourceforge.net/jython/?rev=4973&view=rev Author: nriley Date: 2008-07-19 05:54:20 +0000 (Sat, 19 Jul 2008) Log Message: ----------- Clean up install targets; allow install to be run without full-build; normalize source directory structure between checked-out and installed versions. Modified Paths: -------------- branches/asm/build.xml Modified: branches/asm/build.xml =================================================================== --- branches/asm/build.xml 2008-07-19 05:49:11 UTC (rev 4972) +++ branches/asm/build.xml 2008-07-19 05:54:20 UTC (rev 4973) @@ -162,6 +162,7 @@ <available property="informix.present" classname="com.informix.jdbc.IfxDriver" classpath="${informix.jar}" /> <available property="oracle.present" classname="oracle.jdbc.driver.OracleDriver" classpath="${oracle.jar}" /> + <available property="cpythonlib.present" file="${jython.base.dir}/CPythonLib.includes"/> <path id="test.classpath"> <path refid="main.classpath"/> @@ -268,14 +269,13 @@ <echo>templates.dir = '${templates.dir}'</echo> <echo>templates.lazy = '${templates.lazy}'</echo> <echo>python.lib = '${python.lib}'</echo> - <echo>javaccHome = '${javaccHome}'</echo> <echo>build.compiler = '${build.compiler}'</echo> <echo>jdk.target.version = '${jdk.target.version}'</echo> <echo>jdk.source.version = '${jdk.source.version}'</echo> <echo>deprecation = '${deprecation}'</echo> <echo>debug = '${debug}'</echo> <echo>nowarn = '${nowarn}'</echo> - <echo>--- properties (used for full-build only ) ---</echo> + <echo>--- properties (used for full-build only) ---</echo> <echo>python.exe = '${python.exe}'</echo> <echo>svn.main.dir = '${svn.main.dir}'</echo> <echo>svn.revision = '${svn.revision}'</echo> @@ -438,7 +438,7 @@ </target> - <target name="compile" depends="init,antlr_gen,copy-antlr,jarjar,brand-version"> + <target name="compile" depends="init,antlr_gen,jarjar,brand-version"> <javac destdir="${compile.dir}" target="${jdk.target.version}" source="${jdk.source.version}" @@ -585,13 +585,12 @@ </javadoc> </target> - <target name="copy-antlr" if="full-build"> - <copy todir="${dist.dir}/src/java" preservelastmodified="true"> - <fileset dir="${gensrc.dir}" /> - </copy> + <target name="copy-license" if="do.checkout"> + <echo>copy CPython LICENSE from ${svn.checkout.dir}/python</echo> + <copy file="${svn.checkout.dir}/python/LICENSE" tofile="${dist.dir}/LICENSE_CPython.txt" preservelastmodified="true" /> </target> - <target name="copy-full" depends="copy-lib" if="full-build"> + <target name="copy-full" depends="copy-lib, copy-license" if="full-build"> <echo>copy misc files from ${jython.base.dir}</echo> <copy todir="${dist.dir}" preservelastmodified="true"> <fileset dir="${jython.base.dir}" @@ -599,18 +598,20 @@ /> </copy> - <echo>copy CPython LICENSE from ${svn.checkout.dir}/python</echo> - <copy file="${svn.checkout.dir}/python/LICENSE" tofile="${dist.dir}/LICENSE_CPython.txt" preservelastmodified="true" /> - <!-- sources: todir has to correspond with installer/**/JarInstaller.java --> <echo>copy sources from ${jython.base.dir}</echo> - <copy todir="${dist.dir}/src/java" preservelastmodified="true"> + <copy todir="${dist.dir}" preservelastmodified="true"> <fileset dir="${jython.base.dir}"> <include name="src/**/*.java" /> <include name="src/com/**/*.properties" /> + <include name="src/shell/*" /> + <include name="src/templates/*" /> <include name="Lib/jxxload_help/*.java" /> + <include name="src/org/**/ucnhash.dat" /> + <include name="grammar/*.g" /> + <include name="extlibs/**/*.jar" /> <include name="tests/java/**/*.java" /> - <include name="src/org/**/ucnhash.dat" /> + <include name="CoreExposed.includes" /> </fileset> </copy> @@ -629,19 +630,17 @@ </copy> </target> - <target name="copy-lib" depends="init"> + <target name="copy-lib" depends="init, copy-javalib, copy-cpythonlib"> + <!-- XXX untested and most likely broken in 2.5 <copy todir="${dist.dir}" preservelastmodified="true"> <fileset dir="${jython.base.dir}" includes="Tools/**/*.py" /> </copy> + --> <copy todir="${dist.dir}/Lib"> <fileset dir="${jython.base.dir}/Lib"> <exclude name="**/*.class"/> </fileset> - <fileset dir="${python.lib}" excludes="**/*.pyc, **/*.pyo" includesfile="${jython.base.dir}/CPythonLib.includes"> - <!-- The include file gets all of CPythonLib's test directory, but we only want the ones from Jython's Lib. --> - <present present="srconly" targetdir="${jython.base.dir}/Lib"/> - </fileset> </copy> <copy todir="${dist.dir}/bin"> @@ -652,6 +651,18 @@ <fileset dir="${dist.dir}/bin" /> </chmod> + </target> + + <target name="copy-cpythonlib" if="cpythonlib.present"> + <copy todir="${dist.dir}/Lib"> + <fileset dir="${python.lib}" excludes="**/*.pyc, **/*.pyo" includesfile="${jython.base.dir}/CPythonLib.includes"> + <!-- The include file gets all of CPythonLib's test directory, but we only want the ones from Jython's Lib. --> + <present present="srconly" targetdir="${jython.base.dir}/Lib"/> + </fileset> + </copy> + </target> + + <target name="copy-javalib" unless="full-build"> <copy todir="${dist.dir}/javalib"> <fileset dir="${jython.base.dir}/extlibs"> <exclude name="profile.properties"/> @@ -663,8 +674,14 @@ </copy> </target> + <!-- if install called by itself, make sure all the dependent targets run; + otherwise, redundant with full-check --> + <target name="install-init"> + <property name="full-build" value="true" /> + </target> + <!-- wrap the build into the installer --> - <target name="install" depends="brand-readme-version, jar-complete, javadoc, copy-full"> + <target name="install" depends="brand-readme-version, install-init, jar-complete, javadoc, copy-full"> <property name="install.src.dir" value="${jython.base.dir}/../installer25/src/java" /> <echo>compiling installer from ${install.src.dir}</echo> <javac srcdir="${install.src.dir}" This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <nr...@us...> - 2008-07-19 05:49:14
|
Revision: 4972 http://jython.svn.sourceforge.net/jython/?rev=4972&view=rev Author: nriley Date: 2008-07-19 05:49:11 +0000 (Sat, 19 Jul 2008) Log Message: ----------- remove jythonc script; make core install work again; install more source bits; prepend to new launcher scripts Modified Paths: -------------- branches/installer25/src/java/org/python/util/install/JarInstaller.java branches/installer25/src/java/org/python/util/install/StartScriptGenerator.java Modified: branches/installer25/src/java/org/python/util/install/JarInstaller.java =================================================================== --- branches/installer25/src/java/org/python/util/install/JarInstaller.java 2008-07-18 20:51:00 UTC (rev 4971) +++ branches/installer25/src/java/org/python/util/install/JarInstaller.java 2008-07-19 05:49:11 UTC (rev 4972) @@ -52,6 +52,8 @@ List coreLibFiles = new ArrayList(); if (!installationType.installSources()) { excludeDirs.add("src"); + excludeDirs.add("grammar"); + excludeDirs.add("extlibs"); } if (!installationType.installDocumentation()) { excludeDirs.add("Doc"); @@ -93,6 +95,10 @@ exclude = true; } } + // exclude build.xml when not installing source + if (!installationType.installSources() && zipEntryName.equals("build.xml")) + exclude = true; + // handle exclusion of core Lib files if (!exclude) { exclude = shouldExcludeFile(installationType, coreLibFiles, zipEntry, zipEntryName); @@ -133,6 +139,7 @@ _progressListener.progressStartScripts(); StartScriptGenerator generator = new StartScriptGenerator(targetDirectory, javaHome); generator.generateStartScripts(); + StandalonePackager.emptyDirectory(new File(targetDirectory, "bin"), null); } else { _progressListener.progressStandalone(); File jythonJar = new File(targetDirectory, JYTHON_JAR); @@ -220,6 +227,8 @@ coreLibFiles.add("javapath.py"); coreLibFiles.add("jreload.py"); coreLibFiles.add("marshal.py"); + coreLibFiles.add("os.py"); + coreLibFiles.add("posixpath.py"); coreLibFiles.add("random.py"); coreLibFiles.add("re.py"); coreLibFiles.add("site.py"); @@ -228,6 +237,7 @@ coreLibFiles.add("sre_compile.py"); coreLibFiles.add("sre_constants.py"); coreLibFiles.add("sre_parse.py"); + coreLibFiles.add("stat.py"); coreLibFiles.add("string.py"); coreLibFiles.add("zipfile.py"); coreLibFiles.add("zlib.py"); Modified: branches/installer25/src/java/org/python/util/install/StartScriptGenerator.java =================================================================== --- branches/installer25/src/java/org/python/util/install/StartScriptGenerator.java 2008-07-18 20:51:00 UTC (rev 4971) +++ branches/installer25/src/java/org/python/util/install/StartScriptGenerator.java 2008-07-19 05:49:11 UTC (rev 4972) @@ -1,6 +1,7 @@ package org.python.util.install; import java.io.File; +import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.text.MessageFormat; @@ -17,8 +18,6 @@ private final static String JYTHON = "jython"; private final static String JYTHON_BAT = "jython.bat"; - private final static String JYTHONC = "jythonc"; - private final static String JYTHONC_BAT = "jythonc.bat"; private final static String JYTHON_JAR = JarInstaller.JYTHON_JAR; static { @@ -73,7 +72,6 @@ protected final void generateStartScripts() throws IOException { generateJythonScript(); - generateJythoncScript(); } private final void generateJythonScript() throws IOException { @@ -90,43 +88,18 @@ } } - private final void generateJythoncScript() throws IOException { - switch (getFlavour()) { - case BOTH_FLAVOUR: - writeToFile(JYTHONC_BAT, getJythoncScript(WINDOWS_FLAVOUR)); - makeExecutable(writeToFile(JYTHONC, getJythoncScript(BOTH_FLAVOUR))); - break; - case WINDOWS_FLAVOUR: - writeToFile(JYTHONC_BAT, getJythoncScript(WINDOWS_FLAVOUR)); - break; - default: - makeExecutable(writeToFile(JYTHONC, getJythoncScript(UNIX_FLAVOUR))); - } - } - /** * only <code>protected</code> for unit test use */ protected final String getJythonScript(int flavour) throws IOException { if (flavour == WINDOWS_FLAVOUR) { - return getStartScript(getWindowsJythonTemplate()); + return getStartScript(getWindowsJythonTemplate()) + readFromFile(JYTHON_BAT); } else { - return getStartScript(getUnixJythonTemplate(flavour)); + return getStartScript(getUnixJythonTemplate()) + readFromFile(JYTHON); } } /** - * only <code>protected</code> for unit test use - */ - protected final String getJythoncScript(int flavour) throws IOException { - if (flavour == WINDOWS_FLAVOUR) { - return getStartScript(getWindowsJythoncTemplate()); - } else { - return getStartScript(getUnixJythoncTemplate()); - } - } - - /** * These placeholders are valid for all private methods: * * {0} : current date <br> @@ -150,8 +123,9 @@ */ private String getWindowsJythonTemplate() { StringBuffer buffer = getWindowsHeaderTemplate(); - buffer.append("\"{2}\\bin\\java.exe\" -Dpython.home=\"{3}\" -Dpython.executable=\"%0\" -classpath \"{3}\\" + JYTHON_JAR - + ";%CLASSPATH%\" org.python.util.jython %ARGS%" + WIN_CR_LF); + buffer.append("set JAVA_HOME=\"{2}\"" + WIN_CR_LF); + buffer.append("set JYTHON_HOME=\"{3}\"" + WIN_CR_LF); + buffer.append(WIN_CR_LF); return buffer.toString(); } @@ -160,32 +134,12 @@ * * @see getStartScript */ - private String getWindowsJythoncTemplate() { - StringBuffer buffer = getWindowsHeaderTemplate(); - buffer.append("\"{3}\\jython.bat\" \"{3}\\Tools\\jythonc\\jythonc.py\" %ARGS%" + WIN_CR_LF); - return buffer.toString(); - } - - /** - * placeholders: - * - * @see getStartScript - */ private StringBuffer getWindowsHeaderTemplate() { StringBuffer buffer = new StringBuffer(1000); buffer.append("@echo off" + WIN_CR_LF); buffer.append("rem This file was generated by the Jython installer" + WIN_CR_LF); buffer.append("rem Created on {0} by {1}" + WIN_CR_LF); buffer.append(WIN_CR_LF); - buffer.append("set ARGS=" + WIN_CR_LF); - buffer.append(WIN_CR_LF); - buffer.append(":loop" + WIN_CR_LF); - buffer.append("if [%1] == [] goto end" + WIN_CR_LF); - buffer.append(" set ARGS=%ARGS% %1" + WIN_CR_LF); - buffer.append(" shift" + WIN_CR_LF); - buffer.append(" goto loop" + WIN_CR_LF); - buffer.append(":end" + WIN_CR_LF); - buffer.append(WIN_CR_LF); return buffer; } @@ -194,11 +148,11 @@ * * @see getStartScript */ - private String getUnixJythonTemplate(int flavour) { + private String getUnixJythonTemplate() { StringBuffer buffer = getUnixHeaderTemplate(); - buffer.append("CP=\"{3}/" + JYTHON_JAR + "\"\n"); - buffer.append("if [ ! -z \"$CLASSPATH\" ]\nthen\n CP=$CP:$CLASSPATH\nfi\n"); - buffer.append("\"{2}/bin/java\" -Dpython.home=\"{3}\" -Dpython.executable=\"$0\" -classpath \"$CP\" org.python.util.jython \"$@\"\n"); + buffer.append("JAVA_HOME=\"{2}\"\n"); + buffer.append("JYTHON_HOME=\"{3}\"\n"); + buffer.append("\n"); return buffer.toString(); } @@ -207,20 +161,9 @@ * * @see getStartScript */ - private String getUnixJythoncTemplate() { - StringBuffer buffer = getUnixHeaderTemplate(); - buffer.append("\"{3}/jython\" \"{3}/Tools/jythonc/jythonc.py\" \"$@\"\n"); - return buffer.toString(); - } - - /** - * placeholders: - * - * @see getStartScript - */ private StringBuffer getUnixHeaderTemplate() { StringBuffer buffer = new StringBuffer(1000); - buffer.append("#!/bin/sh\n"); + buffer.append("#!/usr/bin/env bash\n"); buffer.append("\n"); buffer.append("# This file was generated by the Jython installer\n"); buffer.append("# Created on {0} by {1}\n"); @@ -230,6 +173,24 @@ /** * @param fileName The short file name, e.g. JYTHON_BAT + * + * @throws IOException + */ + private String readFromFile(String fileName) throws IOException { + File file = new File(new File(_targetDirectory, "bin"), fileName); + FileReader fileReader = new FileReader(file); + StringBuffer sb = new StringBuffer(); + char[] b = new char[8192]; + int n; + + while ( (n = fileReader.read(b)) > 0) { + sb.append(b, 0, n); + } + return sb.toString(); + } + + /** + * @param fileName The short file name, e.g. JYTHON_BAT * @param contents * * @throws IOException This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |