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: <zy...@us...> - 2009-04-18 23:28:34
|
Revision: 6242 http://jython.svn.sourceforge.net/jython/?rev=6242&view=rev Author: zyasoft Date: 2009-04-18 23:28:20 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Merged revisions 6230,6232-6236,6241 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r6230 | pjenvey | 2009-04-15 23:48:35 -0600 (Wed, 15 Apr 2009) | 1 line make BadPickleGet an actual exception ........ r6232 | pjenvey | 2009-04-16 17:59:40 -0600 (Thu, 16 Apr 2009) | 1 line cleanup/coding standards ........ r6233 | pjenvey | 2009-04-16 19:35:16 -0600 (Thu, 16 Apr 2009) | 2 lines fix LineBufferedWriter.write's result, cleanup ........ r6234 | pjenvey | 2009-04-16 19:38:24 -0600 (Thu, 16 Apr 2009) | 3 lines rename eof_fodder7 to match other SyntaxError'ing tests. avoids test_compiler from randomly importing it ........ r6235 | pjenvey | 2009-04-16 21:44:35 -0600 (Thu, 16 Apr 2009) | 3 lines o fix memoization with cyclic structures: http://bugs.python.org/issue998998 o cleanup persistent_id/load handling, allow persistent_load as a list ........ r6236 | fwierzbicki | 2009-04-17 08:06:01 -0600 (Fri, 17 Apr 2009) | 2 lines More tinkering to get a useful policy file for GAE testing. ........ r6241 | amak | 2009-04-18 07:06:43 -0600 (Sat, 18 Apr 2009) | 3 lines For the moment, we do not actually support IPV6. Before we can support it, we need to establish how such support can be adequately tested. Having the has_ipv6 flag as 1/True is misleading to the users. ........ Modified Paths: -------------- branches/newlist/Lib/socket.py branches/newlist/Lib/test/test_cpickle_jy.py branches/newlist/Lib/test/test_eof_jy.py branches/newlist/src/org/python/core/io/BufferedWriter.java branches/newlist/src/org/python/core/io/LineBufferedWriter.java branches/newlist/src/org/python/core/io/StreamIO.java branches/newlist/src/org/python/core/io/UniversalIOWrapper.java branches/newlist/src/org/python/modules/cPickle.java branches/newlist/tests/policy/nowrite.policy branches/newlist/tests/policy/run.sh Added Paths: ----------- branches/newlist/Lib/test/badsyntax_eof1.py Removed Paths: ------------- branches/newlist/Lib/test/eof_fodder7.py Property Changed: ---------------- branches/newlist/ Property changes on: branches/newlist ___________________________________________________________________ Modified: svnmerge-integrated - /branches/modjy:1-6074 /branches/pbcvm:1-6045 /trunk/jython:1-6228 + /branches/modjy:1-6074 /branches/pbcvm:1-6045 /trunk/jython:1-6241 Modified: branches/newlist/Lib/socket.py =================================================================== --- branches/newlist/Lib/socket.py 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/Lib/socket.py 2009-04-18 23:28:20 UTC (rev 6242) @@ -484,10 +484,11 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# For now, we DO NOT have complete IPV6 support. +has_ipv6 = False + # Name and address functions - -has_ipv6 = 1 - + def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) Copied: branches/newlist/Lib/test/badsyntax_eof1.py (from rev 6241, trunk/jython/Lib/test/badsyntax_eof1.py) =================================================================== --- branches/newlist/Lib/test/badsyntax_eof1.py (rev 0) +++ branches/newlist/Lib/test/badsyntax_eof1.py 2009-04-18 23:28:20 UTC (rev 6242) @@ -0,0 +1,5 @@ +def hi(): + pass + +def bye(): + hi( Deleted: branches/newlist/Lib/test/eof_fodder7.py =================================================================== --- branches/newlist/Lib/test/eof_fodder7.py 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/Lib/test/eof_fodder7.py 2009-04-18 23:28:20 UTC (rev 6242) @@ -1,5 +0,0 @@ -def hi(): - pass - -def bye(): - hi( Modified: branches/newlist/Lib/test/test_cpickle_jy.py =================================================================== --- branches/newlist/Lib/test/test_cpickle_jy.py 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/Lib/test/test_cpickle_jy.py 2009-04-18 23:28:20 UTC (rev 6242) @@ -7,13 +7,34 @@ import unittest from test import test_support +class MyClass(object): + pass + + 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_cyclic_memoize(self): + # http://bugs.python.org/issue998998 - cPickle shouldn't fail + # this, though pickle.py still does + m = MyClass() + m2 = MyClass() + s = set([m]) + m.foo = set([m2]) + m2.foo = s + + s2 = cPickle.loads(cPickle.dumps(s)) + self.assertEqual(len(s2), 1) + m3 = iter(s2).next() + self.assertEqual(len(m3.foo), 1) + m4 = iter(m3.foo).next() + self.assertEqual(m4.foo, s2) + + def test_main(): test_support.run_unittest(CPickleTestCase) Modified: branches/newlist/Lib/test/test_eof_jy.py =================================================================== --- branches/newlist/Lib/test/test_eof_jy.py 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/Lib/test/test_eof_jy.py 2009-04-18 23:28:20 UTC (rev 6242) @@ -47,7 +47,7 @@ def test_trailing_paren(self): try: - import eof_fodder7 + import badsyntax_eof1 except SyntaxError, cause: self.assertEquals(cause.lineno, 5) Modified: branches/newlist/src/org/python/core/io/BufferedWriter.java =================================================================== --- branches/newlist/src/org/python/core/io/BufferedWriter.java 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/src/org/python/core/io/BufferedWriter.java 2009-04-18 23:28:20 UTC (rev 6242) @@ -53,10 +53,11 @@ int totalToWrite = total - toBuffer; int count = totalToWrite; + ByteBuffer[] bulk = new ByteBuffer[] {buffer, bytes}; // Prepare the buffer for writing buffer.flip(); while (count > 0) { - count -= rawIO.write(new ByteBuffer[] {buffer, bytes}); + count -= rawIO.write(bulk); } // Prepare the buffer for buffering buffer.clear(); Modified: branches/newlist/src/org/python/core/io/LineBufferedWriter.java =================================================================== --- branches/newlist/src/org/python/core/io/LineBufferedWriter.java 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/src/org/python/core/io/LineBufferedWriter.java 2009-04-18 23:28:20 UTC (rev 6242) @@ -23,7 +23,7 @@ /** {@inheritDoc} */ public int write(ByteBuffer bytes) { - int written = 0; + int size = bytes.remaining(); while (bytes.hasRemaining()) { byte next = bytes.get(); @@ -37,11 +37,10 @@ } if (next == LF_BYTE) { - written += buffer.position(); flush(); } } - return written; + return size; } } Modified: branches/newlist/src/org/python/core/io/StreamIO.java =================================================================== --- branches/newlist/src/org/python/core/io/StreamIO.java 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/src/org/python/core/io/StreamIO.java 2009-04-18 23:28:20 UTC (rev 6242) @@ -16,8 +16,8 @@ import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import org.python.core.Py; import org.python.core.imp; -import org.python.core.Py; /** * Raw I/O implementation for simple streams. @@ -82,9 +82,6 @@ * Construct a StreamIO for the given write channel. * * @param writeChannel a WritableByteChannel - * @param isatty boolean whether this io object is a tty device - * @param closefd boolean whether the underlying file is closed on - * close() (defaults to True) */ public StreamIO(WritableByteChannel writeChannel) { this(writeChannel, true); @@ -160,56 +157,62 @@ /** Unwrap one or more nested FilterInputStreams. */ private static FileDescriptor getInputFileDescriptor(InputStream stream) throws IOException { - if (stream == null) - return null; - if (stream instanceof FileInputStream) - return ((FileInputStream)stream).getFD(); - if (stream instanceof FilterInputStream) { - Field inField = null; - try { - inField = FilterInputStream.class.getDeclaredField("in"); - inField.setAccessible(true); - return getInputFileDescriptor((InputStream)inField.get(stream)); - } catch (Exception e) { - } finally { - if (inField != null && inField.isAccessible()) - inField.setAccessible(false); - } - } - return null; + if (stream == null) { + return null; + } + if (stream instanceof FileInputStream) { + return ((FileInputStream)stream).getFD(); + } + if (stream instanceof FilterInputStream) { + Field inField = null; + try { + inField = FilterInputStream.class.getDeclaredField("in"); + inField.setAccessible(true); + return getInputFileDescriptor((InputStream)inField.get(stream)); + } catch (Exception e) { + // XXX: masking other exceptions + } finally { + if (inField != null && inField.isAccessible()) + inField.setAccessible(false); + } + } + return null; } /** Unwrap one or more nested FilterOutputStreams. */ private static FileDescriptor getOutputFileDescriptor(OutputStream stream) throws IOException { - if (stream == null) - return null; - if (stream instanceof FileOutputStream) - return ((FileOutputStream)stream).getFD(); - if (stream instanceof FilterOutputStream) { - Field outField = null; - try { - outField = FilterOutputStream.class.getDeclaredField("out"); - outField.setAccessible(true); - return getOutputFileDescriptor((OutputStream)outField.get(stream)); - } catch (Exception e) { - } finally { - if (outField != null && outField.isAccessible()) - outField.setAccessible(false); - } - } - return null; + if (stream == null) { + return null; + } + if (stream instanceof FileOutputStream) { + return ((FileOutputStream)stream).getFD(); + } + if (stream instanceof FilterOutputStream) { + Field outField = null; + try { + outField = FilterOutputStream.class.getDeclaredField("out"); + outField.setAccessible(true); + return getOutputFileDescriptor((OutputStream)outField.get(stream)); + } catch (Exception e) { + // XXX: masking other exceptions + } finally { + if (outField != null && outField.isAccessible()) + outField.setAccessible(false); + } + } + return null; } /** {@inheritDoc} */ - public boolean isatty() { checkClosed(); FileDescriptor fd; try { - if ( ((fd = getInputFileDescriptor(inputStream)) == null) && - ((fd = getOutputFileDescriptor(outputStream)) == null)) - return false; + if ((fd = getInputFileDescriptor(inputStream)) == null + && (fd = getOutputFileDescriptor(outputStream)) == null) { + return false; + } } catch (IOException e) { return false; } Modified: branches/newlist/src/org/python/core/io/UniversalIOWrapper.java =================================================================== --- branches/newlist/src/org/python/core/io/UniversalIOWrapper.java 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/src/org/python/core/io/UniversalIOWrapper.java 2009-04-18 23:28:20 UTC (rev 6242) @@ -3,7 +3,6 @@ import java.nio.ByteBuffer; import java.util.EnumSet; -import java.util.Iterator; import org.python.core.Py; import org.python.core.PyObject; @@ -189,7 +188,6 @@ byte[] readaheadArray; int readaheadPos; int interimBuilderPos; - String line; do { readaheadArray = readahead.array(); @@ -313,12 +311,12 @@ if (size == 0) { return Py.None; } else if (size == 1) { - Newline newline = (Newline)newlineTypes.iterator().next(); + Newline newline = newlineTypes.iterator().next(); return new PyString(newline.getValue()); } - int i = 0; PyObject[] newlines = new PyObject[size]; + int i = 0; for (Newline newline : newlineTypes) { newlines[i++] = new PyString(newline.getValue()); } Modified: branches/newlist/src/org/python/modules/cPickle.java =================================================================== --- branches/newlist/src/org/python/modules/cPickle.java 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/src/org/python/modules/cPickle.java 2009-04-18 23:28:20 UTC (rev 6242) @@ -384,11 +384,8 @@ public static PyObject PicklingError; public static PyObject UnpickleableError; public static PyObject UnpicklingError; + public static PyObject BadPickleGet; - public static final PyString BadPickleGet = - new PyString("cPickle.BadPickleGet"); - - final static char MARK = '('; final static char STOP = '.'; final static char POP = '0'; @@ -510,6 +507,7 @@ PicklingError = Py.makeClass("PicklingError", PickleError, exceptionNamespace()); UnpickleableError = Py.makeClass("UnpickleableError", PicklingError, _UnpickleableError()); UnpicklingError = Py.makeClass("UnpicklingError", PickleError, exceptionNamespace()); + BadPickleGet = Py.makeClass("BadPickleGet", UnpicklingError, exceptionNamespace()); } public static PyObject exceptionNamespace() { @@ -772,14 +770,8 @@ private void save(PyObject object, boolean pers_save) { - if (!pers_save) { - if (persistent_id != null) { - PyObject pid = persistent_id.__call__(object); - if (pid != Py.None) { - save_pers(pid); - return; - } - } + if (!pers_save && persistent_id != null && save_pers(object, persistent_id)) { + return; } int d = get_id(object); @@ -803,12 +795,8 @@ if (save_type(object, t)) return; - if (inst_persistent_id != null) { - PyObject pid = inst_persistent_id.__call__(object); - if (pid != Py.None) { - save_pers(pid); - return; - } + if (!pers_save && inst_persistent_id != null && save_pers(object, inst_persistent_id)) { + return; } if (Py.isSubClass(t, PyType.TYPE)) { @@ -861,13 +849,20 @@ "Second element of tupe returned by " + reduce.__repr__() + " must be a tuple"); } - save_reduce(callable, arg_tup, state, listitems, dictitems, putMemo(d, object)); - + save_reduce(callable, arg_tup, state, listitems, dictitems, object); } - final private void save_pers(PyObject pid) { + final private boolean save_pers(PyObject object, PyObject pers_func) { + PyObject pid = pers_func.__call__(object); + if (pid == Py.None) { + return false; + } + if (protocol == 0) { + if (!Py.isInstance(pid, PyString.TYPE)) { + throw new PyException(PicklingError, "persistent id must be string"); + } file.write(PERSID); file.write(pid.toString()); file.write("\n"); @@ -875,10 +870,12 @@ save(pid, true); file.write(BINPERSID); } + return true; } final private void save_reduce(PyObject callable, PyObject arg_tup, - PyObject state, PyObject listitems, PyObject dictitems, int memoId) + PyObject state, PyObject listitems, PyObject dictitems, + PyObject object) { PyObject callableName = callable.__findattr__("__name__"); if(protocol >= 2 && callableName != null @@ -896,7 +893,10 @@ save(arg_tup); file.write(REDUCE); } - put(memoId); + + // Memoize + put(putMemo(get_id(object), object)); + if (listitems != Py.None) { batch_appends(listitems); } @@ -1699,17 +1699,30 @@ final private void load_persid() { - String pid = file.readlineNoNl(); - push(persistent_load.__call__(new PyString(pid))); + load_persid(new PyString(file.readlineNoNl())); } final private void load_binpersid() { - PyObject pid = pop(); - push(persistent_load.__call__(pid)); + load_persid(pop()); } + final private void load_persid(PyObject pid) { + if (persistent_load == null) { + throw new PyException(UnpicklingError, + "A load persistent id instruction was encountered,\n" + + "but no persistent_load function was specified."); + } + if (persistent_load instanceof PyList) { + ((PyList)persistent_load).append(pid); + } else { + pid = persistent_load.__call__(pid); + } + push(pid); + } + + final private void load_none() { push(Py.None); } @@ -2067,16 +2080,18 @@ final private void load_get() { String py_str = file.readlineNoNl(); PyObject value = memo.get(py_str); - if (value == null) + if (value == null) { throw new PyException(BadPickleGet, py_str); + } push(value); } final private void load_binget() { String py_key = String.valueOf((int)file.read(1).charAt(0)); PyObject value = memo.get(py_key); - if (value == null) + if (value == null) { throw new PyException(BadPickleGet, py_key); + } push(value); } @@ -2084,8 +2099,9 @@ int i = read_binint(); String py_key = String.valueOf(i); PyObject value = memo.get(py_key); - if (value == null) + if (value == null) { throw new PyException(BadPickleGet, py_key); + } push(value); } Modified: branches/newlist/tests/policy/nowrite.policy =================================================================== --- branches/newlist/tests/policy/nowrite.policy 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/tests/policy/nowrite.policy 2009-04-18 23:28:20 UTC (rev 6242) @@ -1,3 +1,8 @@ grant { + permission java.lang.RuntimePermission "createClassLoader"; + permission java.lang.RuntimePermission "getProtectionDomain"; permission java.util.PropertyPermission "*", "read"; + permission java.io.FilePermission "<<ALL FILES>>", "read"; + + permission java.lang.RuntimePermission "accessDeclaredMembers"; }; Modified: branches/newlist/tests/policy/run.sh =================================================================== --- branches/newlist/tests/policy/run.sh 2009-04-18 13:06:43 UTC (rev 6241) +++ branches/newlist/tests/policy/run.sh 2009-04-18 23:28:20 UTC (rev 6242) @@ -1 +1 @@ -java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ +java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython -Dpython.home=../../dist -Dpython.cachedir.skip=true $@ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-04-18 13:06:49
|
Revision: 6241 http://jython.svn.sourceforge.net/jython/?rev=6241&view=rev Author: amak Date: 2009-04-18 13:06:43 +0000 (Sat, 18 Apr 2009) Log Message: ----------- For the moment, we do not actually support IPV6. Before we can support it, we need to establish how such support can be adequately tested. Having the has_ipv6 flag as 1/True is misleading to the users. Modified Paths: -------------- trunk/jython/Lib/socket.py Modified: trunk/jython/Lib/socket.py =================================================================== --- trunk/jython/Lib/socket.py 2009-04-18 02:53:00 UTC (rev 6240) +++ trunk/jython/Lib/socket.py 2009-04-18 13:06:43 UTC (rev 6241) @@ -484,10 +484,11 @@ else: return self._do_receive_nio(0, num_bytes, flags) +# For now, we DO NOT have complete IPV6 support. +has_ipv6 = False + # Name and address functions - -has_ipv6 = 1 - + def _gethostbyaddr(name): # This is as close as I can get; at least the types are correct... addresses = java.net.InetAddress.getAllByName(gethostbyname(name)) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-18 02:53:03
|
Revision: 6240 http://jython.svn.sourceforge.net/jython/?rev=6240&view=rev Author: zyasoft Date: 2009-04-18 02:53:00 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Removed helper and transition to newlist classes and any corresponding references. Modified Paths: -------------- branches/newlist/CoreExposed.includes branches/newlist/src/org/python/core/Py.java branches/newlist/src/org/python/core/PyList.java branches/newlist/src/templates/mappings Removed Paths: ------------- branches/newlist/Lib/test/test_newtuple.py branches/newlist/src/org/python/core/PyNewTuple.java branches/newlist/src/org/python/core/PyNewTupleDerived.java branches/newlist/src/org/python/core/PyObjectArray.java branches/newlist/src/org/python/core/PyObjectList.java branches/newlist/src/org/python/core/PySequenceObjectList.java Modified: branches/newlist/CoreExposed.includes =================================================================== --- branches/newlist/CoreExposed.includes 2009-04-18 02:31:16 UTC (rev 6239) +++ branches/newlist/CoreExposed.includes 2009-04-18 02:53:00 UTC (rev 6240) @@ -27,8 +27,6 @@ org/python/core/PyMethod.class org/python/core/PyMethodDescr.class org/python/core/PyModule.class -org/python/core/PyNewList.class -org/python/core/PyNewTuple.class org/python/core/PyNone.class org/python/core/PyObject.class org/python/core/PyProperty.class Deleted: branches/newlist/Lib/test/test_newtuple.py =================================================================== --- branches/newlist/Lib/test/test_newtuple.py 2009-04-18 02:31:16 UTC (rev 6239) +++ branches/newlist/Lib/test/test_newtuple.py 2009-04-18 02:53:00 UTC (rev 6240) @@ -1,12 +0,0 @@ -import unittest -from test import test_support, seq_tests -from org.python.core import PyNewTuple as newtuple - -class TupleTest(seq_tests.CommonTest): - type2test = newtuple - -def test_main(): - test_support.run_unittest(TupleTest) - -if __name__=="__main__": - test_main() Modified: branches/newlist/src/org/python/core/Py.java =================================================================== --- branches/newlist/src/org/python/core/Py.java 2009-04-18 02:31:16 UTC (rev 6239) +++ branches/newlist/src/org/python/core/Py.java 2009-04-18 02:53:00 UTC (rev 6240) @@ -21,6 +21,8 @@ import org.python.antlr.base.mod; import com.kenai.constantine.platform.Errno; +import java.util.ArrayList; +import java.util.List; import org.python.compiler.Module; import org.python.core.adapter.ClassicPyObjectAdapter; import org.python.core.adapter.ExtensiblePyObjectAdapter; @@ -1932,13 +1934,12 @@ } catch (PyException exc) { } - PyObjectArray objs = new PyObjectArray(n); + List<PyObject> objs = new ArrayList<PyObject>(n); for (PyObject item : o.asIterable()) { objs.add(item); } - // Cut back if guess was too large. - objs.trimToSize(); - return (PyObject[]) objs.getArray(); + PyObject dest[] = new PyObject[0]; + return (objs.toArray(dest)); } } /** @deprecated */ Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-18 02:31:16 UTC (rev 6239) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-18 02:53:00 UTC (rev 6240) @@ -651,11 +651,6 @@ final void list_extend(PyObject o) { if (o instanceof PyList) { list.addAll(((PyList) o).list); - } else if (o instanceof PySequenceObjectList) { - PyObject other[] = ((PySequenceObjectList) o).getArray(); - for (int i = 0; i < other.length; i++) { - list.add(other[i]); - } } else { for (PyObject item : o.asIterable()) { list.add(item); Deleted: branches/newlist/src/org/python/core/PyNewTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyNewTuple.java 2009-04-18 02:31:16 UTC (rev 6239) +++ branches/newlist/src/org/python/core/PyNewTuple.java 2009-04-18 02:53:00 UTC (rev 6240) @@ -1,569 +0,0 @@ -// Copyright (c) Corporation for National Research Initiatives -package org.python.core; - -import java.util.Arrays; -import java.util.Collection; -import java.util.Collections; -import java.util.Iterator; -import java.util.List; -import java.util.ListIterator; - -import org.python.expose.ExposedMethod; -import org.python.expose.ExposedNew; -import org.python.expose.ExposedType; -import org.python.expose.MethodType; - -/** - * A builtin python tuple. - */ -@ExposedType(name = "newtuple", base = PyObject.class) -public class PyNewTuple extends PySequenceList implements List { - - public static final PyType TYPE = PyType.fromClass(PyNewTuple.class); - private final PyObject[] array; - private static final PyNewTuple EMPTY_TUPLE = new PyNewTuple(); - - public PyNewTuple() { - this(TYPE, Py.EmptyObjects); - } - - public PyNewTuple(PyObject... elements) { - this(TYPE, elements); - } - - public PyNewTuple(Collection<PyObject> collection) { - this(TYPE, collection); - } - - public PyNewTuple(PyType subtype, PyObject[] elements) { - super(subtype); -// System.err.println("Initializing from " + Arrays.toString(elements)); - if (elements == null) { - array = new PyObject[0]; - } else { - array = new PyObject[elements.length]; - System.arraycopy(elements, 0, array, 0, elements.length); - } - } - - public PyNewTuple(PyObject[] elements, boolean copy) { - this(TYPE, elements, copy); - } - - public PyNewTuple(PyType subtype, PyObject[] elements, boolean copy) { - super(subtype); - - if (copy) { - array = new PyObject[elements.length]; - System.arraycopy(elements, 0, array, 0, elements.length); - } else { - array = elements; - } - } - - public PyNewTuple(PyType subtype, Collection<PyObject> elements) { - super(subtype); - if (elements == null) { - array = new PyObject[0]; - } else { - array = new PyObject[elements.size()]; - elements.toArray(array); - } - } - - private static PyNewTuple fromArrayNoCopy(PyObject[] elements) { -// System.err.println("newtuple (no copy):" + Arrays.toString(elements)); - return new PyNewTuple(elements, false); - } - private volatile List<PyObject> cachedList = null; - - private List<PyObject> getList() { - if (cachedList == null) { - cachedList = Arrays.asList(array); - } - return cachedList; - } - - @ExposedNew - final static PyObject newtuple_new(PyNewWrapper new_, boolean init, PyType subtype, - PyObject[] args, String[] keywords) { -// System.err.println("newtuple_new"); - ArgParser ap = new ArgParser("newtuple", args, keywords, new String[]{"sequence"}, 0); - PyObject S = ap.getPyObject(0, null); -// System.err.println("newtuple: new_=" + new_ + ",S=" + S); - if (new_.for_type == subtype) { - if (S == null) { - return EMPTY_TUPLE; - } - if (S instanceof PyNewTupleDerived) { - return new PyNewTuple(((PyNewTuple) S).getArray()); - } - if (S instanceof PyNewTuple) { - return S; - } - return fromArrayNoCopy(Py.make_array(S)); - } else { - if (S == null) { - return new PyNewTupleDerived(subtype, Py.EmptyObjects); - } - return new PyNewTupleDerived(subtype, Py.make_array(S)); - } - } - - /** - * Return a new PyNewTuple from an iterable. - * - * Raises a TypeError if the object is not iterable. - * - * @param iterable an iterable PyObject - * @return a PyNewTuple containing each item in the iterable - */ - public static PyNewTuple fromIterable(PyObject iterable) { - return fromArrayNoCopy(Py.make_array(iterable)); - } - - protected PyObject getslice(int start, int stop, int step) { - if (step > 0 && stop < start) { - stop = start; - } - int n = sliceLength(start, stop, step); - PyObject[] newArray = new PyObject[n]; - PyObject[] array = getArray(); - - if (step == 1) { - System.arraycopy(array, start, newArray, 0, stop - start); - return fromArrayNoCopy(newArray); - } - int j = 0; - for (int i = start; j < n; i += step) { - newArray[j] = array[i]; - j++; - } - return fromArrayNoCopy(newArray); - } - - protected PyObject repeat(int count) { - if (count < 0) { - count = 0; - } - int size = size(); - if (size == 0 || count == 1) { - if (getType() == TYPE) { - // Since tuples are immutable, we can return a shared copy in this case - return this; - } - if (size == 0) { - return EMPTY_TUPLE; - } - } - - int newSize = size * count; - if (newSize / size != count) { - throw Py.MemoryError(""); - } - - PyObject[] array = getArray(); - PyObject[] newArray = new PyObject[newSize]; - for (int i = 0; i < count; i++) { - System.arraycopy(array, 0, newArray, i * size, size); - } - return fromArrayNoCopy(newArray); - } - - public int __len__() { - return newtuple___len__(); - } - - @ExposedMethod(doc = BuiltinDocs.tuple___len___doc) - final int newtuple___len__() { - return size(); - } - - @ExposedMethod(doc = BuiltinDocs.tuple___contains___doc) - final boolean newtuple___contains__(PyObject o) { - return super.__contains__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___ne___doc) - final PyObject newtuple___ne__(PyObject o) { - return super.__ne__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___eq___doc) - final PyObject newtuple___eq__(PyObject o) { - return super.__eq__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___gt___doc) - final PyObject newtuple___gt__(PyObject o) { - return super.__gt__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___ge___doc) - final PyObject newtuple___ge__(PyObject o) { - return super.__ge__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___lt___doc) - final PyObject newtuple___lt__(PyObject o) { - return super.__lt__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___le___doc) - final PyObject newtuple___le__(PyObject o) { - return super.__le__(o); - } - - public PyObject __add__(PyObject generic_other) { - return newtuple___add__(generic_other); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___add___doc) - final PyObject newtuple___add__(PyObject generic_other) { - PyNewTuple sum = null; - if (generic_other instanceof PyNewTuple) { - PyNewTuple other = (PyNewTuple) generic_other; - PyObject[] newArray = new PyObject[array.length + other.array.length]; - System.arraycopy(array, 0, newArray, 0, array.length); - System.arraycopy(other.array, 0, newArray, array.length, other.array.length); - sum = fromArrayNoCopy(newArray); - } - return sum; - } - - @Override - public PyObject __mul__(PyObject o) { - return newtuple___mul__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___mul___doc) - final PyObject newtuple___mul__(PyObject o) { - if (!o.isIndex()) { - return null; - } - return repeat(o.asIndex(Py.OverflowError)); - } - - @Override - public PyObject __rmul__(PyObject o) { - return newtuple___rmul__(o); - } - - @ExposedMethod(type = MethodType.BINARY, doc = BuiltinDocs.tuple___rmul___doc) - final PyObject newtuple___rmul__(PyObject o) { - if (!o.isIndex()) { - return null; - } - return repeat(o.asIndex(Py.OverflowError)); - } - - public PyObject __iter__() { - return newtuple___iter__(); - } - - @ExposedMethod(doc = BuiltinDocs.tuple___iter___doc) - public PyObject newtuple___iter__() { - return new PyFastSequenceIter(this); - } - - @ExposedMethod(defaults = "null", doc = BuiltinDocs.tuple___getslice___doc) - final PyObject newtuple___getslice__(PyObject s_start, PyObject s_stop, PyObject s_step) { - return seq___getslice__(s_start, s_stop, s_step); - } - - @ExposedMethod(doc = BuiltinDocs.tuple___getitem___doc) - final PyObject newtuple___getitem__(PyObject index) { - PyObject ret = seq___finditem__(index); - if (ret == null) { - throw Py.IndexError("index out of range: " + index); - } - return ret; - } - - @ExposedMethod(doc = BuiltinDocs.tuple___getnewargs___doc) - final PyTuple newtuple___getnewargs__() { - return new PyTuple(new PyTuple(getArray())); - } - - public PyTuple __getnewargs__() { - return newtuple___getnewargs__(); - } - - public int hashCode() { - return newtuple___hash__(); - } - - @ExposedMethod(doc = BuiltinDocs.tuple___hash___doc) - final int newtuple___hash__() { - // strengthened hash to avoid common collisions. from CPython - // tupleobject.tuplehash. See http://bugs.python.org/issue942952 - int y; - int len = size(); - int mult = 1000003; - int x = 0x345678; - PyObject[] array = getArray(); - while (--len >= 0) { - y = array[len].hashCode(); - x = (x ^ y) * mult; - mult += 82520 + len + len; - } - return x + 97531; - } - - private String subobjRepr(PyObject o) { - if (o == null) { - return "null"; - } - return o.__repr__().toString(); - } - - public String toString() { - return newtuple___repr__(); - } - - @ExposedMethod(doc = BuiltinDocs.tuple___repr___doc) - final String newtuple___repr__() { - StringBuilder buf = new StringBuilder("("); - for (int i = 0; i < array.length - 1; i++) { - buf.append(subobjRepr(array[i])); - buf.append(", "); - } - if (array.length > 0) { - buf.append(subobjRepr(array[array.length - 1])); - } - if (array.length == 1) { - buf.append(","); - } - buf.append(")"); - return buf.toString(); - } - - public List subList(int fromIndex, int toIndex) { - return Collections.unmodifiableList(getList().subList(fromIndex, toIndex)); - } - - // Make PyNewTuple immutable from the collections interfaces by overriding - // all the mutating methods to throw UnsupportedOperationException exception. - // This is how Collections.unmodifiableList() does it. - public Iterator iterator() { - return new Iterator() { - - Iterator i = getList().iterator(); - - public void remove() { - throw new UnsupportedOperationException(); - } - - public boolean hasNext() { - return i.hasNext(); - } - - public Object next() { - return i.next(); - } - }; - } - - public boolean add(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean remove(Object o) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(Collection coll) { - throw new UnsupportedOperationException(); - } - - public boolean removeAll(Collection coll) { - throw new UnsupportedOperationException(); - } - - public boolean retainAll(Collection coll) { - throw new UnsupportedOperationException(); - } - - public void clear() { - throw new UnsupportedOperationException(); - } - - public Object set(int index, Object element) { - throw new UnsupportedOperationException(); - } - - public void add(int index, Object element) { - throw new UnsupportedOperationException(); - } - - public Object remove(int index) { - throw new UnsupportedOperationException(); - } - - public boolean addAll(int index, Collection c) { - throw new UnsupportedOperationException(); - } - - public ListIterator listIterator() { - return listIterator(0); - } - - public ListIterator listIterator(final int index) { - return new ListIterator() { - - ListIterator i = getList().listIterator(index); - - public boolean hasNext() { - return i.hasNext(); - } - - public Object next() { - return i.next(); - } - - public boolean hasPrevious() { - return i.hasPrevious(); - } - - public Object previous() { - return i.previous(); - } - - public int nextIndex() { - return i.nextIndex(); - } - - public int previousIndex() { - return i.previousIndex(); - } - - public void remove() { - throw new UnsupportedOperationException(); - } - - public void set(Object o) { - throw new UnsupportedOperationException(); - } - - public void add(Object o) { - throw new UnsupportedOperationException(); - } - }; - } - - protected String unsupportedopMessage(String op, PyObject o2) { - if (op.equals("+")) { - return "can only concatenate tuple (not \"{2}\") to tuple"; - } - return super.unsupportedopMessage(op, o2); - } - - public void pyset(int index, PyObject value) { - throw Py.TypeError("'tuple' object does not support item assignment"); - } - - @Override - public boolean contains(Object o) { - PyObject converted = Py.java2py(o); - for (int i = 0; i < array.length; i++) { - if (array[i].equals(converted)) { - return true; - } - } - return false; - } - - @Override - public boolean containsAll(Collection c) { - if (c instanceof PySequenceList) { - return getList().containsAll(c); - } else { - //XXX: FJW this seems unnecessary. - return getList().containsAll(new PyList(c)); - } - } - - @Override - public boolean equals(Object o) { - if (o instanceof PyNewTuple) { - return Arrays.equals(array, ((PyNewTuple) o).array); - } else if (o instanceof List) { // XXX copied from PyList, but... - return o.equals(this); // XXX shouldn't this compare using py2java? - } - return false; - } - - @Override - public Object get(int index) { - return array[index].__tojava__(Object.class); - } - - @Override - public PyObject[] getArray() { - return array; - } - - @Override - public int indexOf(Object o) { - PyObject converted = Py.java2py(o); - for (int i = 0; i < array.length; i++) { - if (array[i].equals(converted)) { - return i; - } - } - return -1; - } - - @Override - public boolean isEmpty() { - return array.length == 0; - } - - @Override - public int lastIndexOf(Object o) { - PyObject converted = Py.java2py(o); - int lastIndex = -1; - for (int i = 0; i < array.length; i++) { - if (array[i].equals(converted)) { - lastIndex = i; - } - } - return lastIndex; - } - - @Override - public void pyadd(int index, PyObject element) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public boolean pyadd(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public PyObject pyget(int index) { - return array[index]; - } - - @Override - public void remove(int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); - } - - @Override - public int size() { - return array.length; - } - - @Override - public Object[] toArray() { - return array; - } - - @Override - public Object[] toArray(Object[] a) { - System.arraycopy(array, 0, a, 0, array.length); - return a; - } -} Deleted: branches/newlist/src/org/python/core/PyNewTupleDerived.java =================================================================== --- branches/newlist/src/org/python/core/PyNewTupleDerived.java 2009-04-18 02:31:16 UTC (rev 6239) +++ branches/newlist/src/org/python/core/PyNewTupleDerived.java 2009-04-18 02:53:00 UTC (rev 6240) @@ -1,1162 +0,0 @@ -/* Generated file, do not modify. See jython/src/templates/gderived.py. */ -package org.python.core; - -import java.io.Serializable; - -public class PyNewTupleDerived extends PyNewTuple implements Slotted { - - public PyObject getSlot(int index) { - return slots[index]; - } - - public void setSlot(int index,PyObject value) { - slots[index]=value; - } - - private PyObject[]slots; - - private PyObject dict; - - public PyObject fastGetDict() { - return dict; - } - - public PyObject getDict() { - return dict; - } - - public void setDict(PyObject newDict) { - if (newDict instanceof PyStringMap||newDict instanceof PyDictionary) { - dict=newDict; - } else { - throw Py.TypeError("__dict__ must be set to a Dictionary "+newDict.getClass().getName()); - } - } - - public void delDict() { - // deleting an object's instance dict makes it grow a new one - dict=new PyStringMap(); - } - - public PyNewTupleDerived(PyType subtype,PyObject[]elements) { - super(subtype,elements); - slots=new PyObject[subtype.getNumSlots()]; - dict=subtype.instDict(); - } - - public PyString __str__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__str__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__str__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__str__(); - } - - public PyString __repr__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__repr__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__repr__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__repr__(); - } - - public PyString __hex__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__hex__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__hex__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__hex__(); - } - - public PyString __oct__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__oct__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyString) - return(PyString)res; - throw Py.TypeError("__oct__"+" returned non-"+"string"+" (type "+res.getType().fastGetName()+")"); - } - return super.__oct__(); - } - - public PyFloat __float__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__float__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyFloat) - return(PyFloat)res; - throw Py.TypeError("__float__"+" returned non-"+"float"+" (type "+res.getType().fastGetName()+")"); - } - return super.__float__(); - } - - public PyComplex __complex__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__complex__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyComplex) - return(PyComplex)res; - throw Py.TypeError("__complex__"+" returned non-"+"complex"+" (type "+res.getType().fastGetName()+")"); - } - return super.__complex__(); - } - - public PyObject __pos__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__pos__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__pos__(); - } - - public PyObject __neg__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__neg__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__neg__(); - } - - public PyObject __abs__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__abs__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__abs__(); - } - - public PyObject __invert__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__invert__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__invert__(); - } - - public PyObject __reduce__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__reduce__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - return super.__reduce__(); - } - - public PyObject __add__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__add__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__add__(other); - } - - public PyObject __radd__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__radd__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__radd__(other); - } - - public PyObject __sub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__sub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__sub__(other); - } - - public PyObject __rsub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rsub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rsub__(other); - } - - public PyObject __mul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__mul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__mul__(other); - } - - public PyObject __rmul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rmul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rmul__(other); - } - - public PyObject __div__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__div__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__div__(other); - } - - public PyObject __rdiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rdiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rdiv__(other); - } - - public PyObject __floordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__floordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__floordiv__(other); - } - - public PyObject __rfloordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rfloordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rfloordiv__(other); - } - - public PyObject __truediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__truediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__truediv__(other); - } - - public PyObject __rtruediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rtruediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rtruediv__(other); - } - - public PyObject __mod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__mod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__mod__(other); - } - - public PyObject __rmod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rmod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rmod__(other); - } - - public PyObject __divmod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__divmod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__divmod__(other); - } - - public PyObject __rdivmod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rdivmod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rdivmod__(other); - } - - public PyObject __rpow__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rpow__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rpow__(other); - } - - public PyObject __lshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__lshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__lshift__(other); - } - - public PyObject __rlshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rlshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rlshift__(other); - } - - public PyObject __rshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rshift__(other); - } - - public PyObject __rrshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rrshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rrshift__(other); - } - - public PyObject __and__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__and__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__and__(other); - } - - public PyObject __rand__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rand__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rand__(other); - } - - public PyObject __or__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__or__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__or__(other); - } - - public PyObject __ror__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ror__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ror__(other); - } - - public PyObject __xor__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__xor__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__xor__(other); - } - - public PyObject __rxor__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__rxor__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__rxor__(other); - } - - public PyObject __lt__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__lt__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__lt__(other); - } - - public PyObject __le__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__le__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__le__(other); - } - - public PyObject __gt__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__gt__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__gt__(other); - } - - public PyObject __ge__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ge__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ge__(other); - } - - public PyObject __eq__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__eq__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__eq__(other); - } - - public PyObject __ne__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ne__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ne__(other); - } - - public PyObject __iadd__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__iadd__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__iadd__(other); - } - - public PyObject __isub__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__isub__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__isub__(other); - } - - public PyObject __imul__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__imul__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__imul__(other); - } - - public PyObject __idiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__idiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__idiv__(other); - } - - public PyObject __ifloordiv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ifloordiv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ifloordiv__(other); - } - - public PyObject __itruediv__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__itruediv__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__itruediv__(other); - } - - public PyObject __imod__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__imod__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__imod__(other); - } - - public PyObject __ipow__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ipow__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ipow__(other); - } - - public PyObject __ilshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ilshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ilshift__(other); - } - - public PyObject __irshift__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__irshift__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__irshift__(other); - } - - public PyObject __iand__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__iand__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__iand__(other); - } - - public PyObject __ior__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ior__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ior__(other); - } - - public PyObject __ixor__(PyObject other) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__ixor__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__ixor__(other); - } - - public PyObject __int__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__int__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger||res instanceof PyLong) - return(PyObject)res; - throw Py.TypeError("__int__"+" should return an integer"); - } - return super.__int__(); - } - - public PyObject __long__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__long__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyLong||res instanceof PyInteger) - return res; - throw Py.TypeError("__long__"+" returned non-"+"long"+" (type "+res.getType().fastGetName()+")"); - } - return super.__long__(); - } - - public int hashCode() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__hash__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger) { - return((PyInteger)res).getValue(); - } else - if (res instanceof PyLong) { - return((PyLong)res).getValue().intValue(); - } - throw Py.TypeError("__hash__ should return a int"); - } - if (self_type.lookup("__eq__")!=null||self_type.lookup("__cmp__")!=null) { - throw Py.TypeError(String.format("unhashable type: '%.200s'",getType().fastGetName())); - } - return super.hashCode(); - } - - public PyUnicode __unicode__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__unicode__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyUnicode) - return(PyUnicode)res; - if (res instanceof PyString) - return new PyUnicode((PyString)res); - throw Py.TypeError("__unicode__"+" should return a "+"unicode"); - } - return super.__unicode__(); - } - - public int __cmp__(PyObject other) { - PyType self_type=getType(); - PyType[]where_type=new PyType[1]; - PyObject impl=self_type.lookup_where("__cmp__",where_type); - // Full Compatibility with CPython __cmp__: - // If the derived type don't override __cmp__, the - // *internal* super().__cmp__ should be called, not the - // exposed one. The difference is that the exposed __cmp__ - // throws a TypeError if the argument is an instance of the same type. - if (impl==null||where_type[0]==TYPE||Py.isSubClass(TYPE,where_type[0])) { - return super.__cmp__(other); - } - PyObject res=impl.__get__(this,self_type).__call__(other); - if (res==Py.NotImplemented) { - return-2; - } - int c=res.asInt(); - return c<0?-1:c>0?1:0; - } - - public boolean __nonzero__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__nonzero__"); - if (impl==null) { - impl=self_type.lookup("__len__"); - if (impl==null) - return super.__nonzero__(); - } - PyObject o=impl.__get__(this,self_type).__call__(); - Class c=o.getClass(); - if (c!=PyInteger.class&&c!=PyBoolean.class) { - throw Py.TypeError(String.format("__nonzero__ should return bool or int, returned %s",self_type.getName())); - } - return o.__nonzero__(); - } - - public boolean __contains__(PyObject o) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__contains__"); - if (impl==null) - return super.__contains__(o); - return impl.__get__(this,self_type).__call__(o).__nonzero__(); - } - - public int __len__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__len__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger) - return((PyInteger)res).getValue(); - throw Py.TypeError("__len__ should return a int"); - } - return super.__len__(); - } - - public PyObject __iter__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__iter__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(); - impl=self_type.lookup("__getitem__"); - if (impl==null) - return super.__iter__(); - return new PySequenceIter(this); - } - - public PyObject __iternext__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("next"); - if (impl!=null) { - try { - return impl.__get__(this,self_type).__call__(); - } catch (PyException exc) { - if (Py.matchException(exc,Py.StopIteration)) - return null; - throw exc; - } - } - return super.__iternext__(); // ??? - } - - public PyObject __finditem__(PyObject key) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) - try { - return impl.__get__(this,self_type).__call__(key); - } catch (PyException exc) { - if (Py.matchException(exc,Py.LookupError)) - return null; - throw exc; - } - return super.__finditem__(key); - } - - public PyObject __finditem__(int key) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) - try { - return impl.__get__(this,self_type).__call__(new PyInteger(key)); - } catch (PyException exc) { - if (Py.matchException(exc,Py.LookupError)) - return null; - throw exc; - } - return super.__finditem__(key); - } - - public PyObject __getitem__(PyObject key) { - // Same as __finditem__, without swallowing LookupErrors. This allows - // __getitem__ implementations written in Python to raise custom - // exceptions (such as subclasses of KeyError). - // - // We are forced to duplicate the code, instead of defining __finditem__ - // in terms of __getitem__. That's because PyObject defines __getitem__ - // in terms of __finditem__. Therefore, we would end with an infinite - // loop when self_type.lookup("__getitem__") returns null: - // - // __getitem__ -> super.__getitem__ -> __finditem__ -> __getitem__ - // - // By duplicating the (short) lookup and call code, we are safe, because - // the call chains will be: - // - // __finditem__ -> super.__finditem__ - // - // __getitem__ -> super.__getitem__ -> __finditem__ -> super.__finditem__ - - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getitem__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(key); - return super.__getitem__(key); - } - - public void __setitem__(PyObject key,PyObject value) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setitem__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(key,value); - return; - } - super.__setitem__(key,value); - } - - public PyObject __getslice__(PyObject start,PyObject stop,PyObject step) { // ??? - if (step!=null) { - return __getitem__(new PySlice(start,stop,step)); - } - PyType self_type=getType(); - PyObject impl=self_type.lookup("__getslice__"); - if (impl!=null) { - PyObject[]indices=PySlice.indices2(this,start,stop); - return impl.__get__(this,self_type).__call__(indices[0],indices[1]); - } - return super.__getslice__(start,stop,step); - } - - public void __setslice__(PyObject start,PyObject stop,PyObject step,PyObject value) { - if (step!=null) { - __setitem__(new PySlice(start,stop,step),value); - return; - } - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setslice__"); - if (impl!=null) { - PyObject[]indices=PySlice.indices2(this,start,stop); - impl.__get__(this,self_type).__call__(indices[0],indices[1],value); - return; - } - super.__setslice__(start,stop,step,value); - } - - public void __delslice__(PyObject start,PyObject stop,PyObject step) { - if (step!=null) { - __delitem__(new PySlice(start,stop,step)); - return; - } - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delslice__"); - if (impl!=null) { - PyObject[]indices=PySlice.indices2(this,start,stop); - impl.__get__(this,self_type).__call__(indices[0],indices[1]); - return; - } - super.__delslice__(start,stop,step); - } - - public void __delitem__(PyObject key) { // ??? - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delitem__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(key); - return; - } - super.__delitem__(key); - } - - public PyObject __call__(PyObject args[],String keywords[]) { - ThreadState ts=Py.getThreadState(); - if (ts.recursion_depth++>ts.systemState.getrecursionlimit()) - throw Py.RuntimeError("maximum __call__ recursion depth exceeded"); - try { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__call__"); - if (impl!=null) - return impl.__get__(this,self_type).__call__(args,keywords); - return super.__call__(args,keywords); - } finally { - --ts.recursion_depth; - } - } - - public PyObject __findattr_ex__(String name) { - PyType self_type=getType(); - // TODO: We should speed this up. As the __getattribute__ slot almost never - // changes, it is a good candidate for caching, as PyClass does with - // __getattr__. See #1102. - PyObject getattribute=self_type.lookup("__getattribute__"); - PyString py_name=null; - PyException firstAttributeError=null; - try { - if (getattribute!=null) { - py_name=PyString.fromInterned(name); - return getattribute.__get__(this,self_type).__call__(py_name); - } else { - Py.Warning(String.format("__getattribute__ not found on type %s",self_type.getName())); - PyObject ret=super.__findattr_ex__(name); - if (ret!=null) { - return ret; - } // else: pass through to __getitem__ invocation - } - } catch (PyException e) { - if (!Py.matchException(e,Py.AttributeError)) { - throw e; - } else { - firstAttributeError=e; // saved to avoid swallowing custom AttributeErrors - // and pass through to __getattr__ invocation. - } - } - PyObject getattr=self_type.lookup("__getattr__"); - if (getattr!=null) { - if (py_name==null) { - py_name=PyString.fromInterned(name); - } - return getattr.__get__(this,self_type).__call__(py_name); - } - if (firstAttributeError!=null) { - throw firstAttributeError; - } - return null; - } - - public void __setattr__(String name,PyObject value) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__setattr__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(PyString.fromInterned(name),value); - return; - } - super.__setattr__(name,value); - } - - public void __delattr__(String name) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delattr__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(PyString.fromInterned(name)); - return; - } - super.__delattr__(name); - } - - public PyObject __get__(PyObject obj,PyObject type) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__get__"); - if (impl!=null) { - if (obj==null) - obj=Py.None; - if (type==null) - type=Py.None; - return impl.__get__(this,self_type).__call__(obj,type); - } - return super.__get__(obj,type); - } - - public void __set__(PyObject obj,PyObject value) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__set__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(obj,value); - return; - } - super.__set__(obj,value); - } - - public void __delete__(PyObject obj) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__delete__"); - if (impl!=null) { - impl.__get__(this,self_type).__call__(obj); - return; - } - super.__delete__(obj); - } - - public PyObject __pow__(PyObject other,PyObject modulo) { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__pow__"); - if (impl!=null) { - PyObject res; - if (modulo==null) { - res=impl.__get__(this,self_type).__call__(other); - } else { - res=impl.__get__(this,self_type).__call__(other,modulo); - } - if (res==Py.NotImplemented) - return null; - return res; - } - return super.__pow__(other,modulo); - } - - public void dispatch__init__(PyType type,PyObject[]args,String[]keywords) { - PyType self_type=getType(); - if (self_type.isSubType(type)) { - PyObject impl=self_type.lookup("__init__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(args,keywords); - if (res!=Py.None) { - throw Py.TypeError(String.format("__init__() should return None, not '%.200s'",res.getType().fastGetName())); - } - proxyInit(); - } - } - } - - public PyObject __index__() { - PyType self_type=getType(); - PyObject impl=self_type.lookup("__index__"); - if (impl!=null) { - PyObject res=impl.__get__(this,self_type).__call__(); - if (res instanceof PyInteger||res instanceof PyLong) { - return res; - } - throw Py.TypeError(String.format("__index__ returned non-(int,long) (type %s)",res.getType().fastGetName())); - } - return super.__index__(); - } - - public Object __tojava__(Class c) { - // If we are not being asked by the "default" conversion to java, then - // we can provide this as the result, as long as it is a instance of the - // specified class. Without this, derived.__tojava__(PyObject.class) - // would broke. (And that's not pure speculation: PyReflectedFunction's - // ReflectedArgs asks for things like that). - if ((c!=Object.class)&&(c!=Serializable.class)&&... [truncated message content] |
From: <zy...@us...> - 2009-04-18 02:31:20
|
Revision: 6239 http://jython.svn.sourceforge.net/jython/?rev=6239&view=rev Author: zyasoft Date: 2009-04-18 02:31:16 +0000 (Sat, 18 Apr 2009) Log Message: ----------- Cleanup. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PyTuple.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-18 01:06:26 UTC (rev 6238) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-18 02:31:16 UTC (rev 6239) @@ -1,4 +1,4 @@ - // Copyright (c) Corporation for National Research Initiatives +// Copyright (c) Corporation for National Research Initiatives package org.python.core; import java.util.ArrayList; @@ -140,11 +140,9 @@ } else if (value instanceof PySequence) { setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (value != null && !(value instanceof List)) { - //XXX: can we avoid copying here? Needed to pass test_userlist value = new PyList(value); setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { -// System.err.println("List"); List valueList = (List) value.__tojava__(List.class); if (valueList != null && valueList != Py.NoConversion) { setsliceList(start, stop, step, valueList); @@ -782,7 +780,6 @@ if (c instanceof PySequenceList) { return list.containsAll(c); } else { - //XXX: FJW this seems unnecessary. return list.containsAll(new PyList(c)); } } @@ -948,52 +945,8 @@ copy[i] = ((PyObject) copy[i]).__tojava__(Object.class); } return copy; -// System.err.println("toArray:" + this); -// System.err.println(CallStackUtil.getCallStackAsString()); -// return list.toArray(); } - // from http://roncox.org/20 - XXX just here for debugging - static class CallStackUtil { - - public synchronized static String getCallStackAsString() { - StringBuilder sb = new StringBuilder(); - - StackTraceElement[] stackTraceElements = - Thread.currentThread().getStackTrace(); - - String[] array = getCallStackAsStringArray(stackTraceElements); - - for (int i = 0; i < array.length; i++) { - sb.append(array[i] + "\n"); - } - return sb.toString(); - } - - public synchronized static String[] getCallStackAsStringArray() { - StackTraceElement[] stackTraceElements = - Thread.currentThread().getStackTrace(); - - String[] array = getCallStackAsStringArray(stackTraceElements); - - return array; - } - - private synchronized static String[] getCallStackAsStringArray(StackTraceElement[] stackTraceElements) { - ArrayList<String> list = new ArrayList<String>(); - String[] array = new String[1]; - - for (int i = 0; i < stackTraceElements.length; i++) { - StackTraceElement element = stackTraceElements[i]; - String classname = element.getClassName(); - String methodName = element.getMethodName(); - int lineNumber = element.getLineNumber(); - list.add(classname + "." + methodName + ":" + lineNumber); - } - return list.toArray(array); - } - } - @Override public Object[] toArray(Object[] a) { Object copy[] = list.toArray(); Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-18 01:06:26 UTC (rev 6238) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-18 02:31:16 UTC (rev 6239) @@ -33,7 +33,6 @@ public PyTuple(PyType subtype, PyObject[] elements) { super(subtype); -// System.err.println("Initializing from " + Arrays.toString(elements)); if (elements == null) { array = new PyObject[0]; } else { @@ -58,7 +57,6 @@ } private static PyTuple fromArrayNoCopy(PyObject[] elements) { -// System.err.println("newtuple (no copy):" + Arrays.toString(elements)); return new PyTuple(elements, false); } private volatile List<PyObject> cachedList = null; @@ -73,10 +71,8 @@ @ExposedNew final static PyObject tuple_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { -// System.err.println("tuple_new"); ArgParser ap = new ArgParser("newtuple", args, keywords, new String[]{"sequence"}, 0); PyObject S = ap.getPyObject(0, null); -// System.err.println("newtuple: new_=" + new_ + ",S=" + S); if (new_.for_type == subtype) { if (S == null) { return EMPTY_TUPLE; @@ -154,6 +150,7 @@ return fromArrayNoCopy(newArray); } + @Override public int __len__() { return tuple___len__(); } @@ -198,6 +195,7 @@ return super.__le__(o); } + @Override public PyObject __add__(PyObject generic_other) { return tuple___add__(generic_other); } @@ -241,6 +239,7 @@ return repeat(o.asIndex(Py.OverflowError)); } + @Override public PyObject __iter__() { return tuple___iter__(); } @@ -269,10 +268,12 @@ return new PyTuple(new PyTuple(getArray())); } + @Override public PyTuple __getnewargs__() { return tuple___getnewargs__(); } + @Override public int hashCode() { return tuple___hash__(); } @@ -300,6 +301,7 @@ return o.__repr__().toString(); } + @Override public String toString() { return tuple___repr__(); } @@ -335,9 +337,6 @@ return new PyTuple(elements); } - // Make PyTuple immutable from the collections interfaces by overriding - // all the mutating methods to throw UnsupportedOperationException exception. - // This is how Collections.unmodifiableList() does it. public Iterator iterator() { return new Iterator() { @@ -469,8 +468,8 @@ public boolean equals(Object o) { if (o instanceof PyTuple) { return Arrays.equals(array, ((PyTuple) o).array); - } else if (o instanceof List) { // XXX copied from PyList, but... - return o.equals(this); // XXX shouldn't this compare using py2java? + } else if (o instanceof List) { + return o.equals(this); } return false; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-18 01:06:27
|
Revision: 6238 http://jython.svn.sourceforge.net/jython/?rev=6238&view=rev Author: zyasoft Date: 2009-04-18 01:06:26 +0000 (Sat, 18 Apr 2009) Log Message: ----------- All tests now pass, so just need some minor cleanup. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PyTuple.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-17 23:50:17 UTC (rev 6237) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-18 01:06:26 UTC (rev 6238) @@ -758,28 +758,13 @@ @Override public boolean addAll(int index, Collection c) { - if (c instanceof PySequenceList) { - list.addAll(index, c); - } else { - // need to use add to convert anything pulled from a collection into a PyObject - for (Object element : c) { - add(element); - } - } - return c.size() > 0; + PyList elements = new PyList(c); + return list.addAll(index, elements.list); } @Override public boolean addAll(Collection c) { - if (c instanceof PySequenceList) { - list.addAll(c); - } else { - // need to use add to convert anything pulled from a collection into a PyObject - for (Object element : c) { - add(element); - } - } - return c.size() > 0; + return addAll(0, c); } @Override @@ -846,57 +831,51 @@ @Override public ListIterator listIterator() { - return new PyListIterator(0); + return listIterator(0); } @Override - public ListIterator listIterator(int index) { - return new PyListIterator(index); - } + public ListIterator listIterator(final int index) { + return new ListIterator() { - public class PyListIterator implements ListIterator { + private final ListIterator<PyObject> iter = list.listIterator(index); - private final ListIterator<PyObject> iter; + public boolean hasNext() { + return iter.hasNext(); + } - PyListIterator(int index) { - iter = list.listIterator(index); - } + public Object next() { + return iter.next().__tojava__(Object.class); + } - public boolean hasNext() { - return iter.hasNext(); - } + public boolean hasPrevious() { + return iter.hasPrevious(); + } - public Object next() { - return iter.next().__tojava__(Object.class); - } + public Object previous() { + return iter.previous().__tojava__(Object.class); + } - public boolean hasPrevious() { - return iter.hasPrevious(); - } + public int nextIndex() { + return iter.nextIndex(); + } - public Object previous() { - return iter.previous().__tojava__(Object.class); - } + public int previousIndex() { + return iter.previousIndex(); + } - public int nextIndex() { - return iter.nextIndex(); - } + public void remove() { + iter.remove(); + } - public int previousIndex() { - return iter.previousIndex(); - } + public void set(Object o) { + iter.set(Py.java2py(o)); + } - public void remove() { - iter.remove(); - } - - public void set(Object o) { - iter.set(Py.java2py(o)); - } - - public void add(Object o) { - iter.add(Py.java2py(o)); - } + public void add(Object o) { + iter.add(Py.java2py(o)); + } + }; } @Override Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-17 23:50:17 UTC (rev 6237) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-18 01:06:26 UTC (rev 6238) @@ -322,7 +322,17 @@ } public List subList(int fromIndex, int toIndex) { - return Collections.unmodifiableList(getList().subList(fromIndex, toIndex)); + if (fromIndex < 0 || toIndex > size()) { + throw new IndexOutOfBoundsException(); + } else if (fromIndex > toIndex) { + throw new IllegalArgumentException(); + } + System.err.println("subList" + fromIndex + "," + toIndex); + PyObject elements[] = new PyObject[toIndex - fromIndex]; + for (int i = 0, j = fromIndex; i < elements.length; i++, j++) { + elements[i] = array[j]; + } + return new PyTuple(elements); } // Make PyTuple immutable from the collections interfaces by overriding @@ -331,18 +341,18 @@ public Iterator iterator() { return new Iterator() { - Iterator i = getList().iterator(); + private final Iterator<PyObject> iter = getList().iterator(); public void remove() { throw new UnsupportedOperationException(); } public boolean hasNext() { - return i.hasNext(); + return iter.hasNext(); } public Object next() { - return i.next(); + return iter.next().__tojava__(Object.class); } }; } @@ -394,30 +404,30 @@ public ListIterator listIterator(final int index) { return new ListIterator() { - ListIterator i = getList().listIterator(index); + private final ListIterator<PyObject> iter = getList().listIterator(index); public boolean hasNext() { - return i.hasNext(); + return iter.hasNext(); } public Object next() { - return i.next(); + return iter.next().__tojava__(Object.class); } public boolean hasPrevious() { - return i.hasPrevious(); + return iter.hasPrevious(); } public Object previous() { - return i.previous(); + return iter.previous().__tojava__(Object.class); } public int nextIndex() { - return i.nextIndex(); + return iter.nextIndex(); } public int previousIndex() { - return i.previousIndex(); + return iter.previousIndex(); } public void remove() { @@ -447,12 +457,12 @@ @Override public boolean contains(Object o) { - return getList().contains(o); + return getList().contains(Py.java2py(o)); } @Override public boolean containsAll(Collection c) { - return getList().containsAll(c); + return getList().containsAll(new PyList(c)); } @Override @@ -487,7 +497,7 @@ @Override public int lastIndexOf(Object o) { - return getList().lastIndexOf(o); + return getList().lastIndexOf(Py.java2py(o)); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-17 23:50:26
|
Revision: 6237 http://jython.svn.sourceforge.net/jython/?rev=6237&view=rev Author: zyasoft Date: 2009-04-17 23:50:17 +0000 (Fri, 17 Apr 2009) Log Message: ----------- Additional proxying fixes Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PyTuple.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-17 14:06:01 UTC (rev 6236) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-17 23:50:17 UTC (rev 6237) @@ -31,7 +31,7 @@ list = Generic.list(); } - public PyList(List list, boolean convert) { + private PyList(List list, boolean convert) { super(TYPE); if (!convert) { this.list = list; @@ -71,7 +71,7 @@ } } - public static PyList fromList(List list) { + public static PyList fromList(List<PyObject> list) { return new PyList(list, false); } @@ -97,7 +97,9 @@ return; } if (seq instanceof PyList) { - list.addAll((PyList) seq); // don't convert + list.addAll(((PyList) seq).list); // don't convert + } else if (seq instanceof PyTuple) { + list.addAll(((PyTuple) seq).getList()); } else { for (PyObject item : seq.asIterable()) { append(item); @@ -134,7 +136,7 @@ if (value == this) { // copy value = new PyList((PySequence) value); } - setslicePyList(start, stop, step, (PyList)value); + setslicePyList(start, stop, step, (PyList) value); } else if (value instanceof PySequence) { setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (value != null && !(value instanceof List)) { @@ -162,7 +164,7 @@ } protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { - if(step == 1) { + if (step == 1) { List<PyObject> insertion = new ArrayList<PyObject>(); if (iter != null) { while (iter.hasNext()) { @@ -185,12 +187,12 @@ } protected void setslicePyList(int start, int stop, int step, PyList other) { - if(step == 1) { + if (step == 1) { list.subList(start, stop).clear(); list.addAll(start, other.list); } else { int size = list.size(); - Iterator<PyObject> iter = other.listIterator(); + Iterator<PyObject> iter = other.list.listIterator(); for (int j = start; iter.hasNext(); j += step) { PyObject item = iter.next(); if (j >= size) { @@ -215,7 +217,7 @@ PyList newList = new PyList(); for (int i = 0; i < count; i++) { - newList.addAll(this); + newList.addAll(list); } return newList; } @@ -804,7 +806,7 @@ public boolean equals(Object o) { if (o instanceof PyList) { return (((PyList) o).list.equals(list)); - } else if(o instanceof List) { // XXX copied from PyList, but... + } else if (o instanceof List) { // XXX copied from PyList, but... return o.equals(this); // XXX shouldn't this compare using py2java? } return false; @@ -818,7 +820,7 @@ /** @deprecated */ @Override public PyObject[] getArray() { - PyObject a[] = new PyObject[list.size()]; + PyObject a[] = null; // = new PyObject[list.size()]; return list.toArray(a); } @@ -839,19 +841,64 @@ @Override public int lastIndexOf(Object o) { - return list.lastIndexOf(o); + return list.lastIndexOf(Py.java2py(o)); } @Override public ListIterator listIterator() { - return list.listIterator(); + return new PyListIterator(0); } @Override public ListIterator listIterator(int index) { - return list.listIterator(index); + return new PyListIterator(index); } + public class PyListIterator implements ListIterator { + + private final ListIterator<PyObject> iter; + + PyListIterator(int index) { + iter = list.listIterator(index); + } + + public boolean hasNext() { + return iter.hasNext(); + } + + public Object next() { + return iter.next().__tojava__(Object.class); + } + + public boolean hasPrevious() { + return iter.hasPrevious(); + } + + public Object previous() { + return iter.previous().__tojava__(Object.class); + } + + public int nextIndex() { + return iter.nextIndex(); + } + + public int previousIndex() { + return iter.previousIndex(); + } + + public void remove() { + iter.remove(); + } + + public void set(Object o) { + iter.set(Py.java2py(o)); + } + + public void add(Object o) { + iter.add(Py.java2py(o)); + } + } + @Override public void pyadd(int index, PyObject element) { list.add(index, element); @@ -912,17 +959,75 @@ @Override public List subList(int fromIndex, int toIndex) { - return list.subList(fromIndex, toIndex); + return fromList(list.subList(fromIndex, toIndex)); } @Override public Object[] toArray() { - return list.toArray(); + Object copy[] = list.toArray(); + for (int i = 0; i < copy.length; i++) { + copy[i] = ((PyObject) copy[i]).__tojava__(Object.class); + } + return copy; +// System.err.println("toArray:" + this); +// System.err.println(CallStackUtil.getCallStackAsString()); +// return list.toArray(); } + // from http://roncox.org/20 - XXX just here for debugging + static class CallStackUtil { + + public synchronized static String getCallStackAsString() { + StringBuilder sb = new StringBuilder(); + + StackTraceElement[] stackTraceElements = + Thread.currentThread().getStackTrace(); + + String[] array = getCallStackAsStringArray(stackTraceElements); + + for (int i = 0; i < array.length; i++) { + sb.append(array[i] + "\n"); + } + return sb.toString(); + } + + public synchronized static String[] getCallStackAsStringArray() { + StackTraceElement[] stackTraceElements = + Thread.currentThread().getStackTrace(); + + String[] array = getCallStackAsStringArray(stackTraceElements); + + return array; + } + + private synchronized static String[] getCallStackAsStringArray(StackTraceElement[] stackTraceElements) { + ArrayList<String> list = new ArrayList<String>(); + String[] array = new String[1]; + + for (int i = 0; i < stackTraceElements.length; i++) { + StackTraceElement element = stackTraceElements[i]; + String classname = element.getClassName(); + String methodName = element.getMethodName(); + int lineNumber = element.getLineNumber(); + list.add(classname + "." + methodName + ":" + lineNumber); + } + return list.toArray(array); + } + } + @Override public Object[] toArray(Object[] a) { - return list.toArray(a); + Object copy[] = list.toArray(); + if (a.length != copy.length) { + a = copy; + } + for (int i = 0; i < copy.length; i++) { + a[i] = ((PyObject) copy[i]).__tojava__(Object.class); + } + for (int i = copy.length; i < a.length; i++) { + a[i] = null; + } + return a; } protected PyObject getslice(int start, int stop, int step) { Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-17 14:06:01 UTC (rev 6236) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-17 23:50:17 UTC (rev 6237) @@ -63,7 +63,7 @@ } private volatile List<PyObject> cachedList = null; - private List<PyObject> getList() { + List<PyObject> getList() { if (cachedList == null) { cachedList = Arrays.asList(array); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-17 14:06:08
|
Revision: 6236 http://jython.svn.sourceforge.net/jython/?rev=6236&view=rev Author: fwierzbicki Date: 2009-04-17 14:06:01 +0000 (Fri, 17 Apr 2009) Log Message: ----------- More tinkering to get a useful policy file for GAE testing. Modified Paths: -------------- trunk/jython/tests/policy/nowrite.policy trunk/jython/tests/policy/run.sh Modified: trunk/jython/tests/policy/nowrite.policy =================================================================== --- trunk/jython/tests/policy/nowrite.policy 2009-04-17 03:44:35 UTC (rev 6235) +++ trunk/jython/tests/policy/nowrite.policy 2009-04-17 14:06:01 UTC (rev 6236) @@ -1,3 +1,8 @@ grant { + permission java.lang.RuntimePermission "createClassLoader"; + permission java.lang.RuntimePermission "getProtectionDomain"; permission java.util.PropertyPermission "*", "read"; + permission java.io.FilePermission "<<ALL FILES>>", "read"; + + permission java.lang.RuntimePermission "accessDeclaredMembers"; }; Modified: trunk/jython/tests/policy/run.sh =================================================================== --- trunk/jython/tests/policy/run.sh 2009-04-17 03:44:35 UTC (rev 6235) +++ trunk/jython/tests/policy/run.sh 2009-04-17 14:06:01 UTC (rev 6236) @@ -1 +1 @@ -java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ +java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython -Dpython.home=../../dist -Dpython.cachedir.skip=true $@ This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-17 03:44:56
|
Revision: 6235 http://jython.svn.sourceforge.net/jython/?rev=6235&view=rev Author: pjenvey Date: 2009-04-17 03:44:35 +0000 (Fri, 17 Apr 2009) Log Message: ----------- o fix memoization with cyclic structures: http://bugs.python.org/issue998998 o cleanup persistent_id/load handling, allow persistent_load as a list Modified Paths: -------------- trunk/jython/Lib/test/test_cpickle_jy.py trunk/jython/src/org/python/modules/cPickle.java Modified: trunk/jython/Lib/test/test_cpickle_jy.py =================================================================== --- trunk/jython/Lib/test/test_cpickle_jy.py 2009-04-17 01:38:24 UTC (rev 6234) +++ trunk/jython/Lib/test/test_cpickle_jy.py 2009-04-17 03:44:35 UTC (rev 6235) @@ -7,13 +7,34 @@ import unittest from test import test_support +class MyClass(object): + pass + + 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_cyclic_memoize(self): + # http://bugs.python.org/issue998998 - cPickle shouldn't fail + # this, though pickle.py still does + m = MyClass() + m2 = MyClass() + s = set([m]) + m.foo = set([m2]) + m2.foo = s + + s2 = cPickle.loads(cPickle.dumps(s)) + self.assertEqual(len(s2), 1) + m3 = iter(s2).next() + self.assertEqual(len(m3.foo), 1) + m4 = iter(m3.foo).next() + self.assertEqual(m4.foo, s2) + + def test_main(): test_support.run_unittest(CPickleTestCase) Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2009-04-17 01:38:24 UTC (rev 6234) +++ trunk/jython/src/org/python/modules/cPickle.java 2009-04-17 03:44:35 UTC (rev 6235) @@ -770,14 +770,8 @@ private void save(PyObject object, boolean pers_save) { - if (!pers_save) { - if (persistent_id != null) { - PyObject pid = persistent_id.__call__(object); - if (pid != Py.None) { - save_pers(pid); - return; - } - } + if (!pers_save && persistent_id != null && save_pers(object, persistent_id)) { + return; } int d = get_id(object); @@ -801,12 +795,8 @@ if (save_type(object, t)) return; - if (inst_persistent_id != null) { - PyObject pid = inst_persistent_id.__call__(object); - if (pid != Py.None) { - save_pers(pid); - return; - } + if (!pers_save && inst_persistent_id != null && save_pers(object, inst_persistent_id)) { + return; } if (Py.isSubClass(t, PyType.TYPE)) { @@ -859,13 +849,20 @@ "Second element of tupe returned by " + reduce.__repr__() + " must be a tuple"); } - save_reduce(callable, arg_tup, state, listitems, dictitems, putMemo(d, object)); - + save_reduce(callable, arg_tup, state, listitems, dictitems, object); } - final private void save_pers(PyObject pid) { + final private boolean save_pers(PyObject object, PyObject pers_func) { + PyObject pid = pers_func.__call__(object); + if (pid == Py.None) { + return false; + } + if (protocol == 0) { + if (!Py.isInstance(pid, PyString.TYPE)) { + throw new PyException(PicklingError, "persistent id must be string"); + } file.write(PERSID); file.write(pid.toString()); file.write("\n"); @@ -873,10 +870,12 @@ save(pid, true); file.write(BINPERSID); } + return true; } final private void save_reduce(PyObject callable, PyObject arg_tup, - PyObject state, PyObject listitems, PyObject dictitems, int memoId) + PyObject state, PyObject listitems, PyObject dictitems, + PyObject object) { PyObject callableName = callable.__findattr__("__name__"); if(protocol >= 2 && callableName != null @@ -894,7 +893,10 @@ save(arg_tup); file.write(REDUCE); } - put(memoId); + + // Memoize + put(putMemo(get_id(object), object)); + if (listitems != Py.None) { batch_appends(listitems); } @@ -1697,17 +1699,30 @@ final private void load_persid() { - String pid = file.readlineNoNl(); - push(persistent_load.__call__(new PyString(pid))); + load_persid(new PyString(file.readlineNoNl())); } final private void load_binpersid() { - PyObject pid = pop(); - push(persistent_load.__call__(pid)); + load_persid(pop()); } + final private void load_persid(PyObject pid) { + if (persistent_load == null) { + throw new PyException(UnpicklingError, + "A load persistent id instruction was encountered,\n" + + "but no persistent_load function was specified."); + } + if (persistent_load instanceof PyList) { + ((PyList)persistent_load).append(pid); + } else { + pid = persistent_load.__call__(pid); + } + push(pid); + } + + final private void load_none() { push(Py.None); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-17 02:22:44
|
Revision: 6233 http://jython.svn.sourceforge.net/jython/?rev=6233&view=rev Author: pjenvey Date: 2009-04-17 01:35:16 +0000 (Fri, 17 Apr 2009) Log Message: ----------- fix LineBufferedWriter.write's result, cleanup Modified Paths: -------------- trunk/jython/src/org/python/core/io/BufferedWriter.java trunk/jython/src/org/python/core/io/LineBufferedWriter.java Modified: trunk/jython/src/org/python/core/io/BufferedWriter.java =================================================================== --- trunk/jython/src/org/python/core/io/BufferedWriter.java 2009-04-16 23:59:40 UTC (rev 6232) +++ trunk/jython/src/org/python/core/io/BufferedWriter.java 2009-04-17 01:35:16 UTC (rev 6233) @@ -53,10 +53,11 @@ int totalToWrite = total - toBuffer; int count = totalToWrite; + ByteBuffer[] bulk = new ByteBuffer[] {buffer, bytes}; // Prepare the buffer for writing buffer.flip(); while (count > 0) { - count -= rawIO.write(new ByteBuffer[] {buffer, bytes}); + count -= rawIO.write(bulk); } // Prepare the buffer for buffering buffer.clear(); Modified: trunk/jython/src/org/python/core/io/LineBufferedWriter.java =================================================================== --- trunk/jython/src/org/python/core/io/LineBufferedWriter.java 2009-04-16 23:59:40 UTC (rev 6232) +++ trunk/jython/src/org/python/core/io/LineBufferedWriter.java 2009-04-17 01:35:16 UTC (rev 6233) @@ -23,7 +23,7 @@ /** {@inheritDoc} */ public int write(ByteBuffer bytes) { - int written = 0; + int size = bytes.remaining(); while (bytes.hasRemaining()) { byte next = bytes.get(); @@ -37,11 +37,10 @@ } if (next == LF_BYTE) { - written += buffer.position(); flush(); } } - return written; + return size; } } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-17 02:22:35
|
Revision: 6234 http://jython.svn.sourceforge.net/jython/?rev=6234&view=rev Author: pjenvey Date: 2009-04-17 01:38:24 +0000 (Fri, 17 Apr 2009) Log Message: ----------- rename eof_fodder7 to match other SyntaxError'ing tests. avoids test_compiler from randomly importing it Modified Paths: -------------- trunk/jython/Lib/test/test_eof_jy.py Added Paths: ----------- trunk/jython/Lib/test/badsyntax_eof1.py Removed Paths: ------------- trunk/jython/Lib/test/eof_fodder7.py Copied: trunk/jython/Lib/test/badsyntax_eof1.py (from rev 6223, trunk/jython/Lib/test/eof_fodder7.py) =================================================================== --- trunk/jython/Lib/test/badsyntax_eof1.py (rev 0) +++ trunk/jython/Lib/test/badsyntax_eof1.py 2009-04-17 01:38:24 UTC (rev 6234) @@ -0,0 +1,5 @@ +def hi(): + pass + +def bye(): + hi( Deleted: trunk/jython/Lib/test/eof_fodder7.py =================================================================== --- trunk/jython/Lib/test/eof_fodder7.py 2009-04-17 01:35:16 UTC (rev 6233) +++ trunk/jython/Lib/test/eof_fodder7.py 2009-04-17 01:38:24 UTC (rev 6234) @@ -1,5 +0,0 @@ -def hi(): - pass - -def bye(): - hi( Modified: trunk/jython/Lib/test/test_eof_jy.py =================================================================== --- trunk/jython/Lib/test/test_eof_jy.py 2009-04-17 01:35:16 UTC (rev 6233) +++ trunk/jython/Lib/test/test_eof_jy.py 2009-04-17 01:38:24 UTC (rev 6234) @@ -47,7 +47,7 @@ def test_trailing_paren(self): try: - import eof_fodder7 + import badsyntax_eof1 except SyntaxError, cause: self.assertEquals(cause.lineno, 5) This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-16 23:59:54
|
Revision: 6232 http://jython.svn.sourceforge.net/jython/?rev=6232&view=rev Author: pjenvey Date: 2009-04-16 23:59:40 +0000 (Thu, 16 Apr 2009) Log Message: ----------- cleanup/coding standards Modified Paths: -------------- trunk/jython/src/org/python/core/io/StreamIO.java trunk/jython/src/org/python/core/io/UniversalIOWrapper.java Modified: trunk/jython/src/org/python/core/io/StreamIO.java =================================================================== --- trunk/jython/src/org/python/core/io/StreamIO.java 2009-04-16 06:18:40 UTC (rev 6231) +++ trunk/jython/src/org/python/core/io/StreamIO.java 2009-04-16 23:59:40 UTC (rev 6232) @@ -16,8 +16,8 @@ import java.nio.channels.ReadableByteChannel; import java.nio.channels.WritableByteChannel; +import org.python.core.Py; import org.python.core.imp; -import org.python.core.Py; /** * Raw I/O implementation for simple streams. @@ -82,9 +82,6 @@ * Construct a StreamIO for the given write channel. * * @param writeChannel a WritableByteChannel - * @param isatty boolean whether this io object is a tty device - * @param closefd boolean whether the underlying file is closed on - * close() (defaults to True) */ public StreamIO(WritableByteChannel writeChannel) { this(writeChannel, true); @@ -160,56 +157,62 @@ /** Unwrap one or more nested FilterInputStreams. */ private static FileDescriptor getInputFileDescriptor(InputStream stream) throws IOException { - if (stream == null) - return null; - if (stream instanceof FileInputStream) - return ((FileInputStream)stream).getFD(); - if (stream instanceof FilterInputStream) { - Field inField = null; - try { - inField = FilterInputStream.class.getDeclaredField("in"); - inField.setAccessible(true); - return getInputFileDescriptor((InputStream)inField.get(stream)); - } catch (Exception e) { - } finally { - if (inField != null && inField.isAccessible()) - inField.setAccessible(false); - } - } - return null; + if (stream == null) { + return null; + } + if (stream instanceof FileInputStream) { + return ((FileInputStream)stream).getFD(); + } + if (stream instanceof FilterInputStream) { + Field inField = null; + try { + inField = FilterInputStream.class.getDeclaredField("in"); + inField.setAccessible(true); + return getInputFileDescriptor((InputStream)inField.get(stream)); + } catch (Exception e) { + // XXX: masking other exceptions + } finally { + if (inField != null && inField.isAccessible()) + inField.setAccessible(false); + } + } + return null; } /** Unwrap one or more nested FilterOutputStreams. */ private static FileDescriptor getOutputFileDescriptor(OutputStream stream) throws IOException { - if (stream == null) - return null; - if (stream instanceof FileOutputStream) - return ((FileOutputStream)stream).getFD(); - if (stream instanceof FilterOutputStream) { - Field outField = null; - try { - outField = FilterOutputStream.class.getDeclaredField("out"); - outField.setAccessible(true); - return getOutputFileDescriptor((OutputStream)outField.get(stream)); - } catch (Exception e) { - } finally { - if (outField != null && outField.isAccessible()) - outField.setAccessible(false); - } - } - return null; + if (stream == null) { + return null; + } + if (stream instanceof FileOutputStream) { + return ((FileOutputStream)stream).getFD(); + } + if (stream instanceof FilterOutputStream) { + Field outField = null; + try { + outField = FilterOutputStream.class.getDeclaredField("out"); + outField.setAccessible(true); + return getOutputFileDescriptor((OutputStream)outField.get(stream)); + } catch (Exception e) { + // XXX: masking other exceptions + } finally { + if (outField != null && outField.isAccessible()) + outField.setAccessible(false); + } + } + return null; } /** {@inheritDoc} */ - public boolean isatty() { checkClosed(); FileDescriptor fd; try { - if ( ((fd = getInputFileDescriptor(inputStream)) == null) && - ((fd = getOutputFileDescriptor(outputStream)) == null)) - return false; + if ((fd = getInputFileDescriptor(inputStream)) == null + && (fd = getOutputFileDescriptor(outputStream)) == null) { + return false; + } } catch (IOException e) { return false; } Modified: trunk/jython/src/org/python/core/io/UniversalIOWrapper.java =================================================================== --- trunk/jython/src/org/python/core/io/UniversalIOWrapper.java 2009-04-16 06:18:40 UTC (rev 6231) +++ trunk/jython/src/org/python/core/io/UniversalIOWrapper.java 2009-04-16 23:59:40 UTC (rev 6232) @@ -3,7 +3,6 @@ import java.nio.ByteBuffer; import java.util.EnumSet; -import java.util.Iterator; import org.python.core.Py; import org.python.core.PyObject; @@ -189,7 +188,6 @@ byte[] readaheadArray; int readaheadPos; int interimBuilderPos; - String line; do { readaheadArray = readahead.array(); @@ -313,12 +311,12 @@ if (size == 0) { return Py.None; } else if (size == 1) { - Newline newline = (Newline)newlineTypes.iterator().next(); + Newline newline = newlineTypes.iterator().next(); return new PyString(newline.getValue()); } - int i = 0; PyObject[] newlines = new PyObject[size]; + int i = 0; for (Newline newline : newlineTypes) { newlines[i++] = new PyString(newline.getValue()); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-16 06:18:48
|
Revision: 6231 http://jython.svn.sourceforge.net/jython/?rev=6231&view=rev Author: zyasoft Date: 2009-04-16 06:18:40 +0000 (Thu, 16 Apr 2009) Log Message: ----------- Fixed JavaImportHelper#getFromListAsStrings, which was assuming that the PyTuple it was iterating over would contain String, not PyString. Now allow both, just in case, since either should be applicable anyway. Modified Paths: -------------- branches/newlist/src/org/python/core/JavaImportHelper.java branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/packagecache/PackageManager.java Modified: branches/newlist/src/org/python/core/JavaImportHelper.java =================================================================== --- branches/newlist/src/org/python/core/JavaImportHelper.java 2009-04-16 05:48:35 UTC (rev 6230) +++ branches/newlist/src/org/python/core/JavaImportHelper.java 2009-04-16 06:18:40 UTC (rev 6231) @@ -120,6 +120,9 @@ Iterator iterator = ((PyTuple) fromlist).iterator(); while (iterator.hasNext()) { Object obj = iterator.next(); + if (obj instanceof PyString) { + obj = ((PyString)obj).string; + } if (obj instanceof String) { String fromName = (String) obj; if (!"*".equals(fromName)) { Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-16 05:48:35 UTC (rev 6230) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-16 06:18:40 UTC (rev 6231) @@ -142,7 +142,7 @@ value = new PyList(value); setsliceIterator(start, stop, step, value.asIterable().iterator()); } else { - System.err.println("List"); +// System.err.println("List"); List valueList = (List) value.__tojava__(List.class); if (valueList != null && valueList != Py.NoConversion) { setsliceList(start, stop, step, valueList); Modified: branches/newlist/src/org/python/core/packagecache/PackageManager.java =================================================================== --- branches/newlist/src/org/python/core/packagecache/PackageManager.java 2009-04-16 05:48:35 UTC (rev 6230) +++ branches/newlist/src/org/python/core/packagecache/PackageManager.java 2009-04-16 06:18:40 UTC (rev 6231) @@ -88,11 +88,9 @@ if (!instantiate) { PyList ret = cls.keys(); - PyList dictKeys = dict.keys(); - for (int i = 0; i < dictKeys.__len__(); i++) { - PyObject name = dictKeys.pyget(i); + for (PyObject name : dictKeys.asIterable()) { if (!cls.has_key(name)) { if (exclpkgs && dict.get(name) instanceof PyJavaPackage) continue; @@ -103,7 +101,6 @@ return ret; } - for (PyObject pyname : cls.keys().asIterable()) { if (!dict.has_key(pyname)) { String name = pyname.toString(); @@ -118,8 +115,7 @@ * Helper merging list2 into list1. Returns list1. */ protected PyList merge(PyList list1, PyList list2) { - for (int i = 0; i < list2.__len__(); i++) { - PyObject name = list2.pyget(i); + for (PyObject name : list2.asIterable()) { list1.append(name); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-16 05:48:48
|
Revision: 6230 http://jython.svn.sourceforge.net/jython/?rev=6230&view=rev Author: pjenvey Date: 2009-04-16 05:48:35 +0000 (Thu, 16 Apr 2009) Log Message: ----------- make BadPickleGet an actual exception Modified Paths: -------------- trunk/jython/src/org/python/modules/cPickle.java Modified: trunk/jython/src/org/python/modules/cPickle.java =================================================================== --- trunk/jython/src/org/python/modules/cPickle.java 2009-04-16 03:11:53 UTC (rev 6229) +++ trunk/jython/src/org/python/modules/cPickle.java 2009-04-16 05:48:35 UTC (rev 6230) @@ -384,11 +384,8 @@ public static PyObject PicklingError; public static PyObject UnpickleableError; public static PyObject UnpicklingError; + public static PyObject BadPickleGet; - public static final PyString BadPickleGet = - new PyString("cPickle.BadPickleGet"); - - final static char MARK = '('; final static char STOP = '.'; final static char POP = '0'; @@ -510,6 +507,7 @@ PicklingError = Py.makeClass("PicklingError", PickleError, exceptionNamespace()); UnpickleableError = Py.makeClass("UnpickleableError", PicklingError, _UnpickleableError()); UnpicklingError = Py.makeClass("UnpicklingError", PickleError, exceptionNamespace()); + BadPickleGet = Py.makeClass("BadPickleGet", UnpicklingError, exceptionNamespace()); } public static PyObject exceptionNamespace() { @@ -2067,16 +2065,18 @@ final private void load_get() { String py_str = file.readlineNoNl(); PyObject value = memo.get(py_str); - if (value == null) + if (value == null) { throw new PyException(BadPickleGet, py_str); + } push(value); } final private void load_binget() { String py_key = String.valueOf((int)file.read(1).charAt(0)); PyObject value = memo.get(py_key); - if (value == null) + if (value == null) { throw new PyException(BadPickleGet, py_key); + } push(value); } @@ -2084,8 +2084,9 @@ int i = read_binint(); String py_key = String.valueOf(i); PyObject value = memo.get(py_key); - if (value == null) + if (value == null) { throw new PyException(BadPickleGet, py_key); + } push(value); } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-16 03:11:58
|
Revision: 6229 http://jython.svn.sourceforge.net/jython/?rev=6229&view=rev Author: zyasoft Date: 2009-04-16 03:11:53 +0000 (Thu, 16 Apr 2009) Log Message: ----------- Merged revisions 6208-6214,6218-6221,6224-6226 via svnmerge from https://jython.svn.sourceforge.net/svnroot/jython/trunk/jython ........ r6208 | amak | 2009-04-10 09:36:58 -0600 (Fri, 10 Apr 2009) | 2 lines Creating a poll object cache for MS Windows, because of a problem on that platform with creating too many Selectors. http://bugs.jython.org/issue1291 ........ r6209 | pjenvey | 2009-04-10 13:21:01 -0600 (Fri, 10 Apr 2009) | 5 lines cleanup class __module__ setup: o type/ClassType must default a __module__ (instead of Py.makeClass) for when types are constructed via type(name, bases, dict) o simplify the compiler's __module__ setup as it should just fail fast ........ r6210 | pjenvey | 2009-04-10 15:12:28 -0600 (Fri, 10 Apr 2009) | 3 lines ClassType shouldn't go through object's lookup machinery at all. not even __class__ or __call__ should show up in its lookup ........ r6211 | pjenvey | 2009-04-10 17:09:34 -0600 (Fri, 10 Apr 2009) | 1 line feeble attempt of debugging why these fail on hudson's all job ........ r6212 | pjenvey | 2009-04-10 18:24:56 -0600 (Fri, 10 Apr 2009) | 3 lines from: http://svn.python.org/projects/python/branches/release25-maint/Lib/test/test_cmd_line.py@54387 ........ r6213 | pjenvey | 2009-04-10 18:25:21 -0600 (Fri, 10 Apr 2009) | 3 lines o reapply test_cmd_line workaround o fix error handling of bad -c/-m command lines ........ r6214 | pjenvey | 2009-04-10 19:11:10 -0600 (Fri, 10 Apr 2009) | 1 line fix test_sax when running under a path name with spaces ........ r6218 | amak | 2009-04-11 12:26:24 -0600 (Sat, 11 Apr 2009) | 1 line Adding a readme.txt so that the WEB-INF/lib directory doesn't end getting omitted up by the installer. ........ r6219 | pjenvey | 2009-04-11 14:49:13 -0600 (Sat, 11 Apr 2009) | 1 line cleanup ........ r6220 | pjenvey | 2009-04-11 15:27:36 -0600 (Sat, 11 Apr 2009) | 1 line encode unicode printed to file objects per the file's encoding ........ r6221 | pjenvey | 2009-04-11 18:21:44 -0600 (Sat, 11 Apr 2009) | 1 line restore the original encoding of SyntaxError text ........ r6224 | fwierzbicki | 2009-04-14 15:16:03 -0600 (Tue, 14 Apr 2009) | 6 lines Applied patch from http://bugs.jython.org/issue1271: Bean property accessors in derived class overide methods in base class. I altered his tests so that they are easily runnable by "ant javatest". Thanks to Geoffrey French for the fix. Also fixed a bad comment in IdentityTest.java. ........ r6225 | fwierzbicki | 2009-04-14 16:50:45 -0600 (Tue, 14 Apr 2009) | 3 lines Policy file that disallows writing to the filesystem to test GAE security patch. ........ r6226 | fwierzbicki | 2009-04-14 17:00:40 -0600 (Tue, 14 Apr 2009) | 2 lines Lame shell script to test jython with policy that disallows file writes. ........ Modified Paths: -------------- branches/newlist/Lib/os.py branches/newlist/Lib/select.py branches/newlist/Lib/test/test_class_jy.py branches/newlist/Lib/test/test_cmd_line.py branches/newlist/Lib/test/test_sax.py branches/newlist/NEWS branches/newlist/src/org/python/compiler/Module.java branches/newlist/src/org/python/core/ParserFacade.java branches/newlist/src/org/python/core/Py.java branches/newlist/src/org/python/core/PyClass.java branches/newlist/src/org/python/core/PyFrame.java branches/newlist/src/org/python/core/PyJavaType.java branches/newlist/src/org/python/core/PyType.java branches/newlist/src/org/python/core/StdoutWrapper.java branches/newlist/src/org/python/core/imp.java branches/newlist/src/org/python/util/jython.java branches/newlist/src/shell/jython branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java Added Paths: ----------- branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt branches/newlist/tests/policy/ branches/newlist/tests/policy/nowrite.policy branches/newlist/tests/policy/run.sh branches/newlist/tests/python/prop_test.py Removed Paths: ------------- branches/newlist/tests/policy/nowrite.policy branches/newlist/tests/policy/run.sh Property Changed: ---------------- branches/newlist/ Property changes on: branches/newlist ___________________________________________________________________ Modified: svnmerge-integrated - /branches/modjy:1-6074 /branches/pbcvm:1-6045 /trunk/jython:1-6206 + /branches/modjy:1-6074 /branches/pbcvm:1-6045 /trunk/jython:1-6228 Copied: branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt (from rev 6226, trunk/jython/Demo/modjy_webapp/WEB-INF/lib/readme.txt) =================================================================== --- branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt (rev 0) +++ branches/newlist/Demo/modjy_webapp/WEB-INF/lib/readme.txt 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1 @@ +The jython.jar file should be placed in this directory. Modified: branches/newlist/Lib/os.py =================================================================== --- branches/newlist/Lib/os.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/os.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -1080,7 +1080,6 @@ return _posix.isatty(fileno) if not isinstance(fileno, IOBase): - print fileno raise TypeError('a file descriptor is required') return fileno.isatty() Modified: branches/newlist/Lib/select.py =================================================================== --- branches/newlist/Lib/select.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/select.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -7,10 +7,11 @@ import java.nio.channels.Selector from java.nio.channels.SelectionKey import OP_ACCEPT, OP_CONNECT, OP_WRITE, OP_READ +import errno +import os +import Queue import socket -import errno - class error(Exception): pass ALL = None @@ -144,10 +145,18 @@ except java.lang.Exception, jlx: raise _map_exception(jlx) - def close(self): + def _deregister_all(self): try: for k in self.selector.keys(): k.cancel() + # Keys are not actually removed from the selector until the next select operation. + self.selector.selectNow() + except java.lang.Exception, jlx: + raise _map_exception(jlx) + + def close(self): + try: + self._deregister_all() self.selector.close() except java.lang.Exception, jlx: raise _map_exception(jlx) @@ -165,10 +174,48 @@ return 0 return int(floatvalue * 1000) # Convert to milliseconds +# This cache for poll objects is required because of a bug in java on MS Windows +# http://bugs.jython.org/issue1291 + +class poll_object_cache: + + def __init__(self): + self.is_windows = os.get_os_type() == 'nt' + if self.is_windows: + self.poll_object_queue = Queue.Queue() + import atexit + atexit.register(self.finalize) + + def get_poll_object(self): + if not self.is_windows: + return poll() + try: + return self.poll_object_queue.get(False) + except Queue.Empty: + return poll() + + def release_poll_object(self, pobj): + if self.is_windows: + pobj._deregister_all() + self.poll_object_queue.put(pobj) + else: + pobj.close() + + def finalize(self): + if self.is_windows: + while True: + try: + p = self.poll_object_queue.get(False) + p.close() + except Queue.Empty: + return + +_poll_object_cache = poll_object_cache() + def native_select(read_fd_list, write_fd_list, outofband_fd_list, timeout=None): timeout = _calcselecttimeoutvalue(timeout) # First create a poll object to do the actual watching. - pobj = poll() + pobj = _poll_object_cache.get_poll_object() try: registered_for_read = {} # Check the read list @@ -192,10 +239,7 @@ write_ready_list.append(fd) return read_ready_list, write_ready_list, oob_ready_list finally: - # Need to close the poll object no matter what happened - # If it is left open, it may still have references to sockets - # That were registered before any exceptions occurred - pobj.close() + _poll_object_cache.release_poll_object(pobj) select = native_select Modified: branches/newlist/Lib/test/test_class_jy.py =================================================================== --- branches/newlist/Lib/test/test_class_jy.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/test/test_class_jy.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -17,17 +17,24 @@ self.assertEqual(str.__module__, '__builtin__') class Foo: pass - self.assertEqual(Foo.__module__, __name__) - self.assertEqual(str(Foo), '%s.Foo' % __name__) - self.assert_(repr(Foo).startswith('<class %s.Foo at' % __name__)) - foo = Foo() - self.assert_(str(foo).startswith('<%s.Foo instance at' % __name__)) + Fu = types.ClassType('Fu', (), {}) + for cls in Foo, Fu: + self.assert_('__module__' in cls.__dict__) + self.assertEqual(cls.__module__, __name__) + self.assertEqual(str(cls), '%s.%s' % (__name__, cls.__name__)) + self.assert_(repr(cls).startswith('<class %s.%s at' % + (__name__, cls.__name__))) + obj = cls() + self.assert_(str(obj).startswith('<%s.%s instance at' % + (__name__, cls.__name__))) class Bar(object): pass class Baz(Object): pass - for cls in Bar, Baz: + Bang = type('Bang', (), {}) + for cls in Bar, Baz, Bang: + self.assert_('__module__' in cls.__dict__) self.assertEqual(cls.__module__, __name__) self.assertEqual(str(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) self.assertEqual(repr(cls), "<class '%s.%s'>" % (__name__, cls.__name__)) Modified: branches/newlist/Lib/test/test_cmd_line.py =================================================================== --- branches/newlist/Lib/test/test_cmd_line.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/test/test_cmd_line.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -1,4 +1,3 @@ -# from CPython 2.4, changing Python to Jython in test_version import test.test_support, unittest import sys @@ -7,14 +6,20 @@ class CmdLineTest(unittest.TestCase): def start_python(self, cmd_line): - outfp, infp = popen2.popen4('%s %s' % (sys.executable, cmd_line)) + outfp, infp = popen2.popen4('"%s" %s' % (sys.executable, cmd_line)) infp.close() data = outfp.read() outfp.close() + # try to cleanup the child so we don't appear to leak when running + # with regrtest -R. This should be a no-op on Windows. + popen2._cleanup() return data - def exit_code(self, cmd_line): - return subprocess.call([sys.executable, cmd_line], stderr=subprocess.PIPE) + def exit_code(self, *args): + cmd_line = [sys.executable] + cmd_line.extend(args) + return subprocess.call(cmd_line, stdout=subprocess.PIPE, + stderr=subprocess.PIPE) def test_directories(self): self.assertNotEqual(self.exit_code('.'), 0) @@ -22,7 +27,7 @@ def verify_valid_flag(self, cmd_line): data = self.start_python(cmd_line) - self.assertTrue(data == '' or data.endswith('\n'), repr(data)) + self.assertTrue(data == '' or data.endswith('\n')) self.assertTrue('Traceback' not in data) def test_environment(self): @@ -45,11 +50,45 @@ self.assertTrue('usage' in self.start_python('-h')) def test_version(self): - version = 'Jython %d.%d' % sys.version_info[:2] + prefix = 'J' if test.test_support.is_jython else 'P' + version = prefix + 'ython %d.%d' % sys.version_info[:2] self.assertTrue(self.start_python('-V').startswith(version)) + def test_run_module(self): + # Test expected operation of the '-m' switch + # Switch needs an argument + self.assertNotEqual(self.exit_code('-m'), 0) + # Check we get an error for a nonexistent module + self.assertNotEqual( + self.exit_code('-m', 'fnord43520xyz'), + 0) + # Check the runpy module also gives an error for + # a nonexistent module + self.assertNotEqual( + self.exit_code('-m', 'runpy', 'fnord43520xyz'), + 0) + # All good if module is located and run successfully + self.assertEqual( + self.exit_code('-m', 'timeit', '-n', '1'), + 0) + + def test_run_code(self): + # Test expected operation of the '-c' switch + # Switch needs an argument + self.assertNotEqual(self.exit_code('-c'), 0) + # Check we get an error for an uncaught exception + self.assertNotEqual( + self.exit_code('-c', 'raise Exception'), + 0) + # All good if execution is successful + self.assertEqual( + self.exit_code('-c', 'pass'), + 0) + + def test_main(): test.test_support.run_unittest(CmdLineTest) + test.test_support.reap_children() if __name__ == "__main__": test_main() Modified: branches/newlist/Lib/test/test_sax.py =================================================================== --- branches/newlist/Lib/test/test_sax.py 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/Lib/test/test_sax.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -2,6 +2,7 @@ # regression test for SAX 2.0 # $Id: test_sax.py,v 1.13 2004/03/20 07:46:04 fdrake Exp $ +import urllib from xml.sax import handler, make_parser, ContentHandler, \ SAXException, SAXReaderNotAvailable, SAXParseException try: @@ -13,7 +14,7 @@ XMLFilterBase, Location from xml.sax.xmlreader import InputSource, AttributesImpl, AttributesNSImpl from cStringIO import StringIO -from test.test_support import verbose, TestFailed, findfile +from test.test_support import is_jython, verbose, TestFailed, findfile # ===== Utilities @@ -472,14 +473,16 @@ parser.setContentHandler(xmlgen) testfile = findfile("test.xml") parser.parse(testfile) - #In Jython, the system id is a URL with forward slashes, and under Windows - #findfile returns a path with backslashes, so replace the backslashes with - #forward - import os - if os.name == 'java': + if is_jython: + # In Jython, the system id is a URL with forward slashes, and + # under Windows findfile returns a path with backslashes, so + # replace the backslashes with forward testfile = testfile.replace('\\', '/') - return xmlgen.location.getSystemId().endswith(testfile) and \ + # XXX: may not match getSystemId when the filename contains funky + # characters (like ':') + expected = urllib.quote(testfile) + return xmlgen.location.getSystemId().endswith(expected) and \ xmlgen.location.getPublicId() is None Modified: branches/newlist/NEWS =================================================================== --- branches/newlist/NEWS 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/NEWS 2009-04-16 03:11:53 UTC (rev 6229) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1271 ] Bean property accessors in derived class overide methods in base class - [ 1264 ] 'is not' test exhibits incorrect behaviour when wrapping Java objects - [ 1295 ] Setting a write-only bean property causes a NPE - [ 1272 ] ASTList ClassCastException Modified: branches/newlist/src/org/python/compiler/Module.java =================================================================== --- branches/newlist/src/org/python/compiler/Module.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/compiler/Module.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -438,25 +438,14 @@ CodeCompiler compiler = new CodeCompiler(this, printResults); if (classBody) { - Label label_got_name = new Label(); - int module_tmp = c.getLocal("org/python/core/PyObject"); - + // Set the class's __module__ to __name__. fails when there's no __name__ c.aload(1); c.ldc("__module__"); - c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); - c.dup(); - c.ifnonnull(label_got_name); - c.pop(); c.aload(1); c.ldc("__name__"); - c.invokevirtual("org/python/core/PyFrame", "getname_or_null", "(" + $str + ")" + $pyObj); + c.invokevirtual("org/python/core/PyFrame", "getname", "(" + $str + ")" + $pyObj); - c.label(label_got_name); - c.astore(module_tmp); - c.aload(1); - c.ldc("__module__"); - c.aload(module_tmp); c.invokevirtual("org/python/core/PyFrame", "setlocal", "(" + $str + $pyObj + ")V"); } Modified: branches/newlist/src/org/python/core/ParserFacade.java =================================================================== --- branches/newlist/src/org/python/core/ParserFacade.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/ParserFacade.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -44,7 +44,7 @@ private ParserFacade() {} - private static String getLine(BufferedReader reader, int line) { + private static String getLine(ExpectedEncodingBufferedReader reader, int line) { if (reader == null) { return ""; } @@ -53,7 +53,14 @@ for (int i = 0; i < line; i++) { text = reader.readLine(); } - return text == null ? text : text + "\n"; + if (text == null) { + return text; + } + if (reader.encoding != null) { + // restore the original encoding + text = new PyUnicode(text).encode(reader.encoding); + } + return text + "\n"; } catch (IOException ioe) { } return text; @@ -80,7 +87,7 @@ line = node.getLine(); col = node.getCharPositionInLine(); } - String text=getLine(reader, line); + String text= getLine(reader, line); String msg = e.getMessage(); if (e.getType() == Py.IndentationError) { return new PyIndentationError(msg, line, col, text, filename); Modified: branches/newlist/src/org/python/core/Py.java =================================================================== --- branches/newlist/src/org/python/core/Py.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/Py.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -1566,14 +1566,6 @@ * @return a new Python Class PyObject */ public static PyObject makeClass(String name, PyObject[] bases, PyObject dict) { - PyFrame frame = getFrame(); - if (dict.__finditem__("__module__") == null) { - PyObject module = frame.getglobal("__name__"); - if (module != null) { - dict.__setitem__("__module__", module); - } - } - PyObject metaclass = dict.__finditem__("__metaclass__"); if (metaclass == null) { @@ -1584,7 +1576,7 @@ metaclass = base.getType(); } } else { - PyObject globals = frame.f_globals; + PyObject globals = getFrame().f_globals; if (globals != null) { metaclass = globals.__finditem__("__metaclass__"); } Modified: branches/newlist/src/org/python/core/PyClass.java =================================================================== --- branches/newlist/src/org/python/core/PyClass.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyClass.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -1,10 +1,7 @@ // Copyright (c) Corporation for National Research Initiatives package org.python.core; -import org.python.expose.ExposedGet; -import org.python.expose.ExposedMethod; import org.python.expose.ExposedNew; -import org.python.expose.ExposedSet; import org.python.expose.ExposedType; /** @@ -16,16 +13,12 @@ public static final PyType TYPE = PyType.fromClass(PyClass.class); /** Holds the namespace for this class */ - @ExposedGet public PyObject __dict__; /** The base classes of this class */ - @ExposedGet public PyTuple __bases__; /** The name of this class */ - @ExposedGet - @ExposedSet public String __name__; // Store these methods for performance optimization. These are only used by PyInstance @@ -55,10 +48,8 @@ if (!(dict instanceof PyStringMap || dict instanceof PyDictionary)) { throw Py.TypeError("PyClass_New: dict must be a dictionary"); } - if (dict.__finditem__("__doc__") == null) { - dict.__setitem__("__doc__", Py.None); - } - findModule(dict); + PyType.ensureDoc(dict); + PyType.ensureModule(dict); if (!(bases instanceof PyTuple)) { throw Py.TypeError("PyClass_New: bases must be a tuple"); @@ -94,19 +85,6 @@ __contains__ = lookup("__contains__"); } - private static void findModule(PyObject dict) { - PyObject module = dict.__finditem__("__module__"); - if (module == null || module == Py.None) { - PyFrame f = Py.getFrame(); - if (f != null) { - PyObject nm = f.f_globals.__finditem__("__name__"); - if (nm != null) { - dict.__setitem__("__module__", nm); - } - } - } - } - PyObject lookup(String name) { PyObject result = __dict__.__finditem__(name); if (result == null && __bases__ != null) { @@ -127,14 +105,70 @@ @Override public PyObject __findattr_ex__(String name) { + if (name == "__dict__") { + return __dict__; + } + if (name == "__bases__") { + return __bases__; + } + if (name == "__name__") { + return Py.newString(__name__); + } + PyObject result = lookup(name); if (result == null) { - return super.__findattr_ex__(name); + return result; } return result.__get__(null, this); } @Override + public void __setattr__(String name, PyObject value) { + if (name == "__dict__") { + setDict(value); + return; + } else if (name == "__bases__") { + setBases(value); + return; + } else if (name == "__name__") { + setName(value); + return; + } else if (name == "__getattr__") { + __getattr__ = value; + return; + } else if (name == "__setattr__") { + __setattr__ = value; + return; + } else if (name == "__delattr__") { + __delattr__ = value; + return; + } else if (name == "__tojava__") { + __tojava__ = value; + return; + } else if (name == "__del__") { + __del__ = value; + return; + } else if (name == "__contains__") { + __contains__ = value; + return; + } + + if (value == null) { + try { + __dict__.__delitem__(name); + } catch (PyException pye) { + noAttributeError(name); + } + } + __dict__.__setitem__(name, value); + } + + @Override + public void __delattr__(String name) { + __setattr__(name, null); + } + + @Override public void __rawdir__(PyDictionary accum) { mergeClassDict(accum, this); } @@ -150,11 +184,6 @@ @Override public PyObject __call__(PyObject[] args, String[] keywords) { - return classobj___call__(args, keywords); - } - - @ExposedMethod - final PyObject classobj___call__(PyObject[] args, String[] keywords) { PyInstance inst; if (__del__ == null) { inst = new PyInstance(this); @@ -166,6 +195,11 @@ return inst; } + @Override + public boolean isCallable() { + return true; + } + /* PyClass's are compared based on __name__ */ @Override public int __cmp__(PyObject other) { @@ -219,17 +253,20 @@ return false; } - @ExposedSet(name = "__dict__") public void setDict(PyObject value) { - if (!(value instanceof PyStringMap || value instanceof PyDictionary)) { + if (value == null || !(value instanceof PyStringMap || value instanceof PyDictionary)) { throw Py.TypeError("__dict__ must be a dictionary object"); } __dict__ = value; } - @ExposedSet(name = "__bases__") - public void setBases(PyTuple value) { - for (PyObject base : value.getArray()) { + public void setBases(PyObject value) { + if (value == null || !(value instanceof PyTuple)) { + throw Py.TypeError("__bases__ must be a tuple object"); + } + + PyTuple bases = (PyTuple)value; + for (PyObject base : bases.getArray()) { if (!(base instanceof PyClass)) { throw Py.TypeError("__bases__ items must be classes"); } @@ -237,6 +274,17 @@ throw Py.TypeError("a __bases__ item causes an inheritance cycle"); } } - __bases__ = value; + __bases__ = bases; } + + public void setName(PyObject value) { + if (value == null || !Py.isInstance(value, PyString.TYPE)) { + throw Py.TypeError("__name__ must be a string object"); + } + String name = value.toString(); + if (name.contains("\u0000")) { + throw Py.TypeError("__name__ must not contain null bytes"); + } + __name__ = name; + } } Modified: branches/newlist/src/org/python/core/PyFrame.java =================================================================== --- branches/newlist/src/org/python/core/PyFrame.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyFrame.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -276,20 +276,6 @@ throw Py.NameError(String.format(NAME_ERROR_MSG, index)); } - public PyObject getname_or_null(String index) { - PyObject ret; - if (f_locals == null || f_locals == f_globals) { - ret = doGetglobal(index); - } else { - ret = f_locals.__finditem__(index); - if (ret != null) { - return ret; - } - ret = doGetglobal(index); - } - return ret; - } - public PyObject getglobal(String index) { PyObject ret = doGetglobal(index); if (ret != null) { Modified: branches/newlist/src/org/python/core/PyJavaType.java =================================================================== --- branches/newlist/src/org/python/core/PyJavaType.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyJavaType.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -407,7 +407,8 @@ // If one of our superclasses has something defined for this name, check if its a bean // property, and if so, try to fill in any gaps in our property from there - PyObject superForName = lookup(prop.__name__); + PyObject fromType[] = new PyObject[] { null }; + PyObject superForName = lookup_where(prop.__name__, fromType); if (superForName instanceof PyBeanProperty) { PyBeanProperty superProp = ((PyBeanProperty)superForName); // If it has a set method and we don't, take it regardless. If the types don't line @@ -426,6 +427,12 @@ // If the parent bean is hiding a static field, we need it as well. prop.field = superProp.field; } + } else if (superForName != null && fromType[0] != this && !(superForName instanceof PyBeanEvent)) { + // There is already an entry for this name + // It came from a type which is not @this; it came from a superclass + // It is not a bean event + // Do not override methods defined in superclass + continue; } // If the return types on the set and get methods for a property don't agree, the get // method takes precedence Modified: branches/newlist/src/org/python/core/PyType.java =================================================================== --- branches/newlist/src/org/python/core/PyType.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/PyType.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -374,10 +374,8 @@ dict.__setitem__("__new__", new PyStaticMethod(new_)); } - // NOTE: __module__ is already guaranteed by Py.makeClass - if (dict.__finditem__("__doc__") == null) { - dict.__setitem__("__doc__", Py.None); - } + ensureDoc(dict); + ensureModule(dict); // Calculate method resolution order mro_internal(); @@ -396,6 +394,37 @@ } } + /** + * Ensure dict contains a __doc__. + * + * @param dict a PyObject mapping + */ + public static void ensureDoc(PyObject dict) { + if (dict.__finditem__("__doc__") == null) { + dict.__setitem__("__doc__", Py.None); + } + } + + /** + * Ensure dict contains a __module__, retrieving it from the current frame if it + * doesn't exist. + * + * @param dict a PyObject mapping + */ + public static void ensureModule(PyObject dict) { + if (dict.__finditem__("__module__") != null) { + return; + } + PyFrame frame = Py.getFrame(); + if (frame == null) { + return; + } + PyObject name = frame.f_globals.__finditem__("__name__"); + if (name != null) { + dict.__setitem__("__module__", name); + } + } + private static PyObject invoke_new_(PyObject new_, PyType type, boolean init, PyObject[] args, String[] keywords) { PyObject newobj; Modified: branches/newlist/src/org/python/core/StdoutWrapper.java =================================================================== --- branches/newlist/src/org/python/core/StdoutWrapper.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/StdoutWrapper.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -105,8 +105,14 @@ file.write(" "); file.softspace = false; } - PyString string = o.__str__(); - String s = string.toString(); + + String s; + if (o instanceof PyUnicode && file.encoding != null) { + s = ((PyUnicode)o).encode(file.encoding, "strict"); + } else { + s = o.__str__().toString(); + } + int len = s.length(); file.write(s); if (o instanceof PyString) { Modified: branches/newlist/src/org/python/core/imp.java =================================================================== --- branches/newlist/src/org/python/core/imp.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/core/imp.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -20,7 +20,7 @@ private static final String UNKNOWN_SOURCEFILE = "<unknown>"; - public static final int APIVersion = 19; + public static final int APIVersion = 20; public static final int NO_MTIME = -1; Modified: branches/newlist/src/org/python/util/jython.java =================================================================== --- branches/newlist/src/org/python/util/jython.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/org/python/util/jython.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -259,6 +259,7 @@ interp.exec(opts.command); } catch (Throwable t) { Py.printException(t); + System.exit(1); } } @@ -273,7 +274,7 @@ } catch (Throwable t) { Py.printException(t); interp.cleanup(); - System.exit(0); + System.exit(-1); } } } @@ -407,8 +408,20 @@ Options.importSite = false; } else if (arg.equals("-c")) { - command = args[++index]; - if (!fixInteractive) interactive = false; + if (arg.length() > 2) { + command = arg.substring(2); + } + else if ((index + 1) < args.length) { + command = args[++index]; + } else { + System.err.println("Argument expected for the -c option"); + System.err.print(jython.usageHeader); + System.err.println("Try `jython -h' for more information."); + return false; + } + if (!fixInteractive) { + interactive = false; + } index++; break; } Modified: branches/newlist/src/shell/jython =================================================================== --- branches/newlist/src/shell/jython 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/src/shell/jython 2009-04-16 03:11:53 UTC (rev 6229) @@ -117,9 +117,13 @@ fi ;; # Match switches that take an argument - -c|-C|-jar|-Q|-W) - python_args=("${python_args[@]}" "$1" "$2") - shift + -c|-C|-m|-jar|-Q|-W) + if [ $# = 1 ]; then + python_args=("${python_args[@]}" "$1") + else + python_args=("${python_args[@]}" "$1" "$2") + shift + fi; ;; # Match -Dprop=val type args -D*) Modified: branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java =================================================================== --- branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -18,7 +18,6 @@ } public void testReadonly() { - //This used to cause an NPE see http://bugs.jython.org/issue1295 interp.execfile("tests/python/identity_test.py"); } } Modified: branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java =================================================================== --- branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-15 06:18:52 UTC (rev 6228) +++ branches/newlist/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-16 03:11:53 UTC (rev 6229) @@ -20,25 +20,8 @@ interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); } - //This test is for http://bugs.jython.org/issue1271 - public void testBaseProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("a = PropShadow.Derived()"); - interp.exec("assert a.foo() == 1, 'a'"); - interp.exec("assert a.bar() == 2, 'b'"); - */ + public void testShadowing() { + interp.execfile("tests/python/prop_test.py"); } - //This test is for http://bugs.jython.org/issue1271 - public void testDerivedProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("b = PropShadow.Derived()"); - interp.exec("assert b.getBaz() == 4, 'c'"); - interp.exec("assert b.getFoo() == 3, 'd'"); - interp.exec("assert b.foo() == 1, 'e'"); - interp.exec("assert b.foo() == 1, 'f'"); - */ - } } Deleted: branches/newlist/tests/policy/nowrite.policy =================================================================== --- trunk/jython/tests/policy/nowrite.policy 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/tests/policy/nowrite.policy 2009-04-16 03:11:53 UTC (rev 6229) @@ -1,3 +0,0 @@ -grant { - permission java.util.PropertyPermission "*", "read"; -}; Copied: branches/newlist/tests/policy/nowrite.policy (from rev 6226, trunk/jython/tests/policy/nowrite.policy) =================================================================== --- branches/newlist/tests/policy/nowrite.policy (rev 0) +++ branches/newlist/tests/policy/nowrite.policy 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1,3 @@ +grant { + permission java.util.PropertyPermission "*", "read"; +}; Deleted: branches/newlist/tests/policy/run.sh =================================================================== --- trunk/jython/tests/policy/run.sh 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/tests/policy/run.sh 2009-04-16 03:11:53 UTC (rev 6229) @@ -1 +0,0 @@ -java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ Copied: branches/newlist/tests/policy/run.sh (from rev 6226, trunk/jython/tests/policy/run.sh) =================================================================== --- branches/newlist/tests/policy/run.sh (rev 0) +++ branches/newlist/tests/policy/run.sh 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1 @@ +java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ Copied: branches/newlist/tests/python/prop_test.py (from rev 6226, trunk/jython/tests/python/prop_test.py) =================================================================== --- branches/newlist/tests/python/prop_test.py (rev 0) +++ branches/newlist/tests/python/prop_test.py 2009-04-16 03:11:53 UTC (rev 6229) @@ -0,0 +1,16 @@ +from org.python.tests.identity import IdentityObject + +#This test is for http://bugs.jython.org/issue1271 +from org.python.tests.props import PropShadow + +a = PropShadow.Derived() +assert a.foo() == 1, 'a' +assert a.bar() == 2, 'b' + +from org.python.tests.props import PropShadow +b = PropShadow.Derived() +assert b.getBaz() == 4, 'c' +assert b.baz == 4, 'e' +assert b.getFoo() == 3, 'd' +assert b.foo() == 1, 'f' + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-15 06:18:59
|
Revision: 6228 http://jython.svn.sourceforge.net/jython/?rev=6228&view=rev Author: zyasoft Date: 2009-04-15 06:18:52 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Slicing is faster. Modified Paths: -------------- branches/newlist/src/org/python/core/PyList.java Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-15 05:58:59 UTC (rev 6227) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-15 06:18:52 UTC (rev 6228) @@ -130,10 +130,12 @@ if (stop < start) { stop = start; } - if (value instanceof PySequence) { + if (value instanceof PyList) { if (value == this) { // copy value = new PyList((PySequence) value); } + setslicePyList(start, stop, step, (PyList)value); + } else if (value instanceof PySequence) { setsliceIterator(start, stop, step, value.asIterable().iterator()); } else if (value != null && !(value instanceof List)) { //XXX: can we avoid copying here? Needed to pass test_userlist @@ -161,16 +163,14 @@ protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { if(step == 1) { - List<PyObject> copy = new ArrayList<PyObject>(); - copy.addAll(this.list.subList(0, start)); + List<PyObject> insertion = new ArrayList<PyObject>(); if (iter != null) { while (iter.hasNext()) { - copy.add(iter.next()); + insertion.add(iter.next()); } } - copy.addAll(this.list.subList(stop, this.list.size())); - this.list.clear(); - this.list.addAll(copy); + list.subList(start, stop).clear(); + list.addAll(start, insertion); } else { int size = list.size(); for (int j = start; iter.hasNext(); j += step) { @@ -184,6 +184,24 @@ } } + protected void setslicePyList(int start, int stop, int step, PyList other) { + if(step == 1) { + list.subList(start, stop).clear(); + list.addAll(start, other.list); + } else { + int size = list.size(); + Iterator<PyObject> iter = other.listIterator(); + for (int j = start; iter.hasNext(); j += step) { + PyObject item = iter.next(); + if (j >= size) { + list.add(item); + } else { + list.set(j, item); + } + } + } + } + @Override protected PyObject repeat(int count) { if (count < 0) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-15 05:59:10
|
Revision: 6227 http://jython.svn.sourceforge.net/jython/?rev=6227&view=rev Author: zyasoft Date: 2009-04-15 05:58:59 +0000 (Wed, 15 Apr 2009) Log Message: ----------- Reverted to r6222 Modified Paths: -------------- branches/newlist/src/org/python/core/AstList.java branches/newlist/src/org/python/core/PyArray.java branches/newlist/src/org/python/core/PyJavaType.java branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PySequence.java branches/newlist/src/org/python/core/SequenceIndexDelegate.java Modified: branches/newlist/src/org/python/core/AstList.java =================================================================== --- branches/newlist/src/org/python/core/AstList.java 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/src/org/python/core/AstList.java 2009-04-15 05:58:59 UTC (rev 6227) @@ -361,7 +361,7 @@ @ExposedMethod final void astlist_extend(PyObject iterable){ int length = size(); - setslice(length, length, 1, iterable,-1,-1); + setslice(length, length, 1, iterable); } public void extend(PyObject iterable) { @@ -454,7 +454,7 @@ return new AstList(newList); } - protected void setslice(int start, int stop, int step, PyObject value,int sliceLength,int valueLength) { + protected void setslice(int start, int stop, int step, PyObject value) { if(stop < start) { stop = start; } Modified: branches/newlist/src/org/python/core/PyArray.java =================================================================== --- branches/newlist/src/org/python/core/PyArray.java 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/src/org/python/core/PyArray.java 2009-04-15 05:58:59 UTC (rev 6227) @@ -1528,7 +1528,7 @@ * @param step * stepping increment of the slice */ - protected void setslice(int start, int stop, int step, PyObject value,int sliceLength,int valueLength) { + protected void setslice(int start, int stop, int step, PyObject value) { if (stop < start) { stop = start; } Modified: branches/newlist/src/org/python/core/PyJavaType.java =================================================================== --- branches/newlist/src/org/python/core/PyJavaType.java 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/src/org/python/core/PyJavaType.java 2009-04-15 05:58:59 UTC (rev 6227) @@ -877,7 +877,7 @@ } @Override - public void setSlice(int start, int stop, int step, PyObject value, int sliceLength,int valueLength) { + public void setSlice(int start, int stop, int step, PyObject value) { if (stop < start) { stop = start; } Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-15 05:58:59 UTC (rev 6227) @@ -20,7 +20,7 @@ public class PyList extends PySequenceList implements List { public static final PyType TYPE = PyType.fromClass(PyList.class); - protected List<PyObject> list; + protected final List<PyObject> list; public PyList() { this(TYPE); @@ -126,76 +126,21 @@ } @Override - protected void setslice(int start, int stop, int step, PyObject value, int sliceLength, int valueLength) { + protected void setslice(int start, int stop, int step, PyObject value) { if (stop < start) { stop = start; } - int size = list.size(); -// System.err.println("start=" + start + ",stop=" + stop + ",step=" + step + ",sliceLength=" + sliceLength); - - - // optimize copy into: x[:] = ... - if (start == 0 && stop == size && step == 1) { // x[:] = ... - Iterator<PyObject> src; - if (value == this) { - src = ((PyList) value).safeIterator(); - } else if (value instanceof PySequenceList) { - src = ((PySequenceList) value).iterator(); - } else { - src = value.asIterable().iterator(); + if (value instanceof PySequence) { + if (value == this) { // copy + value = new PyList((PySequence) value); } - List<PyObject> copy = new ArrayList<PyObject>(valueLength > 0 ? valueLength : 4); - if (src != null) { - while (src.hasNext()) { - copy.add(src.next()); - } - } - list = copy; - return; - } - - if (value instanceof PyObject) { - Iterator<PyObject> src; - if (value == this) { - PyList valueList = (PyList) value; - if (start == 0 && stop == 0 && step == -1) { // x[::-1] = x - valueList.reverse(); - return; - } - src = ((PyList) value).safeIterator(); - } else if (value instanceof PySequenceList) { - src = ((PySequenceList) value).iterator(); - } else if (value instanceof PySequence) { - src = value.asIterable().iterator(); - } else { - src = new PyList(value).iterator(); - } - - if (sliceLength != -1) { - int srcRange = stop - start; - int destRange = step * sliceLength; - -// System.err.println("start=" + start + ",stop=" + stop + ",step=" + step + -// ",sliceLength=" + sliceLength + ",srcRange=" + srcRange + ",destRange=" + destRange); - - if ((destRange >= srcRange && srcRange > destRange - step)) { - setsliceSimple(start, stop, step, src); - return; - } - } - if (stop == start && step < 0) { - setsliceSimple(start, stop, step, src); - } else { - setsliceIterator(start, stop, src); - } - - } // else if (value != null && !(value instanceof List)) { - // //XXX: can we avoid copying here? Needed to pass test_userlist - // value = new PyList(value); - // setsliceIterator(start, stop, value.asIterable().iterator()); - // } - else { -// System.err.println("List"); + setsliceIterator(start, stop, step, value.asIterable().iterator()); + } else if (value != null && !(value instanceof List)) { + //XXX: can we avoid copying here? Needed to pass test_userlist + value = new PyList(value); + setsliceIterator(start, stop, step, value.asIterable().iterator()); + } else { + System.err.println("List"); List valueList = (List) value.__tojava__(List.class); if (valueList != null && valueList != Py.NoConversion) { setsliceList(start, stop, step, valueList); @@ -203,53 +148,40 @@ } } - private final Iterator<PyObject> safeIterator() { - return new Iterator<PyObject>() { - - private int i = 0; - private final PyObject elements[] = getArray(); - - public boolean hasNext() { - return (i < elements.length); - } - - public PyObject next() { - return elements[i++]; - } - - public void remove() { - throw new UnsupportedOperationException("Immutable"); - } - }; - } - - private final void setsliceSimple(int start, int stop, int step, Iterator<PyObject> src) { - for (int i = start; src.hasNext(); i += step) { - list.set(i, src.next()); + protected void setsliceList(int start, int stop, int step, List value) { + int n = sliceLength(start, stop, step); + if (list instanceof ArrayList) { + ((ArrayList) list).ensureCapacity(start + n); } - } - - // XXX needs to follow below logic for setsliceIterator - private final void setsliceList(int start, int stop, int step, List value) { ListIterator src = value.listIterator(); for (int j = start; src.hasNext(); j += step) { set(j, src.next()); } } - - // XXX need to support prepending via ops like x[:0] = whatever; - // note that step must equal 1 in this case - private final void setsliceIterator(int start, int stop, Iterator<PyObject> iter) { - List<PyObject> copy = new ArrayList<PyObject>(); - copy.addAll(this.list.subList(0, start)); - if (iter != null) { - while (iter.hasNext()) { - copy.add(iter.next()); + protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { + if(step == 1) { + List<PyObject> copy = new ArrayList<PyObject>(); + copy.addAll(this.list.subList(0, start)); + if (iter != null) { + while (iter.hasNext()) { + copy.add(iter.next()); + } } + copy.addAll(this.list.subList(stop, this.list.size())); + this.list.clear(); + this.list.addAll(copy); + } else { + int size = list.size(); + for (int j = start; iter.hasNext(); j += step) { + PyObject item = iter.next(); + if (j >= size) { + list.add(item); + } else { + list.set(j, item); + } + } } - copy.addAll(this.list.subList(stop, this.list.size())); - this.list = copy; } @Override @@ -854,7 +786,7 @@ public boolean equals(Object o) { if (o instanceof PyList) { return (((PyList) o).list.equals(list)); - } else if (o instanceof List) { // XXX copied from PyList, but... + } else if(o instanceof List) { // XXX copied from PyList, but... return o.equals(this); // XXX shouldn't this compare using py2java? } return false; @@ -865,6 +797,7 @@ return list.get(index).__tojava__(Object.class); } + /** @deprecated */ @Override public PyObject[] getArray() { PyObject a[] = new PyObject[list.size()]; @@ -991,27 +924,6 @@ return fromList(newList); } - // NOTE: this attempt would seem faster, but the JVM is better optimized for - // the ArrayList implementation in limited testing - // keeping around for now... -// protected PyObject getslice(int start, int stop, int step) { -// if (step > 0 && stop < start) { -// stop = start; -// } -// int n = sliceLength(start, stop, step); -// PyObject elements[] = new PyObject[n]; -// if (step == 1) { -// ListIterator<PyObject> iter = list.listIterator(start); -// for (int i = 0; i < n; i++) { -// elements[i] = iter.next(); -// } -// } else { -// for (int i = start, j = 0; j < n; i += step, j++) { -// elements[j] = list.get(i); -// } -// } -// return new PyList(elements); -// } @Override public boolean remove(Object o) { return list.remove(Py.java2py(o)); Modified: branches/newlist/src/org/python/core/PySequence.java =================================================================== --- branches/newlist/src/org/python/core/PySequence.java 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/src/org/python/core/PySequence.java 2009-04-15 05:58:59 UTC (rev 6227) @@ -67,7 +67,7 @@ /** * Sets the given range of elements. */ - protected void setslice(int start, int stop, int step, PyObject value,int sliceLength,int valueLength) { + protected void setslice(int start, int stop, int step, PyObject value) { throw Py.TypeError(String.format("'%s' object does not support item assignment", getType().fastGetName())); } @@ -400,8 +400,8 @@ } @Override - public void setSlice(int start, int stop, int step, PyObject value, int sliceLength,int valueLength) { - setslice(start, stop, step, value, sliceLength, valueLength); + public void setSlice(int start, int stop, int step, PyObject value) { + setslice(start, stop, step, value); } @Override Modified: branches/newlist/src/org/python/core/SequenceIndexDelegate.java =================================================================== --- branches/newlist/src/org/python/core/SequenceIndexDelegate.java 2009-04-14 23:00:40 UTC (rev 6226) +++ branches/newlist/src/org/python/core/SequenceIndexDelegate.java 2009-04-15 05:58:59 UTC (rev 6227) @@ -17,7 +17,7 @@ public abstract PyObject getSlice(int start, int stop, int step); - public abstract void setSlice(int start, int stop, int step, PyObject value, int sliceLength, int valueLength); + public abstract void setSlice(int start, int stop, int step, PyObject value); public abstract void delItems(int start, int stop); @@ -35,29 +35,11 @@ public void checkIdxAndSetSlice(PySlice slice, PyObject value) { int[] indices = slice.indicesEx(len()); - final int valueLength; - if (slice.step != Py.None) { - valueLength = value.__len__(); - if (valueLength != indices[3]) { + if ((slice.step != Py.None) && value.__len__() != indices[3]) { throw Py.ValueError(String.format("attempt to assign sequence of size %d to extended " + "slice of size %d", value.__len__(), indices[3])); - } - } else { - valueLength = -1; } - - final int sliceLength; - // this enables PyList to use a simpler implementation to avoid List.add for inserts - if (slice.step == Py.None) { - if (valueLength == indices[3]) { - sliceLength = valueLength; - } else { - sliceLength = -1; - } - } else { - sliceLength = valueLength; - } - setSlice(indices[0], indices[1], indices[2], value, sliceLength, valueLength); + setSlice(indices[0], indices[1], indices[2], value); } public void checkIdxAndSetItem(int idx, PyObject value) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-14 23:00:42
|
Revision: 6226 http://jython.svn.sourceforge.net/jython/?rev=6226&view=rev Author: fwierzbicki Date: 2009-04-14 23:00:40 +0000 (Tue, 14 Apr 2009) Log Message: ----------- Lame shell script to test jython with policy that disallows file writes. Added Paths: ----------- trunk/jython/tests/policy/run.sh Added: trunk/jython/tests/policy/run.sh =================================================================== --- trunk/jython/tests/policy/run.sh (rev 0) +++ trunk/jython/tests/policy/run.sh 2009-04-14 23:00:40 UTC (rev 6226) @@ -0,0 +1 @@ +java -Djava.security.manager -Djava.security.policy=nowrite.policy -classpath ../../dist/jython.jar org.python.util.jython $@ Property changes on: trunk/jython/tests/policy/run.sh ___________________________________________________________________ Added: svn:executable + * This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-14 22:50:52
|
Revision: 6225 http://jython.svn.sourceforge.net/jython/?rev=6225&view=rev Author: fwierzbicki Date: 2009-04-14 22:50:45 +0000 (Tue, 14 Apr 2009) Log Message: ----------- Policy file that disallows writing to the filesystem to test GAE security patch. Added Paths: ----------- trunk/jython/tests/policy/ trunk/jython/tests/policy/nowrite.policy Added: trunk/jython/tests/policy/nowrite.policy =================================================================== --- trunk/jython/tests/policy/nowrite.policy (rev 0) +++ trunk/jython/tests/policy/nowrite.policy 2009-04-14 22:50:45 UTC (rev 6225) @@ -0,0 +1,3 @@ +grant { + permission java.util.PropertyPermission "*", "read"; +}; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <fwi...@us...> - 2009-04-14 21:16:08
|
Revision: 6224 http://jython.svn.sourceforge.net/jython/?rev=6224&view=rev Author: fwierzbicki Date: 2009-04-14 21:16:03 +0000 (Tue, 14 Apr 2009) Log Message: ----------- Applied patch from http://bugs.jython.org/issue1271: Bean property accessors in derived class overide methods in base class. I altered his tests so that they are easily runnable by "ant javatest". Thanks to Geoffrey French for the fix. Also fixed a bad comment in IdentityTest.java. Modified Paths: -------------- trunk/jython/NEWS trunk/jython/src/org/python/core/PyJavaType.java trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java Added Paths: ----------- trunk/jython/tests/python/prop_test.py Modified: trunk/jython/NEWS =================================================================== --- trunk/jython/NEWS 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/NEWS 2009-04-14 21:16:03 UTC (rev 6224) @@ -2,6 +2,7 @@ Jython 2.5.0 rc 1 Bugs fixed (new numbering due to move to Roundup) + - [ 1271 ] Bean property accessors in derived class overide methods in base class - [ 1264 ] 'is not' test exhibits incorrect behaviour when wrapping Java objects - [ 1295 ] Setting a write-only bean property causes a NPE - [ 1272 ] ASTList ClassCastException Modified: trunk/jython/src/org/python/core/PyJavaType.java =================================================================== --- trunk/jython/src/org/python/core/PyJavaType.java 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/src/org/python/core/PyJavaType.java 2009-04-14 21:16:03 UTC (rev 6224) @@ -407,7 +407,8 @@ // If one of our superclasses has something defined for this name, check if its a bean // property, and if so, try to fill in any gaps in our property from there - PyObject superForName = lookup(prop.__name__); + PyObject fromType[] = new PyObject[] { null }; + PyObject superForName = lookup_where(prop.__name__, fromType); if (superForName instanceof PyBeanProperty) { PyBeanProperty superProp = ((PyBeanProperty)superForName); // If it has a set method and we don't, take it regardless. If the types don't line @@ -426,6 +427,12 @@ // If the parent bean is hiding a static field, we need it as well. prop.field = superProp.field; } + } else if (superForName != null && fromType[0] != this && !(superForName instanceof PyBeanEvent)) { + // There is already an entry for this name + // It came from a type which is not @this; it came from a superclass + // It is not a bean event + // Do not override methods defined in superclass + continue; } // If the return types on the set and get methods for a property don't agree, the get // method takes precedence Modified: trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/tests/java/org/python/tests/identity/IdentityTest.java 2009-04-14 21:16:03 UTC (rev 6224) @@ -18,7 +18,6 @@ } public void testReadonly() { - //This used to cause an NPE see http://bugs.jython.org/issue1295 interp.execfile("tests/python/identity_test.py"); } } Modified: trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java =================================================================== --- trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-13 17:12:00 UTC (rev 6223) +++ trunk/jython/tests/java/org/python/tests/props/BeanPropertyTest.java 2009-04-14 21:16:03 UTC (rev 6224) @@ -20,25 +20,8 @@ interp.exec("from org.python.tests.props import Readonly;Readonly().a = 'test'"); } - //This test is for http://bugs.jython.org/issue1271 - public void testBaseProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("a = PropShadow.Derived()"); - interp.exec("assert a.foo() == 1, 'a'"); - interp.exec("assert a.bar() == 2, 'b'"); - */ + public void testShadowing() { + interp.execfile("tests/python/prop_test.py"); } - //This test is for http://bugs.jython.org/issue1271 - public void testDerivedProp() { - /* - interp.exec("from org.python.tests.props import PropShadow"); - interp.exec("b = PropShadow.Derived()"); - interp.exec("assert b.getBaz() == 4, 'c'"); - interp.exec("assert b.getFoo() == 3, 'd'"); - interp.exec("assert b.foo() == 1, 'e'"); - interp.exec("assert b.foo() == 1, 'f'"); - */ - } } Added: trunk/jython/tests/python/prop_test.py =================================================================== --- trunk/jython/tests/python/prop_test.py (rev 0) +++ trunk/jython/tests/python/prop_test.py 2009-04-14 21:16:03 UTC (rev 6224) @@ -0,0 +1,16 @@ +from org.python.tests.identity import IdentityObject + +#This test is for http://bugs.jython.org/issue1271 +from org.python.tests.props import PropShadow + +a = PropShadow.Derived() +assert a.foo() == 1, 'a' +assert a.bar() == 2, 'b' + +from org.python.tests.props import PropShadow +b = PropShadow.Derived() +assert b.getBaz() == 4, 'c' +assert b.baz == 4, 'e' +assert b.getFoo() == 3, 'd' +assert b.foo() == 1, 'f' + This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-13 17:12:04
|
Revision: 6223 http://jython.svn.sourceforge.net/jython/?rev=6223&view=rev Author: zyasoft Date: 2009-04-13 17:12:00 +0000 (Mon, 13 Apr 2009) Log Message: ----------- Changed protocol from SequenceIndexDelegate such that PyList#setslice is ultimately called with the sliceLength and valueLength, or -1 for those fields. This enables access to whether extended slicing was used or not. Modified Paths: -------------- branches/newlist/src/org/python/core/AstList.java branches/newlist/src/org/python/core/PyArray.java branches/newlist/src/org/python/core/PyJavaType.java branches/newlist/src/org/python/core/PyList.java branches/newlist/src/org/python/core/PySequence.java branches/newlist/src/org/python/core/SequenceIndexDelegate.java Modified: branches/newlist/src/org/python/core/AstList.java =================================================================== --- branches/newlist/src/org/python/core/AstList.java 2009-04-12 02:14:00 UTC (rev 6222) +++ branches/newlist/src/org/python/core/AstList.java 2009-04-13 17:12:00 UTC (rev 6223) @@ -361,7 +361,7 @@ @ExposedMethod final void astlist_extend(PyObject iterable){ int length = size(); - setslice(length, length, 1, iterable); + setslice(length, length, 1, iterable,-1,-1); } public void extend(PyObject iterable) { @@ -454,7 +454,7 @@ return new AstList(newList); } - protected void setslice(int start, int stop, int step, PyObject value) { + protected void setslice(int start, int stop, int step, PyObject value,int sliceLength,int valueLength) { if(stop < start) { stop = start; } Modified: branches/newlist/src/org/python/core/PyArray.java =================================================================== --- branches/newlist/src/org/python/core/PyArray.java 2009-04-12 02:14:00 UTC (rev 6222) +++ branches/newlist/src/org/python/core/PyArray.java 2009-04-13 17:12:00 UTC (rev 6223) @@ -1528,7 +1528,7 @@ * @param step * stepping increment of the slice */ - protected void setslice(int start, int stop, int step, PyObject value) { + protected void setslice(int start, int stop, int step, PyObject value,int sliceLength,int valueLength) { if (stop < start) { stop = start; } Modified: branches/newlist/src/org/python/core/PyJavaType.java =================================================================== --- branches/newlist/src/org/python/core/PyJavaType.java 2009-04-12 02:14:00 UTC (rev 6222) +++ branches/newlist/src/org/python/core/PyJavaType.java 2009-04-13 17:12:00 UTC (rev 6223) @@ -877,7 +877,7 @@ } @Override - public void setSlice(int start, int stop, int step, PyObject value) { + public void setSlice(int start, int stop, int step, PyObject value, int sliceLength,int valueLength) { if (stop < start) { stop = start; } Modified: branches/newlist/src/org/python/core/PyList.java =================================================================== --- branches/newlist/src/org/python/core/PyList.java 2009-04-12 02:14:00 UTC (rev 6222) +++ branches/newlist/src/org/python/core/PyList.java 2009-04-13 17:12:00 UTC (rev 6223) @@ -20,7 +20,7 @@ public class PyList extends PySequenceList implements List { public static final PyType TYPE = PyType.fromClass(PyList.class); - protected final List<PyObject> list; + protected List<PyObject> list; public PyList() { this(TYPE); @@ -126,21 +126,76 @@ } @Override - protected void setslice(int start, int stop, int step, PyObject value) { + protected void setslice(int start, int stop, int step, PyObject value, int sliceLength, int valueLength) { if (stop < start) { stop = start; } - if (value instanceof PySequence) { - if (value == this) { // copy - value = new PyList((PySequence) value); + int size = list.size(); +// System.err.println("start=" + start + ",stop=" + stop + ",step=" + step + ",sliceLength=" + sliceLength); + + + // optimize copy into: x[:] = ... + if (start == 0 && stop == size && step == 1) { // x[:] = ... + Iterator<PyObject> src; + if (value == this) { + src = ((PyList) value).safeIterator(); + } else if (value instanceof PySequenceList) { + src = ((PySequenceList) value).iterator(); + } else { + src = value.asIterable().iterator(); } - setsliceIterator(start, stop, step, value.asIterable().iterator()); - } else if (value != null && !(value instanceof List)) { - //XXX: can we avoid copying here? Needed to pass test_userlist - value = new PyList(value); - setsliceIterator(start, stop, step, value.asIterable().iterator()); - } else { - System.err.println("List"); + List<PyObject> copy = new ArrayList<PyObject>(valueLength > 0 ? valueLength : 4); + if (src != null) { + while (src.hasNext()) { + copy.add(src.next()); + } + } + list = copy; + return; + } + + if (value instanceof PyObject) { + Iterator<PyObject> src; + if (value == this) { + PyList valueList = (PyList) value; + if (start == 0 && stop == 0 && step == -1) { // x[::-1] = x + valueList.reverse(); + return; + } + src = ((PyList) value).safeIterator(); + } else if (value instanceof PySequenceList) { + src = ((PySequenceList) value).iterator(); + } else if (value instanceof PySequence) { + src = value.asIterable().iterator(); + } else { + src = new PyList(value).iterator(); + } + + if (sliceLength != -1) { + int srcRange = stop - start; + int destRange = step * sliceLength; + +// System.err.println("start=" + start + ",stop=" + stop + ",step=" + step + +// ",sliceLength=" + sliceLength + ",srcRange=" + srcRange + ",destRange=" + destRange); + + if ((destRange >= srcRange && srcRange > destRange - step)) { + setsliceSimple(start, stop, step, src); + return; + } + } + if (stop == start && step < 0) { + setsliceSimple(start, stop, step, src); + } else { + setsliceIterator(start, stop, src); + } + + } // else if (value != null && !(value instanceof List)) { + // //XXX: can we avoid copying here? Needed to pass test_userlist + // value = new PyList(value); + // setsliceIterator(start, stop, value.asIterable().iterator()); + // } + else { +// System.err.println("List"); List valueList = (List) value.__tojava__(List.class); if (valueList != null && valueList != Py.NoConversion) { setsliceList(start, stop, step, valueList); @@ -148,40 +203,53 @@ } } - protected void setsliceList(int start, int stop, int step, List value) { - int n = sliceLength(start, stop, step); - if (list instanceof ArrayList) { - ((ArrayList) list).ensureCapacity(start + n); + private final Iterator<PyObject> safeIterator() { + return new Iterator<PyObject>() { + + private int i = 0; + private final PyObject elements[] = getArray(); + + public boolean hasNext() { + return (i < elements.length); + } + + public PyObject next() { + return elements[i++]; + } + + public void remove() { + throw new UnsupportedOperationException("Immutable"); + } + }; + } + + private final void setsliceSimple(int start, int stop, int step, Iterator<PyObject> src) { + for (int i = start; src.hasNext(); i += step) { + list.set(i, src.next()); } + } + + // XXX needs to follow below logic for setsliceIterator + private final void setsliceList(int start, int stop, int step, List value) { ListIterator src = value.listIterator(); for (int j = start; src.hasNext(); j += step) { set(j, src.next()); } } - protected void setsliceIterator(int start, int stop, int step, Iterator<PyObject> iter) { - if(step == 1) { - List<PyObject> copy = new ArrayList<PyObject>(); - copy.addAll(this.list.subList(0, start)); - if (iter != null) { - while (iter.hasNext()) { - copy.add(iter.next()); - } + + // XXX need to support prepending via ops like x[:0] = whatever; + // note that step must equal 1 in this case + private final void setsliceIterator(int start, int stop, Iterator<PyObject> iter) { + List<PyObject> copy = new ArrayList<PyObject>(); + copy.addAll(this.list.subList(0, start)); + if (iter != null) { + while (iter.hasNext()) { + copy.add(iter.next()); } - copy.addAll(this.list.subList(stop, this.list.size())); - this.list.clear(); - this.list.addAll(copy); - } else { - int size = list.size(); - for (int j = start; iter.hasNext(); j += step) { - PyObject item = iter.next(); - if (j >= size) { - list.add(item); - } else { - list.set(j, item); - } - } } + copy.addAll(this.list.subList(stop, this.list.size())); + this.list = copy; } @Override @@ -786,7 +854,7 @@ public boolean equals(Object o) { if (o instanceof PyList) { return (((PyList) o).list.equals(list)); - } else if(o instanceof List) { // XXX copied from PyList, but... + } else if (o instanceof List) { // XXX copied from PyList, but... return o.equals(this); // XXX shouldn't this compare using py2java? } return false; @@ -797,7 +865,6 @@ return list.get(index).__tojava__(Object.class); } - /** @deprecated */ @Override public PyObject[] getArray() { PyObject a[] = new PyObject[list.size()]; @@ -924,6 +991,27 @@ return fromList(newList); } + // NOTE: this attempt would seem faster, but the JVM is better optimized for + // the ArrayList implementation in limited testing + // keeping around for now... +// protected PyObject getslice(int start, int stop, int step) { +// if (step > 0 && stop < start) { +// stop = start; +// } +// int n = sliceLength(start, stop, step); +// PyObject elements[] = new PyObject[n]; +// if (step == 1) { +// ListIterator<PyObject> iter = list.listIterator(start); +// for (int i = 0; i < n; i++) { +// elements[i] = iter.next(); +// } +// } else { +// for (int i = start, j = 0; j < n; i += step, j++) { +// elements[j] = list.get(i); +// } +// } +// return new PyList(elements); +// } @Override public boolean remove(Object o) { return list.remove(Py.java2py(o)); Modified: branches/newlist/src/org/python/core/PySequence.java =================================================================== --- branches/newlist/src/org/python/core/PySequence.java 2009-04-12 02:14:00 UTC (rev 6222) +++ branches/newlist/src/org/python/core/PySequence.java 2009-04-13 17:12:00 UTC (rev 6223) @@ -67,7 +67,7 @@ /** * Sets the given range of elements. */ - protected void setslice(int start, int stop, int step, PyObject value) { + protected void setslice(int start, int stop, int step, PyObject value,int sliceLength,int valueLength) { throw Py.TypeError(String.format("'%s' object does not support item assignment", getType().fastGetName())); } @@ -400,8 +400,8 @@ } @Override - public void setSlice(int start, int stop, int step, PyObject value) { - setslice(start, stop, step, value); + public void setSlice(int start, int stop, int step, PyObject value, int sliceLength,int valueLength) { + setslice(start, stop, step, value, sliceLength, valueLength); } @Override Modified: branches/newlist/src/org/python/core/SequenceIndexDelegate.java =================================================================== --- branches/newlist/src/org/python/core/SequenceIndexDelegate.java 2009-04-12 02:14:00 UTC (rev 6222) +++ branches/newlist/src/org/python/core/SequenceIndexDelegate.java 2009-04-13 17:12:00 UTC (rev 6223) @@ -17,7 +17,7 @@ public abstract PyObject getSlice(int start, int stop, int step); - public abstract void setSlice(int start, int stop, int step, PyObject value); + public abstract void setSlice(int start, int stop, int step, PyObject value, int sliceLength, int valueLength); public abstract void delItems(int start, int stop); @@ -35,11 +35,29 @@ public void checkIdxAndSetSlice(PySlice slice, PyObject value) { int[] indices = slice.indicesEx(len()); - if ((slice.step != Py.None) && value.__len__() != indices[3]) { + final int valueLength; + if (slice.step != Py.None) { + valueLength = value.__len__(); + if (valueLength != indices[3]) { throw Py.ValueError(String.format("attempt to assign sequence of size %d to extended " + "slice of size %d", value.__len__(), indices[3])); + } + } else { + valueLength = -1; } - setSlice(indices[0], indices[1], indices[2], value); + + final int sliceLength; + // this enables PyList to use a simpler implementation to avoid List.add for inserts + if (slice.step == Py.None) { + if (valueLength == indices[3]) { + sliceLength = valueLength; + } else { + sliceLength = -1; + } + } else { + sliceLength = valueLength; + } + setSlice(indices[0], indices[1], indices[2], value, sliceLength, valueLength); } public void checkIdxAndSetItem(int idx, PyObject value) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <zy...@us...> - 2009-04-12 02:14:01
|
Revision: 6222 http://jython.svn.sourceforge.net/jython/?rev=6222&view=rev Author: zyasoft Date: 2009-04-12 02:14:00 +0000 (Sun, 12 Apr 2009) Log Message: ----------- Fixed bulk List ops on PyTuple - actual usage doesn't expect that elements are converted to/from Python proxies. Modified Paths: -------------- branches/newlist/src/org/python/core/PyTuple.java Modified: branches/newlist/src/org/python/core/PyTuple.java =================================================================== --- branches/newlist/src/org/python/core/PyTuple.java 2009-04-12 00:21:44 UTC (rev 6221) +++ branches/newlist/src/org/python/core/PyTuple.java 2009-04-12 02:14:00 UTC (rev 6222) @@ -447,23 +447,12 @@ @Override public boolean contains(Object o) { - PyObject converted = Py.java2py(o); - for (int i = 0; i < array.length; i++) { - if (array[i].equals(converted)) { - return true; - } - } - return false; + return getList().contains(o); } @Override public boolean containsAll(Collection c) { - if (c instanceof PySequenceList) { - return getList().containsAll(c); - } else { - //XXX: FJW this seems unnecessary. - return getList().containsAll(new PyList(c)); - } + return getList().containsAll(c); } @Override @@ -488,13 +477,7 @@ @Override public int indexOf(Object o) { - PyObject converted = Py.java2py(o); - for (int i = 0; i < array.length; i++) { - if (array[i].equals(converted)) { - return i; - } - } - return -1; + return getList().indexOf(o); } @Override @@ -504,24 +487,17 @@ @Override public int lastIndexOf(Object o) { - PyObject converted = Py.java2py(o); - int lastIndex = -1; - for (int i = 0; i < array.length; i++) { - if (array[i].equals(converted)) { - lastIndex = i; - } - } - return lastIndex; + return getList().lastIndexOf(o); } @Override public void pyadd(int index, PyObject element) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException(); } @Override public boolean pyadd(PyObject o) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException(); } @Override @@ -531,7 +507,7 @@ @Override public void remove(int start, int stop) { - throw new UnsupportedOperationException("Not supported yet."); + throw new UnsupportedOperationException(); } @Override This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-12 00:21:57
|
Revision: 6221 http://jython.svn.sourceforge.net/jython/?rev=6221&view=rev Author: pjenvey Date: 2009-04-12 00:21:44 +0000 (Sun, 12 Apr 2009) Log Message: ----------- restore the original encoding of SyntaxError text Modified Paths: -------------- trunk/jython/src/org/python/core/ParserFacade.java Modified: trunk/jython/src/org/python/core/ParserFacade.java =================================================================== --- trunk/jython/src/org/python/core/ParserFacade.java 2009-04-11 21:27:36 UTC (rev 6220) +++ trunk/jython/src/org/python/core/ParserFacade.java 2009-04-12 00:21:44 UTC (rev 6221) @@ -44,7 +44,7 @@ private ParserFacade() {} - private static String getLine(BufferedReader reader, int line) { + private static String getLine(ExpectedEncodingBufferedReader reader, int line) { if (reader == null) { return ""; } @@ -53,7 +53,14 @@ for (int i = 0; i < line; i++) { text = reader.readLine(); } - return text == null ? text : text + "\n"; + if (text == null) { + return text; + } + if (reader.encoding != null) { + // restore the original encoding + text = new PyUnicode(text).encode(reader.encoding); + } + return text + "\n"; } catch (IOException ioe) { } return text; @@ -80,7 +87,7 @@ line = node.getLine(); col = node.getCharPositionInLine(); } - String text=getLine(reader, line); + String text= getLine(reader, line); String msg = e.getMessage(); if (e.getType() == Py.IndentationError) { return new PyIndentationError(msg, line, col, text, filename); This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-11 21:27:38
|
Revision: 6220 http://jython.svn.sourceforge.net/jython/?rev=6220&view=rev Author: pjenvey Date: 2009-04-11 21:27:36 +0000 (Sat, 11 Apr 2009) Log Message: ----------- encode unicode printed to file objects per the file's encoding Modified Paths: -------------- trunk/jython/src/org/python/core/StdoutWrapper.java Modified: trunk/jython/src/org/python/core/StdoutWrapper.java =================================================================== --- trunk/jython/src/org/python/core/StdoutWrapper.java 2009-04-11 20:49:13 UTC (rev 6219) +++ trunk/jython/src/org/python/core/StdoutWrapper.java 2009-04-11 21:27:36 UTC (rev 6220) @@ -105,8 +105,14 @@ file.write(" "); file.softspace = false; } - PyString string = o.__str__(); - String s = string.toString(); + + String s; + if (o instanceof PyUnicode && file.encoding != null) { + s = ((PyUnicode)o).encode(file.encoding, "strict"); + } else { + s = o.__str__().toString(); + } + int len = s.length(); file.write(s); if (o instanceof PyString) { This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <pj...@us...> - 2009-04-11 20:49:25
|
Revision: 6219 http://jython.svn.sourceforge.net/jython/?rev=6219&view=rev Author: pjenvey Date: 2009-04-11 20:49:13 +0000 (Sat, 11 Apr 2009) Log Message: ----------- cleanup Modified Paths: -------------- trunk/jython/Lib/os.py Modified: trunk/jython/Lib/os.py =================================================================== --- trunk/jython/Lib/os.py 2009-04-11 18:26:24 UTC (rev 6218) +++ trunk/jython/Lib/os.py 2009-04-11 20:49:13 UTC (rev 6219) @@ -1080,7 +1080,6 @@ return _posix.isatty(fileno) if not isinstance(fileno, IOBase): - print fileno raise TypeError('a file descriptor is required') return fileno.isatty() This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |
From: <am...@us...> - 2009-04-11 18:26:28
|
Revision: 6218 http://jython.svn.sourceforge.net/jython/?rev=6218&view=rev Author: amak Date: 2009-04-11 18:26:24 +0000 (Sat, 11 Apr 2009) Log Message: ----------- Adding a readme.txt so that the WEB-INF/lib directory doesn't end getting omitted up by the installer. Added Paths: ----------- trunk/jython/Demo/modjy_webapp/WEB-INF/lib/readme.txt Added: trunk/jython/Demo/modjy_webapp/WEB-INF/lib/readme.txt =================================================================== --- trunk/jython/Demo/modjy_webapp/WEB-INF/lib/readme.txt (rev 0) +++ trunk/jython/Demo/modjy_webapp/WEB-INF/lib/readme.txt 2009-04-11 18:26:24 UTC (rev 6218) @@ -0,0 +1 @@ +The jython.jar file should be placed in this directory. This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |