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. |