From jython-checkins at python.org Sun Jan 3 20:47:56 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Mon, 04 Jan 2016 01:47:56 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Add_sys=2Egetsizeof_by_inte?= =?utf-8?q?rtally_using_java-size=2Ejar_extlib_=28Apache2_license=29=2C?= Message-ID: <20160104014756.126299.68178@psf.io> https://hg.python.org/jython/rev/c01bab7025e4 changeset: 7846:c01bab7025e4 user: Darjus Loktevic date: Mon Jan 04 12:47:40 2016 +1100 summary: Add sys.getsizeof by intertally using java-size.jar extlib (Apache2 license), and add gc.get_objects by returning the monitoredObjects list (not quite CPython behaviour but close) to support muppy #2450 files: Lib/test/test_support.py | 2 +- Lib/test/test_sys.py | 76 ++++++++++++- build.xml | 2 + extlibs/java-sizeof-0.0.5.jar | Bin src/org/python/core/PySystemState.java | 11 +- src/org/python/modules/gc.java | 23 ++- 6 files changed, 104 insertions(+), 10 deletions(-) diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -1000,7 +1000,7 @@ gc.collect() -_header = '2P' +_header = '1P' if hasattr(sys, "gettotalrefcount"): _header = '2P' + _header _vheader = _header + 'P' diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1,6 +1,8 @@ # -*- coding: iso-8859-1 -*- import unittest, test.test_support import sys, cStringIO +import struct + class SysModuleTest(unittest.TestCase): @@ -273,12 +275,84 @@ self.assertEqual(out, '?') +class SizeofTest(unittest.TestCase): + """Jython modified version of getsizeof""" + + def setUp(self): + self.P = struct.calcsize('P') + self.longdigit = sys.long_info.sizeof_digit + self.file = open(test.test_support.TESTFN, 'wb') + + def tearDown(self): + self.file.close() + test.test_support.unlink(test.test_support.TESTFN) + + check_sizeof = test.test_support.check_sizeof + + def test_default(self): + size = test.test_support.calcobjsize + self.assertEqual(sys.getsizeof(True, -1), size('l')) + + def test_objecttypes(self): + # check all types defined in Objects/ + size = test.test_support.calcobjsize + vsize = test.test_support.calcvobjsize + check = self.check_sizeof + # bool + check(True, size('l')) + # buffer + with test.test_support.check_py3k_warnings(): + check(buffer(''), size('1P2Pil')) + # builtin_function_or_method + check(len, size('3P')) + # bytearray_iterator + check(iter(bytearray()), size('2PP')) + # cell + def get_cell(): + x = 42 + def inner(): + return x + return inner + check(get_cell().func_closure[0], size('2P')) + # classobj (old-style class) + class class_oldstyle(): + def method(): + pass + check(class_oldstyle, size('6P')) + # instance (old-style class) + check(class_oldstyle(), size('3P')) + # instancemethod (old-style class) + check(class_oldstyle().method, size('3P')) + # complex + check(complex(0,1), size('2P2d')) + # code + check(get_cell().func_code, size('4i3Pi3P')) + # BaseException + check(BaseException(), size('3P')) + + def test_pythontypes(self): + # check all types defined in Python/ + size = test.test_support.calcobjsize + vsize = test.test_support.calcvobjsize + check = self.check_sizeof + # imp.NullImporter + import imp + check(imp.NullImporter(self.file.name), size('3P')) + try: + raise TypeError + except TypeError: + tb = sys.exc_info()[2] + # traceback + if tb != None: + check(tb, size('2P2i')) + + def test_main(): if test.test_support.is_jython: del SysModuleTest.test_lost_displayhook del SysModuleTest.test_refcount del SysModuleTest.test_setcheckinterval - test.test_support.run_unittest(SysModuleTest) + test.test_support.run_unittest(SysModuleTest, SizeofTest) if __name__ == "__main__": test_main() diff --git a/build.xml b/build.xml --- a/build.xml +++ b/build.xml @@ -155,6 +155,7 @@ + @@ -604,6 +605,7 @@ + diff --git a/extlibs/java-sizeof-0.0.5.jar b/extlibs/java-sizeof-0.0.5.jar new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..23c555cc17af37962ea51431caf3755b1e85fb20 GIT binary patch [stripped] diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java --- a/src/org/python/core/PySystemState.java +++ b/src/org/python/core/PySystemState.java @@ -31,8 +31,8 @@ import java.util.concurrent.locks.ReentrantLock; import java.util.jar.JarEntry; import java.util.jar.JarFile; - import jnr.posix.util.Platform; +import com.carrotsearch.sizeof.RamUsageEstimator; import org.python.Version; import org.python.core.adapter.ClassicPyObjectAdapter; @@ -432,6 +432,15 @@ return recursionlimit; } + @SuppressWarnings("unused") + public long getsizeof(Object obj, long defaultVal) { + return getsizeof(obj); + } + + public long getsizeof(Object obj) { + return RamUsageEstimator.shallowSizeOf(obj); + } + public void setrecursionlimit(int recursionlimit) { if (recursionlimit <= 0) { throw Py.ValueError("Recursion limit must be positive"); diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java --- a/src/org/python/modules/gc.java +++ b/src/org/python/modules/gc.java @@ -1,10 +1,6 @@ package org.python.modules; -import java.util.Set; -import java.util.List; -import java.util.ArrayList; -import java.util.IdentityHashMap; -import java.util.HashSet; +import java.util.*; import java.util.concurrent.atomic.AtomicBoolean; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; @@ -2558,13 +2554,26 @@ } /** - * Not supported by Jython. + * Only works reliably if {@code monitorGlobal} is active, as it depends on + * monitored objects to search for referrers. It only finds referrers that + * properly implement the traverseproc mechanism (unless reflection-based + * traversion is activated and works stable). * Throws {@link org.python.core.Py#NotImplementedError}. * * @throws org.python.core.Py.NotImplementedError */ public static PyObject get_objects() { - throw Py.NotImplementedError("not applicable to Java GC"); + if (!isMonitoring()) { + throw Py.NotImplementedError( + "not applicable in Jython if gc module is not monitoring PyObjects"); + } + LinkedList resultList = new LinkedList<>(); + synchronized (monitoredObjects) { + for (WeakReferenceGC src: monitoredObjects) { + resultList.add((PyObject) src.get()); + } + } + return new PyList(resultList); } /** -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sun Jan 3 23:26:16 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Mon, 04 Jan 2016 04:26:16 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Unwildcard_java=2Eutil_in_g?= =?utf-8?q?c=2Ejava=2C_update_ACKNOWLEDGEMENTS_with_Java_sizeof=2C_and?= Message-ID: <20160104042616.9624.99947@psf.io> https://hg.python.org/jython/rev/97f078a1e6fb changeset: 7847:97f078a1e6fb user: Darjus Loktevic date: Mon Jan 04 15:17:31 2016 +1100 summary: Unwildcard java.util in gc.java, update ACKNOWLEDGEMENTS with Java sizeof, and make sure we shadow the java sizeof in jarjar files: ACKNOWLEDGMENTS | 1 + build.xml | 7 ++++--- src/org/python/modules/gc.java | 7 ++++++- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS --- a/ACKNOWLEDGMENTS +++ b/ACKNOWLEDGMENTS @@ -35,6 +35,7 @@ * Mock Runner, licensed under the Apache 1.1 license * Netty 4, licensed under the Apache 2.0 license from the Netty project * PyPy datetime module, licensed under the MIT License from the PyPy project +* Java sizeof, licensed under the Apache 2.0 License from the Apache Software Foundation Jython follows closely the Python language and its reference implementation CPython, as created by Guido van Rossum. diff --git a/build.xml b/build.xml --- a/build.xml +++ b/build.xml @@ -583,8 +583,10 @@ - + + + @@ -605,7 +607,6 @@ - diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java --- a/src/org/python/modules/gc.java +++ b/src/org/python/modules/gc.java @@ -1,6 +1,11 @@ package org.python.modules; -import java.util.*; +import java.util.Set; +import java.util.List; +import java.util.LinkedList; +import java.util.ArrayList; +import java.util.IdentityHashMap; +import java.util.HashSet; import java.util.concurrent.atomic.AtomicBoolean; import java.lang.ref.Reference; import java.lang.ref.ReferenceQueue; -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Mon Jan 4 17:06:50 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Mon, 04 Jan 2016 22:06:50 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Use_ArrayList_in_gc=2Eget?= =?utf-8?q?=5Fobjects=28=29_and_test_if_the_object_is_null_before_adding?= Message-ID: <20160104220650.21237.48194@psf.io> https://hg.python.org/jython/rev/c085ec851271 changeset: 7848:c085ec851271 user: Darjus Loktevic date: Tue Jan 05 09:06:44 2016 +1100 summary: Use ArrayList in gc.get_objects() and test if the object is null before adding it to the results files: src/org/python/modules/gc.java | 8 +++++--- 1 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java --- a/src/org/python/modules/gc.java +++ b/src/org/python/modules/gc.java @@ -2,7 +2,6 @@ import java.util.Set; import java.util.List; -import java.util.LinkedList; import java.util.ArrayList; import java.util.IdentityHashMap; import java.util.HashSet; @@ -2572,10 +2571,13 @@ throw Py.NotImplementedError( "not applicable in Jython if gc module is not monitoring PyObjects"); } - LinkedList resultList = new LinkedList<>(); + ArrayList resultList = new ArrayList<>(); synchronized (monitoredObjects) { for (WeakReferenceGC src: monitoredObjects) { - resultList.add((PyObject) src.get()); + PyObject obj = src.get(); + if (obj != null) { + resultList.add(obj); + } } } return new PyList(resultList); -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Mon Jan 4 20:18:34 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 05 Jan 2016 01:18:34 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Use_isTraversable_for_gc=2E?= =?utf-8?q?get=5Fobjects=28=29_and_give_a_hint_about_array_size?= Message-ID: <20160105010616.30374.4666@psf.io> https://hg.python.org/jython/rev/7f3675835a99 changeset: 7849:7f3675835a99 user: Darjus Loktevic date: Tue Jan 05 12:06:07 2016 +1100 summary: Use isTraversable for gc.get_objects() and give a hint about array size files: src/org/python/modules/gc.java | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java --- a/src/org/python/modules/gc.java +++ b/src/org/python/modules/gc.java @@ -2571,11 +2571,11 @@ throw Py.NotImplementedError( "not applicable in Jython if gc module is not monitoring PyObjects"); } - ArrayList resultList = new ArrayList<>(); + ArrayList resultList = new ArrayList<>(monitoredObjects.size()); synchronized (monitoredObjects) { for (WeakReferenceGC src: monitoredObjects) { PyObject obj = src.get(); - if (obj != null) { + if (isTraversable(obj)) { resultList.add(obj); } } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Mon Jan 4 21:40:08 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 05 Jan 2016 02:40:08 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Trim_the_list_in_gc=2Eget?= =?utf-8?q?=5Fobjects=28=29_as_the_hinted_size_may_be_wasteful?= Message-ID: <20160105024008.9642.99213@psf.io> https://hg.python.org/jython/rev/cbd991011dd5 changeset: 7850:cbd991011dd5 user: Darjus Loktevic date: Tue Jan 05 13:40:00 2016 +1100 summary: Trim the list in gc.get_objects() as the hinted size may be wasteful files: src/org/python/modules/gc.java | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/src/org/python/modules/gc.java b/src/org/python/modules/gc.java --- a/src/org/python/modules/gc.java +++ b/src/org/python/modules/gc.java @@ -2580,6 +2580,7 @@ } } } + resultList.trimToSize(); return new PyList(resultList); } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 6 16:42:26 2016 From: jython-checkins at python.org (jim.baker) Date: Wed, 06 Jan 2016 21:42:26 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Various_fixes_for_working_w?= =?utf-8?q?ith_array=2Earray_objects=2E_Fixes_=231780=2C_=232423=2C_=23245?= =?utf-8?q?1?= Message-ID: <20160106214225.17321.69270@psf.io> https://hg.python.org/jython/rev/49d498968f34 changeset: 7851:49d498968f34 user: Jim Baker date: Wed Jan 06 14:42:21 2016 -0700 summary: Various fixes for working with array.array objects. Fixes #1780, #2423, #2451 Now supports for array.array/jarray.array objects: * Boxes primitive arrays when converting to Object[] * Usage in varargs position * Raises TypeError if attempt to hash files: ACKNOWLEDGMENTS | 2 + Lib/test/test_array_jy.py | 84 +++++++++++-- src/org/python/core/PyArray.java | 26 ++++- src/org/python/core/ReflectedArgs.java | 44 ++++-- 4 files changed, 125 insertions(+), 31 deletions(-) diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS --- a/ACKNOWLEDGMENTS +++ b/ACKNOWLEDGMENTS @@ -170,6 +170,8 @@ Stephen Drake Jan Vorwerk Eli Oxman + Robert Patrick + Kevin Edwards Local Variables: mode: indented-text diff --git a/Lib/test/test_array_jy.py b/Lib/test/test_array_jy.py --- a/Lib/test/test_array_jy.py +++ b/Lib/test/test_array_jy.py @@ -1,28 +1,40 @@ -# The jarray module is being phased out, with all functionality -# now available in the array module. -from __future__ import with_statement +# The jarray module is mostly phased out, but it is still has one +# constructor function - zeros - that is not directly available in the +# array module. +# +# The equivalent of +# jarray.zeros(n, typecode) +# is +# array.array(typecode, itertools.repeat(0, n)) +# +# however itertools.repeat does not define __len__ and therefore we +# have to first build out the zero sequence separately, then copy +# over. This overhead could be significant for large arrays. + +import jarray +import itertools import os import unittest +from array import array from test import test_support -from array import array +from java.lang import String as JString +from java.util import Arrays + class ArrayJyTestCase(unittest.TestCase): - def test_jarray(self): # until it is fully formally removed - # While jarray is still being phased out, just flex the initializers. - # The rest of the test for array will catch all the big problems. - import jarray + def test_jarray(self): from java.lang import String - jarray.array(range(5), 'i') - jarray.array([String("a"), String("b"), String("c")], String) - jarray.zeros(5, 'i') - jarray.zeros(5, String) + + self.assertEqual(sum(jarray.array(range(5), 'i')), 10) + self.assertEqual(','.join(jarray.array([String("a"), String("b"), String("c")], String)), u'a,b,c') + self.assertEqual(sum(jarray.zeros(5, 'i')), 0) + self.assertEqual([x for x in jarray.zeros(5, String)], [None, None, None, None, None]) def test_java_object_arrays(self): from array import zeros from java.lang import String from java.lang.reflect import Array - from java.util import Arrays jStringArr = array(String, [String("a"), String("b"), String("c")]) self.assert_( Arrays.equals(jStringArr.typecode, 'java.lang.String'), @@ -91,9 +103,53 @@ ar += Foo() self.assertEqual('__radd__', ar) + def test_nonhashability(self): + "array.array objects are not hashable" + # http://bugs.jython.org/issue2451 + a = array('b', itertools.repeat(0, 100)) + with self.assertRaisesRegexp(TypeError, r"unhashable type: 'array.array'"): + hash(a) + + +class ArrayConversionTestCase(unittest.TestCase): + + # Covers bugs raised in + # http://bugs.jython.org/issue1780, + # http://bugs.jython.org/issue2423 + + def assertAsList(self, a, b): + self.assertEqual(Arrays.asList(a), b) + + def test_boxing_conversion(self): + "array objects support boxing, as they did in Jython 2.1" + from java.lang import Integer + + self.assertAsList(jarray.array([1, 2, 3, 4, 5], Integer), [1, 2, 3, 4, 5]) + self.assertAsList(array(Integer, [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) + self.assertAsList(jarray.array([1, 2, 3, 4, 5], "i"), [1, 2, 3, 4, 5]) + self.assertAsList(array("i", [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) + + def test_object_varargs(self): + "array.array objects can be used in the varargs position, with primitive boxing" + a = array('i', range(5, 10)) + self.assertEqual( + 'arg 0=5, arg 1=6, arg 2=7, arg 3=8, arg 4=9', + JString.format('arg 0=%d, arg 1=%d, arg 2=%d, arg 3=%d, arg 4=%d', [5, 6, 7, 8, 9])) + + def test_assignable_varargs(self): + "array.array objects can be used in the varargs position" + # modified from test case in http://bugs.jython.org/issue2423; + from java.lang import Class + from java.net import URL, URLClassLoader + params = jarray.array([URL], Class) + # URLClassLoader.addURL is protected, so workaround via reflection + method = URLClassLoader.getDeclaredMethod('addURL', params) + # and verify we got the right method after all + self.assertEqual(method.name, "addURL") + def test_main(): - tests = [ToFromfileTestCase, ArrayOpsTestCase] + tests = [ToFromfileTestCase, ArrayOpsTestCase, ArrayConversionTestCase] if test_support.is_jython: tests.extend([ArrayJyTestCase]) test_support.run_unittest(*tests) diff --git a/src/org/python/core/PyArray.java b/src/org/python/core/PyArray.java --- a/src/org/python/core/PyArray.java +++ b/src/org/python/core/PyArray.java @@ -209,6 +209,16 @@ return seq___eq__(o); } + @Override + public int hashCode() { + return array___hash__(); + } + + @ExposedMethod + final int array___hash__() { + throw Py.TypeError(String.format("unhashable type: '%.200s'", getType().fastGetName())); + } + @ExposedMethod(type = MethodType.BINARY) final PyObject array___lt__(PyObject o) { return seq___lt__(o); @@ -450,7 +460,10 @@ */ @Override public Object __tojava__(Class c) { - if (c == Object.class || (c.isArray() && c.getComponentType().isAssignableFrom(type))) { + boolean isArray = c.isArray(); + Class componentType = c.getComponentType(); + + if (c == Object.class || (isArray && componentType.isAssignableFrom(type))) { if (delegate.capacity != delegate.size) { // when unboxing, need to shrink the array first, otherwise incorrect // results to Java @@ -459,9 +472,20 @@ return data; } } + + // rebox: this array is made of primitives but converting to Object[] + if (isArray && componentType == Object.class) { + Object[] boxed = new Object[delegate.size]; + for (int i = 0; i < delegate.size; i++) { + boxed[i] = Array.get(data, i); + } + return boxed; + } + if (c.isInstance(this)) { return this; } + return Py.NoConversion; } diff --git a/src/org/python/core/ReflectedArgs.java b/src/org/python/core/ReflectedArgs.java --- a/src/org/python/core/ReflectedArgs.java +++ b/src/org/python/core/ReflectedArgs.java @@ -111,22 +111,7 @@ // if that's what they need to do ;) if (isVarArgs) { - if (pyArgs.length == 0 || !(pyArgs[pyArgs.length - 1] instanceof PySequenceList)) { - int non_varargs_len = n - 1; - if (pyArgs.length >= non_varargs_len) { - PyObject[] boxedPyArgs = new PyObject[n]; - for (int i = 0; i < non_varargs_len; i++) { - boxedPyArgs[i] = pyArgs[i]; - } - int varargs_len = pyArgs.length - non_varargs_len; - PyObject[] varargs = new PyObject[varargs_len]; - for (int i = 0; i < varargs_len; i++) { - varargs[i] = pyArgs[non_varargs_len + i]; - } - boxedPyArgs[non_varargs_len] = new PyList(varargs); - pyArgs = boxedPyArgs; - } - } + pyArgs = ensureBoxedVarargs(pyArgs, n); } if (pyArgs.length != n) { @@ -164,6 +149,33 @@ return true; } + /* Boxes argument in the varargs position if not already boxed */ + private PyObject[] ensureBoxedVarargs(PyObject[] pyArgs, int n) { + if (pyArgs.length == 0) { + return pyArgs; + } + PyObject lastArg = pyArgs[pyArgs.length - 1]; + if (lastArg instanceof PySequenceList || lastArg instanceof PyArray) { + // FIXME also check if lastArg is sequence-like + return pyArgs; // will be boxed in an array once __tojava__ is called + } + int non_varargs_len = n - 1; + if (pyArgs.length < non_varargs_len) { + return pyArgs; + } + PyObject[] boxedPyArgs = new PyObject[n]; + for (int i = 0; i < non_varargs_len; i++) { + boxedPyArgs[i] = pyArgs[i]; + } + int varargs_len = pyArgs.length - non_varargs_len; + PyObject[] varargs = new PyObject[varargs_len]; + for (int i = 0; i < varargs_len; i++) { + varargs[i] = pyArgs[non_varargs_len + i]; + } + boxedPyArgs[non_varargs_len] = new PyList(varargs); + return boxedPyArgs; + } + public static int precedence(Class arg) { if (arg == Object.class) { return 3000; -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 6 17:23:21 2016 From: jython-checkins at python.org (jim.baker) Date: Wed, 06 Jan 2016 22:23:21 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Verify_compaction_of_array?= =?utf-8?q?=2Earray_occurs_when_converting_to_Object_=28=231745=29?= Message-ID: <20160106222319.30362.87045@psf.io> https://hg.python.org/jython/rev/837c14575b65 changeset: 7852:837c14575b65 user: Jim Baker date: Wed Jan 06 15:23:16 2016 -0700 summary: Verify compaction of array.array occurs when converting to Object (#1745) files: tests/java/org/python/core/PyArrayTest.java | 13 ++++++++++ 1 files changed, 13 insertions(+), 0 deletions(-) diff --git a/tests/java/org/python/core/PyArrayTest.java b/tests/java/org/python/core/PyArrayTest.java --- a/tests/java/org/python/core/PyArrayTest.java +++ b/tests/java/org/python/core/PyArrayTest.java @@ -1,6 +1,7 @@ package org.python.core; import junit.framework.TestCase; +import org.python.util.PythonInterpreter; /** * Tests for PyArray. @@ -50,4 +51,16 @@ assertEquals(new PyArray(PyString.class, new String[] {"x", "b", "y", "d"}), arrayToModify); } + + public void testCompactArray() { + // tests http://bugs.jython.org/issue1745 + PythonInterpreter interp = new PythonInterpreter(); + interp.set("arr", new double[3]); + interp.exec("arr.append(3.0)\n\n"); + Object o = interp.get("arr", Object.class); + double[] a = (double[])o; + assertEquals(4, a.length); + assertEquals(0.0, a[0]); + assertEquals(3.0, a[3]); + } } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 6 20:40:28 2016 From: jython-checkins at python.org (jim.baker) Date: Thu, 07 Jan 2016 01:40:28 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Convert_iterators_to_both_O?= =?utf-8?q?bject=5B=5D_and_primitive_variants=2E_Fixes_=232279?= Message-ID: <20160107014028.3383.17695@psf.io> https://hg.python.org/jython/rev/1e7c082d089d changeset: 7853:1e7c082d089d user: Jim Baker date: Wed Jan 06 18:40:06 2016 -0700 summary: Convert iterators to both Object[] and primitive variants. Fixes #2279 files: Lib/test/test_array_jy.py | 10 + src/org/python/core/PyArray.java | 66 +++++---- src/org/python/core/PyIterator.java | 4 + src/org/python/core/PyXRange.java | 4 + src/org/python/core/ReflectedArgs.java | 14 +- tests/java/org/python/core/PyArrayTest.java | 12 + 6 files changed, 81 insertions(+), 29 deletions(-) diff --git a/Lib/test/test_array_jy.py b/Lib/test/test_array_jy.py --- a/Lib/test/test_array_jy.py +++ b/Lib/test/test_array_jy.py @@ -129,6 +129,16 @@ self.assertAsList(jarray.array([1, 2, 3, 4, 5], "i"), [1, 2, 3, 4, 5]) self.assertAsList(array("i", [1, 2, 3, 4, 5]), [1, 2, 3, 4, 5]) + def test_auxillary_boxing(self): + "PyArray is internally used to support boxing of iterators/iterables" + self.assertAsList(xrange(5), [0, 1, 2, 3, 4]) + self.assertAsList(iter(xrange(5)), [0, 1, 2, 3, 4]) + self.assertAsList(list(xrange(5)), [0, 1, 2, 3, 4]) + self.assertAsList((i * 2 for i in xrange(5)), [0, 2, 4, 6, 8]) + self.assertAsList(iter((i * 2 for i in xrange(5))), [0, 2, 4, 6, 8]) + self.assertAsList(iter((i * 2 for i in xrange(5))), [0, 2, 4, 6, 8]) + self.assertAsList(itertools.chain('ABC', 'DEF'), ['A', 'B', 'C', 'D', 'E', 'F']) + def test_object_varargs(self): "array.array objects can be used in the varargs position, with primitive boxing" a = array('i', range(5, 10)) diff --git a/src/org/python/core/PyArray.java b/src/org/python/core/PyArray.java --- a/src/org/python/core/PyArray.java +++ b/src/org/python/core/PyArray.java @@ -57,6 +57,15 @@ setup(type, data); } + public PyArray(Class type, PyObject initial) { + this(TYPE); + this.type = type; + typecode = class2char(type); + data = Array.newInstance(type, 0); + delegate = new ArrayDelegate(); + useInitial(initial); + } + public PyArray(Class type, int n) { this(type, Array.newInstance(type, n)); } @@ -77,6 +86,34 @@ delegate = new ArrayDelegate(); } + private void useInitial(PyObject initial) { + /* + * The initialiser may be omitted, or may validly be one of several types in the broad + * categories of a byte string (which is treated as a machine representation of the data) or + * an iterable yielding values assignable to the elements. There is special treatment for + * type 'u' Unicode. + */ + if (initial == null) { + // Fall through + + } else if (initial instanceof PyList) { + fromlist(initial); + + } else if (initial instanceof PyString && !(initial instanceof PyUnicode)) { + fromstring(initial.toString()); + + } else if ("u".equals(typecode)) { + if (initial instanceof PyUnicode) { + extendArray(((PyUnicode)initial).toCodePoints()); + } else { + extendUnicodeIter(initial); + } + + } else { + extendInternal(initial); + } + } + @ExposedNew static final PyObject array_new(PyNewWrapper new_, boolean init, PyType subtype, PyObject[] args, String[] keywords) { @@ -130,34 +167,7 @@ class2char(type); self.setup(type, Array.newInstance(type, 0)); self.typecode = typecode; - - /* - * The initialiser may be omitted, or may validly be one of several types in the broad - * categories of a byte string (which is treated as a machine representation of the data) or - * an iterable yielding values assignable to the elements. There is special treatment for - * type 'u' Unicode. - */ - PyObject initial = ap.getPyObject(1, null); - if (initial == null) { - // Fall through - - } else if (initial instanceof PyList) { - self.fromlist(initial); - - } else if (initial instanceof PyString && !(initial instanceof PyUnicode)) { - self.fromstring(initial.toString()); - - } else if ("u".equals(typecode)) { - if (initial instanceof PyUnicode) { - self.extendArray(((PyUnicode)initial).toCodePoints()); - } else { - self.extendUnicodeIter(initial); - } - - } else { - self.extendInternal(initial); - } - + self.useInitial(ap.getPyObject(1, null)); return self; } diff --git a/src/org/python/core/PyIterator.java b/src/org/python/core/PyIterator.java --- a/src/org/python/core/PyIterator.java +++ b/src/org/python/core/PyIterator.java @@ -81,6 +81,10 @@ } return list; } + if (c.isArray()) { + PyArray array = new PyArray(c.getComponentType(), this); + return array.__tojava__(c); + } return super.__tojava__(c); } diff --git a/src/org/python/core/PyXRange.java b/src/org/python/core/PyXRange.java --- a/src/org/python/core/PyXRange.java +++ b/src/org/python/core/PyXRange.java @@ -210,6 +210,10 @@ } return list; } + if (c.isArray()) { + PyArray array = new PyArray(c.getComponentType(), this); + return array.__tojava__(c); + } return super.__tojava__(c); } } diff --git a/src/org/python/core/ReflectedArgs.java b/src/org/python/core/ReflectedArgs.java --- a/src/org/python/core/ReflectedArgs.java +++ b/src/org/python/core/ReflectedArgs.java @@ -155,7 +155,19 @@ return pyArgs; } PyObject lastArg = pyArgs[pyArgs.length - 1]; - if (lastArg instanceof PySequenceList || lastArg instanceof PyArray) { + if (lastArg instanceof PySequenceList || + lastArg instanceof PyArray || + lastArg instanceof PyXRange || + lastArg instanceof PyIterator) { + // NOTE that the check is against PySequenceList, not PySequence, + // because certain Java <=> Python semantics currently require this + // additional strictness. Perhaps this can be relaxed. + + // Empirically this list is exhaustive against the Jython runtime, + // excluding only PyBaseString, PyMemoryView, Py2kBuffer, BaseBytes, + // and AstList, many/most of which seem likely to be problematic for + // varargs usage. + // FIXME also check if lastArg is sequence-like return pyArgs; // will be boxed in an array once __tojava__ is called } diff --git a/tests/java/org/python/core/PyArrayTest.java b/tests/java/org/python/core/PyArrayTest.java --- a/tests/java/org/python/core/PyArrayTest.java +++ b/tests/java/org/python/core/PyArrayTest.java @@ -1,6 +1,7 @@ package org.python.core; import junit.framework.TestCase; +import org.junit.Assert; import org.python.util.PythonInterpreter; /** @@ -63,4 +64,15 @@ assertEquals(0.0, a[0]); assertEquals(3.0, a[3]); } + + public void testToJava() { + PythonInterpreter interp = new PythonInterpreter(); + PyObject pyobj = interp.eval("[i * 2 for i in xrange(5)]"); + Assert.assertArrayEquals + (new int[] {0, 2, 4, 6, 8}, + (int[])pyobj.__tojava__(int[].class)); + Assert.assertArrayEquals( + new Integer[] { 0, 2, 4, 6, 8}, + (Object[])pyobj.__tojava__(Object[].class)); + } } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 6 23:02:41 2016 From: jython-checkins at python.org (jim.baker) Date: Thu, 07 Jan 2016 04:02:41 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_All_JUnit_tests_now_pass=2C?= =?utf-8?q?_usually*?= Message-ID: <20160107040228.69597.83559@psf.io> https://hg.python.org/jython/rev/0702331d99a1 changeset: 7854:0702331d99a1 user: Jim Baker date: Wed Jan 06 21:02:22 2016 -0700 summary: All JUnit tests now pass, usually* JSR 223 scope support, for locals(), needed to take in account support for builtins being added. Also excludes more types not supported by com.ziclix.python.sql. *However we still get intermitten NPE failures in BaseBytes tests, which need to be investigated. files: tests/java/com/ziclix/python/sql/DataHandlerTest.java | 28 +++++++-- tests/java/org/python/jsr223/ScriptEngineTest.java | 19 ++++-- 2 files changed, 32 insertions(+), 15 deletions(-) diff --git a/tests/java/com/ziclix/python/sql/DataHandlerTest.java b/tests/java/com/ziclix/python/sql/DataHandlerTest.java --- a/tests/java/com/ziclix/python/sql/DataHandlerTest.java +++ b/tests/java/com/ziclix/python/sql/DataHandlerTest.java @@ -12,6 +12,7 @@ import java.util.Arrays; import java.util.List; +import org.python.core.PyObject; import org.python.core.PySystemState; import junit.framework.TestCase; @@ -35,24 +36,35 @@ ResultSet rs = (ResultSet)Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] {ResultSet.class}, new DefaultReturnHandler()); - List unsupportedTypes = Arrays.asList("ARRAY", - "DATALINK", - "DISTINCT", - "REF", - "ROWID", // java 6 - "STRUCT"); + List unsupportedTypes = Arrays.asList( + "ARRAY", + "DATALINK", + "DISTINCT", + "REF", + "REF_CURSOR", + "ROWID", + "STRUCT", + "TIME_WITH_TIMEZONE", + "TIMESTAMP_WITH_TIMEZONE" + ); for (Field field : Types.class.getDeclaredFields()) { String typeName = field.getName(); int type = field.getInt(null); if (unsupportedTypes.contains(typeName)) { try { _handler.getPyObject(rs, 1, type); - fail("SQLException expected"); + fail("SQLException expected: " + typeName); } catch (SQLException sqle) { // expected } } else { - assertNotNull(typeName + " should return None", _handler.getPyObject(rs, 1, type)); + try { + PyObject pyobj = _handler.getPyObject(rs, 1, type); + assertNotNull(typeName + " should return None", pyobj); + } catch (SQLException sqle) { + // unexpected! but useful for future proofing changes in SQL support + fail("unexpected SQLException: " + typeName); + } } } } diff --git a/tests/java/org/python/jsr223/ScriptEngineTest.java b/tests/java/org/python/jsr223/ScriptEngineTest.java --- a/tests/java/org/python/jsr223/ScriptEngineTest.java +++ b/tests/java/org/python/jsr223/ScriptEngineTest.java @@ -16,6 +16,7 @@ import junit.framework.TestCase; +import org.junit.Assert; import org.python.core.Options; import org.python.core.PyString; @@ -224,13 +225,18 @@ } } + // FIXME PyScriptEngineScope lacks items(), iteritems(), and other dict methods + // This should be added in a future release + public void testScope_repr() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine pythonEngine = manager.getEngineByName("python"); pythonEngine.eval("a = 4"); pythonEngine.eval("b = 'hi'"); - pythonEngine.eval("localrepr = `locals()`"); - assertEquals("{'b': u'hi', 'a': 4}", pythonEngine.get("localrepr")); + String repr = (String)pythonEngine.eval("repr(locals())"); + // locals() contains builtins as of 2.7.0, so we need to selectively test + Assert.assertTrue(repr.contains("'a': 4")); + Assert.assertTrue(repr.contains("'b': u'hi'")); } public void testScope_iter() throws ScriptException { @@ -238,10 +244,9 @@ ScriptEngine pythonEngine = manager.getEngineByName("python"); pythonEngine.eval("a = 4"); pythonEngine.eval("b = 'hi'"); - pythonEngine.eval("list = []"); - pythonEngine.eval("for loc in locals(): list.append(loc)"); - pythonEngine.eval("listrepr = `list`"); - assertEquals("[u'a', u'b', u'list']", pythonEngine.get("listrepr")); + assertEquals( + "['__builtins__', 'a', 'b']", + pythonEngine.eval("repr(sorted((item for item in locals())))")); } public void testScope_lookup() throws ScriptException { @@ -250,7 +255,7 @@ pythonEngine.eval("a = 4"); pythonEngine.eval("b = 'hi'"); pythonEngine.eval("var_a = locals()['a']"); - pythonEngine.eval("arepr = `var_a`"); + pythonEngine.eval("arepr = repr(var_a)"); assertEquals("4", pythonEngine.get("arepr")); } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 6 23:39:45 2016 From: jython-checkins at python.org (jim.baker) Date: Thu, 07 Jan 2016 04:39:45 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_JSR223_ScriptEngine_now_set?= =?utf-8?q?s_=5F=5Ffile=5F=5F_to_ScriptEngine=2EFILENAME=2C_if_defined=2E?= Message-ID: <20160107043944.17329.80962@psf.io> https://hg.python.org/jython/rev/50126c4efa22 changeset: 7855:50126c4efa22 user: Jim Baker date: Wed Jan 06 21:39:38 2016 -0700 summary: JSR223 ScriptEngine now sets __file__ to ScriptEngine.FILENAME, if defined. Fixes #2223 files: src/org/python/jsr223/PyScriptEngine.java | 2 + tests/java/org/python/jsr223/ScriptEngineTest.java | 34 ++++++--- 2 files changed, 23 insertions(+), 13 deletions(-) diff --git a/src/org/python/jsr223/PyScriptEngine.java b/src/org/python/jsr223/PyScriptEngine.java --- a/src/org/python/jsr223/PyScriptEngine.java +++ b/src/org/python/jsr223/PyScriptEngine.java @@ -69,6 +69,7 @@ if (filename == null) { return interp.compile(script); } else { + interp.getLocals().__setitem__(Py.newString("__file__"), Py.newString(filename)); return interp.compile(script, filename); } } catch (PyException pye) { @@ -82,6 +83,7 @@ if (filename == null) { return interp.compile(reader); } else { + interp.getLocals().__setitem__(Py.newString("__file__"), Py.newString(filename)); return interp.compile(reader, filename); } } catch (PyException pye) { diff --git a/tests/java/org/python/jsr223/ScriptEngineTest.java b/tests/java/org/python/jsr223/ScriptEngineTest.java --- a/tests/java/org/python/jsr223/ScriptEngineTest.java +++ b/tests/java/org/python/jsr223/ScriptEngineTest.java @@ -25,9 +25,11 @@ public void testEvalString() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine pythonEngine = manager.getEngineByName("python"); - + ScriptContext context = pythonEngine.getContext(); + context.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE); assertNull(pythonEngine.eval("x = 5")); - assertEquals(Integer.valueOf(5), pythonEngine.eval("x")); + assertEquals(5, pythonEngine.eval("x")); + assertEquals("sample.py", pythonEngine.eval("__file__")); } public void testSyntaxError() { @@ -76,25 +78,31 @@ public void testCompileEvalString() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine pythonEngine = manager.getEngineByName("python"); - + ScriptContext context = pythonEngine.getContext(); + context.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE); CompiledScript five = ((Compilable)pythonEngine).compile("5"); - assertEquals(Integer.valueOf(5), five.eval()); + assertEquals(5, five.eval()); + assertEquals("sample.py", pythonEngine.eval("__file__")); } public void testEvalReader() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine pythonEngine = manager.getEngineByName("python"); - + ScriptContext context = pythonEngine.getContext(); + context.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE); assertNull(pythonEngine.eval(new StringReader("x = 5"))); - assertEquals(Integer.valueOf(5), pythonEngine.eval(new StringReader("x"))); + assertEquals(5, pythonEngine.eval(new StringReader("x"))); + assertEquals("sample.py", pythonEngine.eval("__file__")); } public void testCompileEvalReader() throws ScriptException { ScriptEngineManager manager = new ScriptEngineManager(); ScriptEngine pythonEngine = manager.getEngineByName("python"); - + ScriptContext context = pythonEngine.getContext(); + context.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE); CompiledScript five = ((Compilable)pythonEngine).compile(new StringReader("5")); - assertEquals(Integer.valueOf(5), five.eval()); + assertEquals(5, five.eval()); + assertEquals("sample.py", pythonEngine.eval("__file__")); } public void testBindings() throws ScriptException { @@ -102,9 +110,9 @@ ScriptEngine pythonEngine = manager.getEngineByName("python"); pythonEngine.put("a", 42); - assertEquals(Integer.valueOf(42), pythonEngine.eval("a")); + assertEquals(42, pythonEngine.eval("a")); assertNull(pythonEngine.eval("x = 5")); - assertEquals(Integer.valueOf(5), pythonEngine.get("x")); + assertEquals(5, pythonEngine.get("x")); assertNull(pythonEngine.eval("del x")); assertNull(pythonEngine.get("x")); } @@ -147,8 +155,8 @@ thread.run(); thread.join(); assertNull(test.exception); - assertEquals(Integer.valueOf(-7), test.x); - assertEquals(Integer.valueOf(15), pythonEngine.get("x")); + assertEquals(-7, test.x); + assertEquals(15, pythonEngine.get("x")); assertNull(pythonEngine.eval("del x")); assertNull(pythonEngine.get("x")); } @@ -159,7 +167,7 @@ Invocable invocableEngine = (Invocable)pythonEngine; assertNull(pythonEngine.eval("def f(x): return abs(x)")); - assertEquals(Integer.valueOf(5), invocableEngine.invokeFunction("f", Integer.valueOf(-5))); + assertEquals(5, invocableEngine.invokeFunction("f", -5)); assertEquals("spam", invocableEngine.invokeMethod(new PyString(" spam "), "strip")); assertEquals("spam", invocableEngine.invokeMethod(" spam ", "strip")); } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 7 00:36:28 2016 From: jython-checkins at python.org (jim.baker) Date: Thu, 07 Jan 2016 05:36:28 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_JSR223_sets_sys=2Eargv_if_F?= =?utf-8?q?ILENAME_and/or_ARGV_set_in_script_context=2E_Fixes?= Message-ID: <20160107053628.21386.25802@psf.io> https://hg.python.org/jython/rev/e1ae43e28fbf changeset: 7856:e1ae43e28fbf user: Jim Baker date: Wed Jan 06 22:36:07 2016 -0700 summary: JSR223 sets sys.argv if FILENAME and/or ARGV set in script context. Fixes #1738, #1739 files: src/org/python/jsr223/PyScriptEngine.java | 17 +++ tests/java/org/python/jsr223/ScriptEngineTest.java | 43 ++++++++++ 2 files changed, 60 insertions(+), 0 deletions(-) diff --git a/src/org/python/jsr223/PyScriptEngine.java b/src/org/python/jsr223/PyScriptEngine.java --- a/src/org/python/jsr223/PyScriptEngine.java +++ b/src/org/python/jsr223/PyScriptEngine.java @@ -37,6 +37,23 @@ interp.setOut(context.getWriter()); interp.setErr(context.getErrorWriter()); interp.setLocals(new PyScriptEngineScope(this, context)); + + // set sys.argv if FILENAME, ARGV attributes are defined + String filename = (String) context.getAttribute(ScriptEngine.FILENAME); + String[] argv = (String[]) context.getAttribute(ScriptEngine.ARGV); + if (argv != null || filename != null) { + PyList pyargv = new PyList(); + if (filename != null) { + pyargv.append(Py.java2py(filename)); + } + if (argv != null) { + for (int i = 0; i < argv.length; i++) { + pyargv.append(Py.java2py(argv[i])); + } + } + interp.getSystemState().argv = pyargv; + } + return interp.eval(code).__tojava__(Object.class); } catch (PyException pye) { throw scriptException(pye); diff --git a/tests/java/org/python/jsr223/ScriptEngineTest.java b/tests/java/org/python/jsr223/ScriptEngineTest.java --- a/tests/java/org/python/jsr223/ScriptEngineTest.java +++ b/tests/java/org/python/jsr223/ScriptEngineTest.java @@ -3,6 +3,7 @@ import java.io.IOException; import java.io.StringReader; import java.math.BigInteger; +import java.util.Arrays; import javax.script.Bindings; import javax.script.Compilable; @@ -30,6 +31,42 @@ assertNull(pythonEngine.eval("x = 5")); assertEquals(5, pythonEngine.eval("x")); assertEquals("sample.py", pythonEngine.eval("__file__")); + pythonEngine.eval("import sys"); + assertEquals(Arrays.asList("sample.py"), pythonEngine.eval("sys.argv")); + } + + public void testEvalStringArgv() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + ScriptContext context = pythonEngine.getContext(); + context.setAttribute(ScriptEngine.FILENAME, "sample.py", ScriptContext.ENGINE_SCOPE); + context.setAttribute(ScriptEngine.ARGV, new String[] {"foo", "bar"}, ScriptContext.ENGINE_SCOPE); + assertNull(pythonEngine.eval("x = 5")); + assertEquals(5, pythonEngine.eval("x")); + assertEquals("sample.py", pythonEngine.eval("__file__")); + pythonEngine.eval("import sys"); + assertEquals(Arrays.asList("sample.py", "foo", "bar"), pythonEngine.eval("sys.argv")); + } + + public void testEvalStringNoFilenameWithArgv() throws ScriptException { + ScriptEngineManager manager = new ScriptEngineManager(); + ScriptEngine pythonEngine = manager.getEngineByName("python"); + ScriptContext context = pythonEngine.getContext(); + context.setAttribute(ScriptEngine.ARGV, new String[] {"foo", "bar"}, ScriptContext.ENGINE_SCOPE); + assertNull(pythonEngine.eval("x = 5")); + assertEquals(5, pythonEngine.eval("x")); + boolean gotExpectedException = false; + try { + pythonEngine.eval("__file__"); + } catch (ScriptException e) { + assertTrue(e.getMessage().startsWith("NameError: ")); + gotExpectedException = true; + } + if (!gotExpectedException) { + fail("Excepted __file__ to be undefined"); + } + pythonEngine.eval("import sys"); + assertEquals(Arrays.asList("foo", "bar"), pythonEngine.eval("sys.argv")); } public void testSyntaxError() { @@ -83,6 +120,8 @@ CompiledScript five = ((Compilable)pythonEngine).compile("5"); assertEquals(5, five.eval()); assertEquals("sample.py", pythonEngine.eval("__file__")); + pythonEngine.eval("import sys"); + assertEquals(Arrays.asList("sample.py"), pythonEngine.eval("sys.argv")); } public void testEvalReader() throws ScriptException { @@ -93,6 +132,8 @@ assertNull(pythonEngine.eval(new StringReader("x = 5"))); assertEquals(5, pythonEngine.eval(new StringReader("x"))); assertEquals("sample.py", pythonEngine.eval("__file__")); + pythonEngine.eval("import sys"); + assertEquals(Arrays.asList("sample.py"), pythonEngine.eval("sys.argv")); } public void testCompileEvalReader() throws ScriptException { @@ -103,6 +144,8 @@ CompiledScript five = ((Compilable)pythonEngine).compile(new StringReader("5")); assertEquals(5, five.eval()); assertEquals("sample.py", pythonEngine.eval("__file__")); + pythonEngine.eval("import sys"); + assertEquals(Arrays.asList("sample.py"), pythonEngine.eval("sys.argv")); } public void testBindings() throws ScriptException { -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 7 00:59:41 2016 From: jython-checkins at python.org (jim.baker) Date: Thu, 07 Jan 2016 05:59:41 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Isolate_each_JSR_ScriptEngi?= =?utf-8?q?ne_with_separate_PySystemState=2E_Fixes_=232154?= Message-ID: <20160107055940.30352.43035@psf.io> https://hg.python.org/jython/rev/0d15d1513251 changeset: 7857:0d15d1513251 user: Jim Baker date: Wed Jan 06 22:59:17 2016 -0700 summary: Isolate each JSR ScriptEngine with separate PySystemState. Fixes #2154 files: src/org/python/util/PythonInterpreter.java | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/src/org/python/util/PythonInterpreter.java b/src/org/python/util/PythonInterpreter.java --- a/src/org/python/util/PythonInterpreter.java +++ b/src/org/python/util/PythonInterpreter.java @@ -78,7 +78,7 @@ * @param dict a Python mapping object (e.g., a dictionary) for use as the default namespace */ public static PythonInterpreter threadLocalStateInterpreter(PyObject dict) { - return new PythonInterpreter(dict, null, true); + return new PythonInterpreter(dict, new PySystemState(), true); } /** -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 7 18:53:39 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Thu, 07 Jan 2016 23:53:39 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Use_a_modified_pip_again_du?= =?utf-8?q?e_to?= Message-ID: <20160107235339.3393.81054@psf.io> https://hg.python.org/jython/rev/5eeac43d71f8 changeset: 7858:5eeac43d71f8 user: Darjus Loktevic date: Fri Jan 08 10:53:29 2016 +1100 summary: Use a modified pip again due to https://bitbucket.org/vinay.sajip/distlib/pull-requests/5 files: Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl | Bin 1 files changed, 0 insertions(+), 0 deletions(-) diff --git a/Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl index 5e490155f0ca7f4ddb64c93c39fb2efb8795cd08..13381adf8a5107cc66187642e7e5f5fe455f4224 GIT binary patch [stripped] -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Fri Jan 8 22:21:57 2016 From: jython-checkins at python.org (jim.baker) Date: Sat, 09 Jan 2016 03:21:57 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Exclude_the_minimal_test=5F?= =?utf-8?q?jsr223=2C_which_causes_subsequent_regrtest_problems?= Message-ID: <20160109032157.3363.88395@psf.io> https://hg.python.org/jython/rev/89598c765f74 changeset: 7859:89598c765f74 user: Jim Baker date: Fri Jan 08 20:21:41 2016 -0700 summary: Exclude the minimal test_jsr223, which causes subsequent regrtest problems The changes for #2154 are now causing regrtest to print output for subsequent tests, which then causes other failures. Exclude this test by default for now. files: Lib/test/regrtest.py | 3 +++ 1 files changed, 3 insertions(+), 0 deletions(-) diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -1354,6 +1354,9 @@ test_httplib test_poplib # 'NoneType' is not iterable test_smtplib + + # Problems with the latest JSR 223 changes; see http://bugs.jython.org/issue2154 + test_jsr223 """, 'java.nt': # Expected to fail on Windows -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sat Jan 9 07:25:32 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Sat, 09 Jan 2016 12:25:32 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Rebundle_pip_as_I=27ve_acci?= =?utf-8?q?dentally_had_tox_artefacts_in_the_wheel?= Message-ID: <20160109122531.59592.41587@psf.io> https://hg.python.org/jython/rev/b4b6cf67c012 changeset: 7860:b4b6cf67c012 user: Darjus Loktevic date: Sat Jan 09 21:48:04 2016 +1100 summary: Rebundle pip as I've accidentally had tox artefacts in the wheel files: Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl | Bin 1 files changed, 0 insertions(+), 0 deletions(-) diff --git a/Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl index 13381adf8a5107cc66187642e7e5f5fe455f4224..60fca519c76d801fe0a63ce43a7a52cbe557feed GIT binary patch [stripped] -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sat Jan 9 07:25:32 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Sat, 09 Jan 2016 12:25:32 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Make_sure_JyAttr_=28*Attr?= =?utf-8?q?=29_methods_are_synchronizing_on_the_objects_they_serve?= Message-ID: <20160109122531.21235.61277@psf.io> https://hg.python.org/jython/rev/724ea1e797f2 changeset: 7861:724ea1e797f2 user: Darjus Loktevic date: Sat Jan 09 21:52:32 2016 +1100 summary: Make sure JyAttr (*Attr) methods are synchronizing on the objects they serve and not themselves. Fixes a performance regression #2452 Additional small refactorings and branch optmizations after checking with jitwatch. files: src/org/python/core/JyAttribute.java | 187 +++++++------- src/org/python/core/PyJavaType.java | 7 +- src/org/python/core/PyObject.java | 21 +- 3 files changed, 109 insertions(+), 106 deletions(-) diff --git a/src/org/python/core/JyAttribute.java b/src/org/python/core/JyAttribute.java --- a/src/org/python/core/JyAttribute.java +++ b/src/org/python/core/JyAttribute.java @@ -184,18 +184,8 @@ * Checks whether the given {@link org.python.core.PyObject} * has an attribute of the given type attached. */ - public static synchronized boolean hasAttr(PyObject ob, byte attr_type) { - if (ob.attributes == null) { - return false; - } - if (!(ob.attributes instanceof JyAttribute)) { - return attr_type == JAVA_PROXY_ATTR; - } - JyAttribute att = (JyAttribute) ob.attributes; - while (att != null && att.attr_type < attr_type) { - att = att.getNext(); - } - return att != null && att.attr_type == attr_type; + public static boolean hasAttr(PyObject ob, byte attr_type) { + return getAttr(ob, attr_type) != null; } /** @@ -203,18 +193,17 @@ * {@link org.python.core.PyObject}. * If no attribute of the given type is attached, null is returned. */ - public static synchronized Object getAttr(PyObject ob, byte attr_type) { - if (ob.attributes == null) { - return null; - } - if (!(ob.attributes instanceof JyAttribute)) { + public static Object getAttr(PyObject ob, byte attr_type) { + synchronized (ob) { + if (ob.attributes instanceof JyAttribute) { + JyAttribute att = (JyAttribute) ob.attributes; + while (att != null && att.attr_type < attr_type) { + att = att.getNext(); + } + return att != null && att.attr_type == attr_type ? att.getValue() : null; + } return attr_type == JAVA_PROXY_ATTR ? ob.attributes : null; } - JyAttribute att = (JyAttribute) ob.attributes; - while (att != null && att.attr_type < attr_type) { - att = att.getNext(); - } - return att != null && att.attr_type == attr_type ? att.getValue() : null; } /** @@ -222,20 +211,22 @@ * given object to the given stream. * (Intended for debugging) */ - public static synchronized void debugPrintAttributes(PyObject o, java.io.PrintStream out) { - out.println("debugPrintAttributes of "+System.identityHashCode(o)+":"); - if (o.attributes == null) { - out.println("null"); - } else if (!(o.attributes instanceof JyAttribute)) { - out.println("only javaProxy"); - } else { - JyAttribute att = (JyAttribute) o.attributes; - while (att != null) { - out.println("att type: "+att.attr_type+" value: "+att.getValue()); - att = att.getNext(); + public static void debugPrintAttributes(PyObject o, java.io.PrintStream out) { + synchronized (o) { + out.println("debugPrintAttributes of " + System.identityHashCode(o) + ":"); + if (o.attributes == null) { + out.println("null"); + } else if (!(o.attributes instanceof JyAttribute)) { + out.println("only javaProxy"); + } else { + JyAttribute att = (JyAttribute) o.attributes; + while (att != null) { + out.println("att type: " + att.attr_type + " value: " + att.getValue()); + att = att.getNext(); + } } + out.println("debugPrintAttributes done"); } - out.println("debugPrintAttributes done"); } /** @@ -243,51 +234,53 @@ * If no corresponding attribute exists yet, one is created. If {@value == null}, * the attribute is removed (if it existed at all). */ - public static synchronized void setAttr(PyObject ob, byte attr_type, Object value) { - if (value == null) { - delAttr(ob, attr_type); - } else { - if (ob.attributes == null) { - if (attr_type == JyAttribute.JAVA_PROXY_ATTR) { - ob.attributes = value; + public static void setAttr(PyObject ob, byte attr_type, Object value) { + synchronized (ob) { + if (value == null) { + delAttr(ob, attr_type); + } else { + if (ob.attributes == null) { + if (attr_type == JyAttribute.JAVA_PROXY_ATTR) { + ob.attributes = value; + } else { + ob.attributes = attr_type < 0 ? + new AttributeLink(attr_type, value) : + new TransientAttributeLink(attr_type, value); + } + } else if (!(ob.attributes instanceof JyAttribute)) { + if (attr_type == JyAttribute.JAVA_PROXY_ATTR) { + ob.attributes = value; + } else { + ob.attributes = new AttributeLink(JyAttribute.JAVA_PROXY_ATTR, ob.attributes); + ((JyAttribute) ob.attributes).setNext(attr_type < 0 ? + new AttributeLink(attr_type, value) : + new TransientAttributeLink(attr_type, value)); + } } else { - ob.attributes = attr_type < 0 ? - new AttributeLink(attr_type, value) : - new TransientAttributeLink(attr_type, value); - } - } else if (!(ob.attributes instanceof JyAttribute)) { - if (attr_type == JyAttribute.JAVA_PROXY_ATTR) { - ob.attributes = value; - } else { - ob.attributes = new AttributeLink(JyAttribute.JAVA_PROXY_ATTR, ob.attributes); - ((JyAttribute) ob.attributes).setNext(attr_type < 0 ? - new AttributeLink(attr_type, value) : - new TransientAttributeLink(attr_type, value)); - } - } else { - JyAttribute att = (JyAttribute) ob.attributes; - if (att.attr_type > attr_type) { - JyAttribute newAtt = attr_type < 0 ? - new AttributeLink(attr_type, value) : - new TransientAttributeLink(attr_type, value); - newAtt.setNext(att); - ob.attributes = newAtt; - } else { - while (att.getNext() != null && att.getNext().attr_type <= attr_type) { - att = att.getNext(); - } - if (att.attr_type == attr_type) { - att.setValue(value); - } else if (att.getNext() == null) { - att.setNext(attr_type < 0 ? - new AttributeLink(attr_type, value) : - new TransientAttributeLink(attr_type, value)); + JyAttribute att = (JyAttribute) ob.attributes; + if (att.attr_type > attr_type) { + JyAttribute newAtt = attr_type < 0 ? + new AttributeLink(attr_type, value) : + new TransientAttributeLink(attr_type, value); + newAtt.setNext(att); + ob.attributes = newAtt; } else { - JyAttribute newAtt = attr_type < 0 ? - new AttributeLink(attr_type, value) : - new TransientAttributeLink(attr_type, value); - newAtt.setNext(att.getNext()); - att.setNext(newAtt); + while (att.getNext() != null && att.getNext().attr_type <= attr_type) { + att = att.getNext(); + } + if (att.attr_type == attr_type) { + att.setValue(value); + } else if (att.getNext() == null) { + att.setNext(attr_type < 0 ? + new AttributeLink(attr_type, value) : + new TransientAttributeLink(attr_type, value)); + } else { + JyAttribute newAtt = attr_type < 0 ? + new AttributeLink(attr_type, value) : + new TransientAttributeLink(attr_type, value); + newAtt.setNext(att.getNext()); + att.setNext(newAtt); + } } } } @@ -299,27 +292,29 @@ * (if it existed at all). This is equivalent to calling * {@code setAttr(ob, attr_type, null)}. */ - public static synchronized void delAttr(PyObject ob, byte attr_type) { - if (ob.attributes == null) { - return; - } else if (attr_type == JAVA_PROXY_ATTR && !(ob.attributes instanceof JyAttribute)) { - ob.attributes = null; - } - JyAttribute att = (JyAttribute) ob.attributes; - if (att.attr_type == attr_type) { - ob.attributes = att.getNext(); - } else { - while (att.getNext() != null && att.getNext().attr_type < attr_type) { - att = att.getNext(); + public static void delAttr(PyObject ob, byte attr_type) { + synchronized (ob) { + if (ob.attributes == null) { + return; + } else if (attr_type == JAVA_PROXY_ATTR && !(ob.attributes instanceof JyAttribute)) { + ob.attributes = null; } - if (att.getNext() != null && att.getNext().attr_type == attr_type) { - att.setNext(att.getNext().getNext()); + JyAttribute att = (JyAttribute) ob.attributes; + if (att.attr_type == attr_type) { + ob.attributes = att.getNext(); + } else { + while (att.getNext() != null && att.getNext().attr_type < attr_type) { + att = att.getNext(); + } + if (att.getNext() != null && att.getNext().attr_type == attr_type) { + att.setNext(att.getNext().getNext()); + } } - } - if (ob.attributes != null) { - att = (JyAttribute) ob.attributes; - if (att.getNext() == null && att.attr_type == JyAttribute.JAVA_PROXY_ATTR) { - ob.attributes = att.getValue(); + if (ob.attributes != null) { + att = (JyAttribute) ob.attributes; + if (att.getNext() == null && att.attr_type == JyAttribute.JAVA_PROXY_ATTR) { + ob.attributes = att.getValue(); + } } } } diff --git a/src/org/python/core/PyJavaType.java b/src/org/python/core/PyJavaType.java --- a/src/org/python/core/PyJavaType.java +++ b/src/org/python/core/PyJavaType.java @@ -253,11 +253,14 @@ } visibleBases.add(PyType.fromClassSkippingInners(iface, needsInners)); } - if (JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR) == Object.class) { + + Object javaProxy = JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); + + if (javaProxy == Object.class) { base = PyType.fromClassSkippingInners(PyObject.class, needsInners); } else if(baseClass == null) { base = PyType.fromClassSkippingInners(Object.class, needsInners); - }else if (JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR) == Class.class) { + } else if (javaProxy == Class.class) { base = PyType.fromClassSkippingInners(PyType.class, needsInners); } else { base = PyType.fromClassSkippingInners(baseClass, needsInners); diff --git a/src/org/python/core/PyObject.java b/src/org/python/core/PyObject.java --- a/src/org/python/core/PyObject.java +++ b/src/org/python/core/PyObject.java @@ -336,8 +336,9 @@ * @param c the Class to convert this PyObject to. **/ public Object __tojava__(Class c) { - if ((c == Object.class || c == Serializable.class) && getJavaProxy() != null) { - return JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); + Object proxy = getJavaProxy(); + if ((c == Object.class || c == Serializable.class) && proxy != null) { + return proxy; } if (c.isInstance(this)) { return this; @@ -348,8 +349,8 @@ c = tmp; } } - if (c.isInstance(getJavaProxy())) { - return JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); + if (c.isInstance(proxy)) { + return proxy; } // convert faux floats @@ -382,11 +383,15 @@ return Py.NoConversion; } - protected synchronized Object getJavaProxy() { - if (!JyAttribute.hasAttr(this, JyAttribute.JAVA_PROXY_ATTR)) { - proxyInit(); + protected Object getJavaProxy() { + Object ob = JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); + if (ob == null) { + synchronized (this) { + proxyInit(); + ob = JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); + } } - return JyAttribute.getAttr(this, JyAttribute.JAVA_PROXY_ATTR); + return ob; } /** -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sat Jan 9 08:38:27 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Sat, 09 Jan 2016 13:38:27 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Add_get/set_checkinterval_t?= =?utf-8?q?o_PySystemState=2Ejava_=28they_do_nothing_as_it=27s_not?= Message-ID: <20160109133827.8277.54884@psf.io> https://hg.python.org/jython/rev/6cf77c44b3b9 changeset: 7862:6cf77c44b3b9 user: Darjus Loktevic date: Sun Jan 10 00:38:20 2016 +1100 summary: Add get/set checkinterval to PySystemState.java (they do nothing as it's not applicable to Jython, but helps interop with CPython targeting libs) files: src/org/python/core/PySystemState.java | 8 ++++++++ 1 files changed, 8 insertions(+), 0 deletions(-) diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java --- a/src/org/python/core/PySystemState.java +++ b/src/org/python/core/PySystemState.java @@ -165,6 +165,8 @@ private int recursionlimit = 1000; + private int checkinterval = 100; + private codecs.CodecState codecState; /** true when a SystemRestart is triggered. */ @@ -496,6 +498,12 @@ return Py.None; } + + /* get and setcheckinterval really do nothing, but it helps when some code tries to use these */ + public PyInteger getcheckinterval() { return new PyInteger(checkinterval); } + + public void setcheckinterval(int interval) { checkinterval = interval; } + /** * Change the current working directory to the specified path. * -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sat Jan 9 13:31:16 2016 From: jython-checkins at python.org (jim.baker) Date: Sat, 09 Jan 2016 18:31:16 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Copy_over_pydoc=5Fdata/*_to?= =?utf-8?q?_stdlib=2E_Enables_use_of_Jedi_package=2E?= Message-ID: <20160109183115.70903.81749@psf.io> https://hg.python.org/jython/rev/a1b682267552 changeset: 7863:a1b682267552 user: Jim Baker date: Sat Jan 09 11:31:11 2016 -0700 summary: Copy over pydoc_data/* to stdlib. Enables use of Jedi package. files: CPythonLib.includes | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/CPythonLib.includes b/CPythonLib.includes --- a/CPythonLib.includes +++ b/CPythonLib.includes @@ -8,11 +8,12 @@ encodings/** ensurepip/** importlib/* +json/** logging/* +pydoc_data/** test/** unittest/** xml/etree/** -json/** # Lib files, in alphabetical order: __future__.py -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sat Jan 9 19:58:39 2016 From: jython-checkins at python.org (jim.baker) Date: Sun, 10 Jan 2016 00:58:39 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Add_lib2to3_module_to_stdli?= =?utf-8?q?b=2E?= Message-ID: <20160110005839.11407.85853@psf.io> https://hg.python.org/jython/rev/6aaa26de5b0b changeset: 7864:6aaa26de5b0b user: Jim Baker date: Sat Jan 09 17:58:29 2016 -0700 summary: Add lib2to3 module to stdlib. Required excluding compilation by Ant of this module's tests. As motivated by the discussion on python-ideas for supporting optional type annotations in Python 2.7; see https://mail.python.org/pipermail/python-ideas/2016-January/037704.html files: CPythonLib.includes | 1 + Lib/test/regrtest.py | 5 ----- build.xml | 16 +++++++++++++++- 3 files changed, 16 insertions(+), 6 deletions(-) diff --git a/CPythonLib.includes b/CPythonLib.includes --- a/CPythonLib.includes +++ b/CPythonLib.includes @@ -8,6 +8,7 @@ encodings/** ensurepip/** importlib/* +lib2to3/** json/** logging/* pydoc_data/** diff --git a/Lib/test/regrtest.py b/Lib/test/regrtest.py --- a/Lib/test/regrtest.py +++ b/Lib/test/regrtest.py @@ -94,8 +94,6 @@ curses - Tests that use curses and will modify the terminal's state and output modes. - lib2to3 - Run the tests for 2to3 (They take a while.) - largefile - It is okay to run some test that may create huge files. These tests can take a long time and may consume >2GB of disk space temporarily. @@ -1267,9 +1265,6 @@ test_winsound test_zipfile64 # requires bogus resource "extralargefile" - # Not yet Jython 3.x - test_lib2to3 - # Could rewrite these tests test_descr # cannot import name verify test_epoll # test works only on Linux 2.6 diff --git a/build.xml b/build.xml --- a/build.xml +++ b/build.xml @@ -786,7 +786,21 @@ - + + -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Sun Jan 10 02:52:00 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Sun, 10 Jan 2016 07:52:00 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_One_more_update_to_the_pip_?= =?utf-8?q?wheel=2C_now_Windows_wrappers_should_be_properly?= Message-ID: <20160110075200.4250.26524@psf.io> https://hg.python.org/jython/rev/9400425da66a changeset: 7865:9400425da66a user: Darjus Loktevic date: Sun Jan 10 18:51:29 2016 +1100 summary: One more update to the pip wheel, now Windows wrappers should be properly generated #2360 files: Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl | Bin 1 files changed, 0 insertions(+), 0 deletions(-) diff --git a/Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/pip-7.1.2-py2.py3-none-any.whl index 60fca519c76d801fe0a63ce43a7a52cbe557feed..519958a9ed6ba469b5c9f8c3c5c933d8e8f3e2fd GIT binary patch [stripped] -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Mon Jan 11 13:24:05 2016 From: jython-checkins at python.org (jim.baker) Date: Mon, 11 Jan 2016 18:24:05 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Bump_copyright_date_for_Jyt?= =?utf-8?q?hon_to_201_2016?= Message-ID: <20160111182405.11387.77481@psf.io> https://hg.python.org/jython/rev/e5d62908c495 changeset: 7866:e5d62908c495 user: Jim Baker date: Mon Jan 11 11:23:59 2016 -0700 summary: Bump copyright date for Jython to 201 2016 files: ACKNOWLEDGMENTS | 2 +- src/org/python/core/PySystemState.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS --- a/ACKNOWLEDGMENTS +++ b/ACKNOWLEDGMENTS @@ -3,7 +3,7 @@ Jython: Python for the Java Platform -Copyright (c) 2000-2015 Jython Developers. +Copyright (c) 2000-2016 Jython Developers. All rights reserved. Copyright (c) 2000 BeOpen.com. diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java --- a/src/org/python/core/PySystemState.java +++ b/src/org/python/core/PySystemState.java @@ -94,7 +94,7 @@ */ public static final PyObject copyright = Py.newString( - "Copyright (c) 2000-2015 Jython Developers.\n" + "All rights reserved.\n\n" + + "Copyright (c) 2000-2016 Jython Developers.\n" + "All rights reserved.\n\n" + "Copyright (c) 2000 BeOpen.com.\n" + "All Rights Reserved.\n\n" + "Copyright (c) 2000 The Apache Software Foundation.\n" + "All rights reserved.\n\n" + "Copyright (c) 1995-2000 Corporation for National Research Initiatives.\n" -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Mon Jan 11 20:29:31 2016 From: jython-checkins at python.org (jim.baker) Date: Tue, 12 Jan 2016 01:29:31 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Document_Ctrl-D_to_exit=2C_?= =?utf-8?q?even_on_Windows=2C_due_to_JLine_2?= Message-ID: <20160112012931.59568.70426@psf.io> https://hg.python.org/jython/rev/e14b67be0bad changeset: 7867:e14b67be0bad user: Jim Baker date: Mon Jan 11 18:29:26 2016 -0700 summary: Document Ctrl-D to exit, even on Windows, due to JLine 2 files: Lib/site.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/site.py b/Lib/site.py --- a/Lib/site.py +++ b/Lib/site.py @@ -375,7 +375,7 @@ if os.sep == ':': eof = 'Cmd-Q' elif os.sep == '\\': - eof = 'Ctrl-Z plus Return' + eof = 'Ctrl-D (i.e. EOF)' # maybe also mention Ctrl-Z if we can support for Windows else: eof = 'Ctrl-D (i.e. EOF)' -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Tue Jan 12 04:03:57 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 12 Jan 2016 09:03:57 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Use_new_version_of_setuptoo?= =?utf-8?q?ls_with_Jython_modifications_=28submitted_for?= Message-ID: <20160112090357.1013.67833@psf.io> https://hg.python.org/jython/rev/ba5855140d27 changeset: 7868:ba5855140d27 user: Darjus Loktevic date: Tue Jan 12 20:03:46 2016 +1100 summary: Use new version of setuptools with Jython modifications (submitted for inclusion upstream). Resolves #2360 files: Lib/ensurepip/__init__.py | 2 +- Lib/ensurepip/_bundled/setuptools-18.4-py2.py3-none-any.whl | Bin Lib/ensurepip/_bundled/setuptools-19.2-py2.py3-none-any.whl | Bin 3 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/ensurepip/__init__.py b/Lib/ensurepip/__init__.py --- a/Lib/ensurepip/__init__.py +++ b/Lib/ensurepip/__init__.py @@ -12,7 +12,7 @@ __all__ = ["version", "bootstrap"] -_SETUPTOOLS_VERSION = "18.4" +_SETUPTOOLS_VERSION = "19.2" _PIP_VERSION = "7.1.2" diff --git a/Lib/ensurepip/_bundled/setuptools-18.4-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/setuptools-18.4-py2.py3-none-any.whl deleted file mode 100644 index 9b94202d13594ef9b51815604bc4a37c3b64bd89..e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 GIT binary patch [stripped] diff --git a/Lib/ensurepip/_bundled/setuptools-19.2-py2.py3-none-any.whl b/Lib/ensurepip/_bundled/setuptools-19.2-py2.py3-none-any.whl new file mode 100644 index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..e57e87e8b05fdcdbf9ed70e21a25e778315df77a GIT binary patch [stripped] -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Tue Jan 12 08:53:56 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 12 Jan 2016 13:53:56 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Improve_method_cache_effici?= =?utf-8?q?ency_=28based_on=3A_http=3A//bugs=2Epython=2Eorg/issue22847=29?= Message-ID: <20160112135345.51234.18050@psf.io> https://hg.python.org/jython/rev/65305241475a changeset: 7869:65305241475a user: Darjus Loktevic date: Wed Jan 13 00:53:38 2016 +1100 summary: Improve method cache efficiency (based on: http://bugs.python.org/issue22847) Quick test of running Jython to the repl showed ~120 collision from 700 cache entries. With the changes, the collision count is ~60 and the size difference is tiny and constant. files: src/org/python/core/PyType.java | 4 ++-- 1 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/python/core/PyType.java b/src/org/python/core/PyType.java --- a/src/org/python/core/PyType.java +++ b/src/org/python/core/PyType.java @@ -2036,7 +2036,7 @@ private final AtomicReferenceArray table; /** Size of the cache exponent (2 ** SIZE_EXP). */ - public static final int SIZE_EXP = 11; + private static final int SIZE_EXP = 12; public MethodCache() { table = new AtomicReferenceArray(1 << SIZE_EXP); @@ -2079,7 +2079,7 @@ * Return the table index for type version/name. */ private static int indexFor(Object version, String name) { - return (version.hashCode() * name.hashCode()) >>> (Integer.SIZE - SIZE_EXP); + return (version.hashCode() ^ name.hashCode()) & ((1 << SIZE_EXP) - 1); } /** -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Tue Jan 12 17:47:59 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 12 Jan 2016 22:47:59 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Expose_org=2Epython=2Emodul?= =?utf-8?q?es=2Esre=2EPatternObject_as_SRE=5FPattern_to_look_like?= Message-ID: <20160112224759.4238.48865@psf.io> https://hg.python.org/jython/rev/3b985a25ee12 changeset: 7870:3b985a25ee12 user: Darjus Loktevic date: Wed Jan 13 09:45:10 2016 +1100 summary: Expose org.python.modules.sre.PatternObject as SRE_Pattern to look like CPython. Fixes #2453 files: CoreExposed.includes | 1 + src/org/python/modules/sre/PatternObject.java | 4 +++- 2 files changed, 4 insertions(+), 1 deletions(-) diff --git a/CoreExposed.includes b/CoreExposed.includes --- a/CoreExposed.includes +++ b/CoreExposed.includes @@ -115,6 +115,7 @@ org/python/modules/operator$PyMethodCaller.class org/python/modules/posix/PyStatResult.class org/python/modules/random/PyRandom.class +org/python/modules/sre/PatternObject.class org/python/modules/thread/PyLocal.class org/python/modules/time/PyTimeTuple.class org/python/modules/zipimport/zipimporter.class diff --git a/src/org/python/modules/sre/PatternObject.java b/src/org/python/modules/sre/PatternObject.java --- a/src/org/python/modules/sre/PatternObject.java +++ b/src/org/python/modules/sre/PatternObject.java @@ -18,8 +18,10 @@ import java.util.*; import org.python.core.*; -import org.python.core.util.StringUtil; +import org.python.expose.ExposedType; + + at ExposedType(name = "SRE_Pattern") public class PatternObject extends PyObject implements Traverseproc { int[] code; /* link to the code string object */ public PyString pattern; /* link to the pattern source (or None) */ -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Tue Jan 12 17:54:24 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 12 Jan 2016 22:54:24 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Patch_=2Etravis=2Eyml_for_b?= =?utf-8?q?uffer_overflow_bug=2C_see?= Message-ID: <20160112225424.121142.5417@psf.io> https://hg.python.org/jython/rev/5998cfe2c8a2 changeset: 7871:5998cfe2c8a2 user: Darjus Loktevic date: Wed Jan 13 09:54:17 2016 +1100 summary: Patch .travis.yml for buffer overflow bug, see https://github.com/travis-ci/travis-ci/issues/5227 files: .travis.yml | 7 +++++++ 1 files changed, 7 insertions(+), 0 deletions(-) diff --git a/.travis.yml b/.travis.yml --- a/.travis.yml +++ b/.travis.yml @@ -29,6 +29,13 @@ env: CUSTOM_JDK="default" before_install: + # Patch for buffer overflow bug, see https://github.com/travis-ci/travis-ci/issues/5227 + - hostname + - cat /etc/hosts # optionally check the content *before* + - sudo hostname "$(hostname | cut -c1-63)" + - sed -e "s/^\\(127\\.0\\.0\\.1.*\\)/\\1 $(hostname | cut -c1-63)/" /etc/hosts | sudo tee /etc/hosts + - hostname + - cat /etc/hosts # optionally check the content *after* - if [ "$TRAVIS_OS_NAME" == "osx" ]; then export JAVA_HOME=$(/usr/libexec/java_home); fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew update; fi - if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew install ant; fi -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Tue Jan 12 18:57:07 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Tue, 12 Jan 2016 23:57:07 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Now_properly_expose_Pattern?= =?utf-8?q?Object=2C_doh?= Message-ID: <20160112235707.4234.31260@psf.io> https://hg.python.org/jython/rev/f09a21ca8b82 changeset: 7872:f09a21ca8b82 user: Darjus Loktevic date: Wed Jan 13 10:57:00 2016 +1100 summary: Now properly expose PatternObject, doh files: src/org/python/core/BuiltinDocs.java | 36 +++++++ src/org/python/modules/sre/PatternObject.java | 51 ++++++++- 2 files changed, 78 insertions(+), 9 deletions(-) diff --git a/src/org/python/core/BuiltinDocs.java b/src/org/python/core/BuiltinDocs.java --- a/src/org/python/core/BuiltinDocs.java +++ b/src/org/python/core/BuiltinDocs.java @@ -4727,4 +4727,40 @@ public final static String traceback_tb_next_doc = ""; + public final static String sre_pattern_doc = + "Compiled regular expression objects"; + + public final static String sre_pattern_match_doc = + "match(string[, pos[, endpos]]) --> match object or None.\n" + + " Matches zero or more characters at the beginning of the string"; + + public final static String sre_pattern_findall_doc = + "findall(string[, pos[, endpos]]) --> list.\n" + + " Return a list of all non-overlapping matches of pattern in string."; + + public final static String sre_pattern_finditer_doc = + "finditer(string[, pos[, endpos]]) --> iterator.\n" + + " Return an iterator over all non-overlapping matches for the \n" + + " RE pattern in string. For each match, the iterator returns a\n" + + " match object."; + + public final static String sre_pattern_search_doc = + "search(string[, pos[, endpos]]) --> match object or None.\n" + + " Scan through string looking for a match, and return a corresponding\n" + + " match object instance. Return None if no position in the string matches."; + + public final static String sre_pattern_split_doc = + "split(string[, maxsplit = 0]) --> list.\n" + + " Split string by the occurrences of pattern."; + + public final static String sre_pattern_sub_doc = + "sub(repl, string[, count = 0]) --> newstring\n" + + " Return the string obtained by replacing the leftmost non-overlapping\n" + + " occurrences of pattern in string by the replacement repl."; + + public final static String sre_pattern_subn_doc = + "subn(repl, string[, count = 0]) --> (newstring, number of subs)\n" + + " Return the tuple (new_string, number_of_subs_made) found by replacing\n" + + " the leftmost non-overlapping occurrences of pattern with the\n" + + " replacement repl."; } diff --git a/src/org/python/modules/sre/PatternObject.java b/src/org/python/modules/sre/PatternObject.java --- a/src/org/python/modules/sre/PatternObject.java +++ b/src/org/python/modules/sre/PatternObject.java @@ -18,10 +18,12 @@ import java.util.*; import org.python.core.*; +import org.python.expose.ExposedGet; +import org.python.expose.ExposedMethod; import org.python.expose.ExposedType; - at ExposedType(name = "SRE_Pattern") + at ExposedType(name = "SRE_Pattern", doc = BuiltinDocs.sre_pattern_doc) public class PatternObject extends PyObject implements Traverseproc { int[] code; /* link to the code string object */ public PyString pattern; /* link to the pattern source (or None) */ @@ -45,7 +47,31 @@ this.indexgroup = indexgroup; } - public MatchObject match(PyObject[] args, String[] kws) { + @ExposedGet(name = "pattern") + public PyString getPattern() { + if (pattern == null) { + return Py.EmptyString; + } + return pattern; + } + + @ExposedGet(name = "flags") + public int getFlags() { + return flags; + } + + @ExposedGet(name = "groups") + public int getGroups() { + return groups; + } + + @ExposedGet(name = "groupindex") + public PyObject getGroupindex() { + return groupindex; + } + + @ExposedMethod(doc = BuiltinDocs.sre_pattern_match_doc) + public PyObject match(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("match", args, kws, "string", "pos", "endpos"); PyString string = extractPyString(ap, 0); @@ -56,10 +82,12 @@ state.ptr = state.start; int status = state.SRE_MATCH(code, 0, 1); - return _pattern_new_match(state, string, status); + MatchObject matchObject = _pattern_new_match(state, string, status); + return matchObject != null ? matchObject : Py.None; } - - public MatchObject search(PyObject[] args, String[] kws) { + + @ExposedMethod(doc = BuiltinDocs.sre_pattern_search_doc) + public PyObject search(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("search", args, kws, "string", "pos", "endpos"); PyString string = extractPyString(ap, 0); @@ -70,10 +98,12 @@ int status = state.SRE_SEARCH(code, 0); - return _pattern_new_match(state, string, status); + MatchObject matchObject = _pattern_new_match(state, string, status); + return matchObject != null ? matchObject : Py.None; } + @ExposedMethod(doc = BuiltinDocs.sre_pattern_sub_doc) public PyObject sub(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("sub", args, kws, "repl", "string", "count"); @@ -84,7 +114,7 @@ } - + @ExposedMethod(doc = BuiltinDocs.sre_pattern_subn_doc) public PyObject subn(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("subn", args, kws, "repl", "string", "count"); @@ -184,6 +214,7 @@ return joiner.__getattr__("join").__call__(list); } + @ExposedMethod(doc = BuiltinDocs.sre_pattern_split_doc) public PyObject split(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("split", args, kws, "string", "maxsplit"); @@ -239,7 +270,7 @@ } - + @ExposedMethod(doc = BuiltinDocs.sre_pattern_findall_doc) public PyObject findall(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("findall", args, kws, "string", "pos", "endpos"); @@ -291,12 +322,14 @@ return new PyList(list); } + @ExposedMethod(doc = BuiltinDocs.sre_pattern_finditer_doc) public PyObject finditer(PyObject[] args, String[] kws) { ScannerObject scanner = scanner(args, kws); PyObject search = scanner.__findattr__("search"); return new PyCallIter(search, Py.None); } - + + @ExposedMethod() public ScannerObject scanner(PyObject[] args, String[] kws) { ArgParser ap = new ArgParser("scanner", args, kws, "pattern", "pos", "endpos"); -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 13 00:57:21 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Wed, 13 Jan 2016 05:57:21 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Sort_all_methods_in_PyJavaT?= =?utf-8?q?ype_in_the_right_order=2E_See_=232391?= Message-ID: <20160113055718.106551.14108@psf.io> https://hg.python.org/jython/rev/ac294f546003 changeset: 7873:ac294f546003 user: Jaime Saiz date: Wed Jan 13 16:55:29 2016 +1100 summary: Sort all methods in PyJavaType in the right order. See #2391 files: ACKNOWLEDGMENTS | 1 + src/org/python/core/PyJavaType.java | 79 ++++++++++ tests/java/javatests/DoubleHolder.java | 17 ++ tests/java/javatests/Issue2391AttrOrderTest.java | 20 ++ tests/java/javatests/NumberHolder.java | 7 + 5 files changed, 124 insertions(+), 0 deletions(-) diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS --- a/ACKNOWLEDGMENTS +++ b/ACKNOWLEDGMENTS @@ -172,6 +172,7 @@ Eli Oxman Robert Patrick Kevin Edwards + Jaime Saiz Local Variables: mode: indented-text diff --git a/src/org/python/core/PyJavaType.java b/src/org/python/core/PyJavaType.java --- a/src/org/python/core/PyJavaType.java +++ b/src/org/python/core/PyJavaType.java @@ -15,8 +15,10 @@ import java.lang.reflect.Member; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.Arrays; import java.util.Collection; import java.util.Collections; +import java.util.Comparator; import java.util.Enumeration; import java.util.EventListener; import java.util.HashMap; @@ -26,6 +28,7 @@ import java.util.Map; import java.util.Queue; import java.util.Set; +import java.util.Stack; import org.python.core.util.StringUtil; import org.python.util.Generic; @@ -297,6 +300,9 @@ methods = allMethods.toArray(new Method[allMethods.size()]); } + /* make sure we "sort" all methods so they resolve in the right order. See #2391 for details */ + Arrays.sort(methods, new MethodComparator(new ClassComparator())); + boolean isInAwt = name.startsWith("java.awt.") && name.indexOf('.', 9) == -1; for (Method meth : methods) { if (!declaredOnMember(baseClass, meth) || ignore(meth)) { @@ -996,6 +1002,79 @@ return Collections.unmodifiableMap(postProxies); } + private class ClassComparator implements Comparator> { + + public int compare(Class c1, Class c2) { + if (c1.equals(c2)) { + return 0; + } else if (c1.isAssignableFrom(c2)) { + return -1; + } else if (c2.isAssignableFrom(c1)) { + return 1; + } + + String s1 = hierarchyName(c1); + String s2 = hierarchyName(c2); + return s1.compareTo(s2); + } + + private String hierarchyName(Class c) { + Stack nameStack = new Stack(); + StringBuilder namesBuilder = new StringBuilder(); + do { + nameStack.push(c.getSimpleName()); + c = c.getSuperclass(); + } while (c != null); + + for (String name: nameStack) { + namesBuilder.append(name); + } + + return namesBuilder.toString(); + } + } + + private class MethodComparator implements Comparator { + + private ClassComparator classComparator; + + public MethodComparator(ClassComparator classComparator) { + this.classComparator = classComparator; + } + + public int compare(Method m1, Method m2) { + int result = m1.getName().compareTo(m2.getName()); + + if (result != 0) { + return result; + } + + Class[] p1 = m1.getParameterTypes(); + Class[] p2 = m2.getParameterTypes(); + + int n1 = p1.length; + int n2 = p2.length; + + result = n1 - n2; + + if (result != 0) { + return result; + } + + result = classComparator.compare(m1.getDeclaringClass(), m2.getDeclaringClass()); + + if (result != 0) { + return result; + } + + if (n1 == 0) { + return classComparator.compare(m1.getReturnType(), m2.getReturnType()); + } else if (n1 == 1) { + return classComparator.compare(p1[0], p2[0]); + } + return result; + } + } /* Traverseproc implementation */ @Override diff --git a/tests/java/javatests/DoubleHolder.java b/tests/java/javatests/DoubleHolder.java new file mode 100644 --- /dev/null +++ b/tests/java/javatests/DoubleHolder.java @@ -0,0 +1,17 @@ +package javatests; + +/* Part of Issue2391 test */ + +public class DoubleHolder implements NumberHolder { + + private Double number = 0.0; + + @Override + public Double getNumber() { + return number; + } + + public void setNumber(Double number) { + this.number = number; + } +} diff --git a/tests/java/javatests/Issue2391AttrOrderTest.java b/tests/java/javatests/Issue2391AttrOrderTest.java new file mode 100644 --- /dev/null +++ b/tests/java/javatests/Issue2391AttrOrderTest.java @@ -0,0 +1,20 @@ +package javatests; + + +import org.junit.Test; +import org.python.util.PythonInterpreter; + +import static org.junit.Assert.assertEquals; + +public class Issue2391AttrOrderTest { + + @Test + public void testAttribute() { + PythonInterpreter interpreter = new PythonInterpreter(); + interpreter.exec("from " + getClass().getPackage().getName() + " import DoubleHolder"); + interpreter.exec("d = DoubleHolder()"); + assertEquals("0.0", interpreter.eval("d.number").toString()); + interpreter.exec("d.number = 3.0"); + assertEquals("3.0", interpreter.eval("d.number").toString()); + } +} diff --git a/tests/java/javatests/NumberHolder.java b/tests/java/javatests/NumberHolder.java new file mode 100644 --- /dev/null +++ b/tests/java/javatests/NumberHolder.java @@ -0,0 +1,7 @@ +package javatests; + +/* Part of Issue2391 test */ + +public interface NumberHolder { + Number getNumber(); +} -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 14 00:44:53 2016 From: jython-checkins at python.org (jim.baker) Date: Thu, 14 Jan 2016 05:44:53 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Ensure_SSLHandler_context_i?= =?utf-8?q?s_set_when_channel_becomes_active=2E_Workaround_for?= Message-ID: <20160114054453.19330.45785@psf.io> https://hg.python.org/jython/rev/3983294381a0 changeset: 7874:3983294381a0 user: Nick Bailey date: Wed Jan 13 22:44:36 2016 -0700 summary: Ensure SSLHandler context is set when channel becomes active. Workaround for #2401 Avoids observed race conditions in Netty, depending on how the SSL handler is added; see https://github.com/netty/netty/issues/4705 files: ACKNOWLEDGMENTS | 1 + Lib/ssl.py | 19 +++++++++++++++---- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/ACKNOWLEDGMENTS b/ACKNOWLEDGMENTS --- a/ACKNOWLEDGMENTS +++ b/ACKNOWLEDGMENTS @@ -173,6 +173,7 @@ Robert Patrick Kevin Edwards Jaime Saiz + Nick Bailey Local Variables: mode: indented-text diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -138,7 +138,7 @@ } _cert_name_types = [ - # Fields documented in + # Fields documented in # http://docs.oracle.com/javase/7/docs/api/java/security/cert/X509Certificate.html#getSubjectAlternativeNames() "other", "rfc822", @@ -443,6 +443,17 @@ pipeline = ch.pipeline() pipeline.addFirst("ssl", self.ssl_handler) +class RaceFreeSslHandler(SslHandler): + """ + This is a temporary workaround to solve a race condition that is present in + Netty 4.0.33. The race condition causes an NPE because 'this.ctx' isn't set when + calling channelActive. Once we upgrade to a version of Netty that fixes the race + condition, we should remove this. + """ + + def channelActive(self, ctx): + self.ctx = ctx + SslHandler.channelActive(self) class SSLSocket(object): @@ -502,10 +513,10 @@ self.handshake_count = 0 self.engine = None - + if self.do_handshake_on_connect and self._sock.connected: if isinstance(self._sock, ChildSocket): - log.debug("Child socket - do not handshake! type=%s parent=%s", type(self._sock), self._sock.parent_socket, + log.debug("Child socket - do not handshake! type=%s parent=%s", type(self._sock), self._sock.parent_socket, extra={"sock": self._sock}) else: self.do_handshake() @@ -599,7 +610,7 @@ self._notify_selectors() if self.ssl_handler is None: - self.ssl_handler = SslHandler(self.engine) + self.ssl_handler = RaceFreeSslHandler(self.engine) self.ssl_handler.handshakeFuture().addListener(handshake_step) if hasattr(self._sock, "connected") and self._sock.connected: -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 20 16:14:09 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Wed, 20 Jan 2016 21:14:09 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_On_setups_where_python=2Eex?= =?utf-8?q?ecutable_property_is_not_available_infer_jython?= Message-ID: <20160120211409.5435.26427@psf.io> https://hg.python.org/jython/rev/d9c1b18fcb9b changeset: 7875:d9c1b18fcb9b user: Darjus Loktevic date: Thu Jan 21 08:08:58 2016 +1100 summary: On setups where python.executable property is not available infer jython executable path from sys.prefix #2441 The executable may not exists and it us up to the user to expose a wrapper if needed. files: src/org/python/core/PySystemState.java | 19 +++++++++---- 1 files changed, 13 insertions(+), 6 deletions(-) diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java --- a/src/org/python/core/PySystemState.java +++ b/src/org/python/core/PySystemState.java @@ -1148,8 +1148,10 @@ } /** - * Determine the default sys.executable value from the registry. Returns Py.None is no - * executable can be found. + * Determine the default sys.executable value from the registry. + * If registry is not set (as in standalone jython jar), will use sys.prefix + /bin/jython(.exe) and the file may + * not exist. Users can create a wrapper in it's place to make it work in embedded environments. + * Only if sys.prefix is null, returns Py.None * * @param props a Properties registry * @return a PyObject path string or Py.None @@ -1157,7 +1159,15 @@ private static PyObject initExecutable(Properties props) { String executable = props.getProperty("python.executable"); if (executable == null) { - return Py.None; + if (prefix == null) { + return Py.None; + } else { + if (Platform.IS_WINDOWS) { + executable = prefix.asString() + "/bin/jython.exe"; + } else { + executable = prefix.asString() + "/bin/jython"; + } + } } File executableFile = new File(executable); @@ -1166,9 +1176,6 @@ } catch (IOException ioe) { executableFile = executableFile.getAbsoluteFile(); } - if (!executableFile.isFile()) { - return Py.None; - } return new PyString(executableFile.getPath()); } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 20 16:49:18 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Wed, 20 Jan 2016 21:49:18 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Do_not_double-wrap_=5Fsock?= =?utf-8?q?=2E=5Fhandle=5Fchannel=5Ffuture_=28it_is_already_decorated_with?= Message-ID: <20160120214918.25908.23414@psf.io> https://hg.python.org/jython/rev/d9c65ac2a079 changeset: 7876:d9c65ac2a079 user: Darjus Loktevic date: Thu Jan 21 08:49:05 2016 +1100 summary: Do not double-wrap _sock._handle_channel_future (it is already decorated with @raises_java_exception) with SSLError in ssl.py as it masks the underlying error files: Lib/ssl.py | 6 ++---- 1 files changed, 2 insertions(+), 4 deletions(-) diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -628,10 +628,8 @@ # http://stackoverflow.com/questions/24628271/exception-in-netty-io-netty-util-concurrent-blockingoperationexception # - we are doing this in the handler thread! return - try: - self._sock._handle_channel_future(handshake, "SSL handshake") - except socket_error, e: - raise SSLError(SSL_ERROR_SSL, e.strerror) + + self._sock._handle_channel_future(handshake, "SSL handshake") def dup(self): raise NotImplemented("Can't dup() %s instances" % -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 20 18:42:40 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Wed, 20 Jan 2016 23:42:40 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Use_File=2EpathSeparator_in?= =?utf-8?q?_PySystemState=2EinitExecutable=2C_related_to_=232441?= Message-ID: <20160120234240.18429.62867@psf.io> https://hg.python.org/jython/rev/c1ccf19521dd changeset: 7877:c1ccf19521dd user: Darjus Loktevic date: Thu Jan 21 10:40:21 2016 +1100 summary: Use File.pathSeparator in PySystemState.initExecutable, related to #2441 files: src/org/python/core/PySystemState.java | 5 +++-- 1 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/org/python/core/PySystemState.java b/src/org/python/core/PySystemState.java --- a/src/org/python/core/PySystemState.java +++ b/src/org/python/core/PySystemState.java @@ -1162,10 +1162,11 @@ if (prefix == null) { return Py.None; } else { + executable = prefix.asString() + File.pathSeparator + "bin" + File.pathSeparator; if (Platform.IS_WINDOWS) { - executable = prefix.asString() + "/bin/jython.exe"; + executable += "jython.exe"; } else { - executable = prefix.asString() + "/bin/jython"; + executable += "jython"; } } } -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 20 18:42:41 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Wed, 20 Jan 2016 23:42:41 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Merge_http=3A//bugs=2Epytho?= =?utf-8?q?n=2Eorg/issue25940_for_ssl_Networked_tests=2C_+_some_test?= Message-ID: <20160120234240.5451.42895@psf.io> https://hg.python.org/jython/rev/469374945934 changeset: 7878:469374945934 user: Darjus Loktevic date: Thu Jan 21 10:42:25 2016 +1100 summary: Merge http://bugs.python.org/issue25940 for ssl Networked tests, + some test fixes related to connect_ex files: Lib/_socket.py | 6 +- Lib/ssl.py | 2 +- Lib/test/https_svn_python_org_root.pem | 41 --- Lib/test/selfsigned_pythontestdotnet.pem | 12 +- Lib/test/test_ssl.py | 113 +++++----- Lib/test/test_support.py | 21 +- 6 files changed, 89 insertions(+), 106 deletions(-) diff --git a/Lib/_socket.py b/Lib/_socket.py --- a/Lib/_socket.py +++ b/Lib/_socket.py @@ -291,7 +291,7 @@ # javaexception : callable that raises the python equivalent exception, or None to stub out as unmapped IOException : lambda x: error(errno.ECONNRESET, 'Software caused connection abort'), - InterruptedIOException : lambda x: timeout(None, 'timed out'), + InterruptedIOException : lambda x: timeout(errno.ETIMEDOUT, 'timed out'), IllegalStateException : lambda x: error(errno.EPIPE, 'Illegal state exception'), java.net.BindException : lambda x: error(errno.EADDRINUSE, 'Address already in use'), @@ -300,7 +300,7 @@ java.net.PortUnreachableException : None, java.net.ProtocolException : None, java.net.SocketException : java_net_socketexception_handler, - java.net.SocketTimeoutException : lambda x: timeout(None, 'timed out'), + java.net.SocketTimeoutException : lambda x: timeout(errno.ETIMEDOUT, 'timed out'), java.net.UnknownHostException : lambda x: gaierror(errno.EGETADDRINFOFAILED, 'getaddrinfo failed'), java.nio.channels.AlreadyConnectedException : lambda x: error(errno.EISCONN, 'Socket is already connected'), @@ -808,7 +808,7 @@ if self.timeout == 0: raise error(errno.ETIMEDOUT, "Connection timed out") else: - raise timeout("timed out") + raise timeout(errno.ETIMEDOUT, "timed out") return result def bind(self, address): diff --git a/Lib/ssl.py b/Lib/ssl.py --- a/Lib/ssl.py +++ b/Lib/ssl.py @@ -571,7 +571,7 @@ log.debug("Connect SSL with handshaking %s", self.do_handshake_on_connect, extra={"sock": self._sock}) rc = self._sock.connect_ex(addr) - if not rc: + if rc == errno.EISCONN: self._connected = True if self.do_handshake_on_connect: self.do_handshake() diff --git a/Lib/test/https_svn_python_org_root.pem b/Lib/test/https_svn_python_org_root.pem deleted file mode 100644 --- a/Lib/test/https_svn_python_org_root.pem +++ /dev/null @@ -1,41 +0,0 @@ ------BEGIN CERTIFICATE----- -MIIHPTCCBSWgAwIBAgIBADANBgkqhkiG9w0BAQQFADB5MRAwDgYDVQQKEwdSb290 -IENBMR4wHAYDVQQLExVodHRwOi8vd3d3LmNhY2VydC5vcmcxIjAgBgNVBAMTGUNB -IENlcnQgU2lnbmluZyBBdXRob3JpdHkxITAfBgkqhkiG9w0BCQEWEnN1cHBvcnRA -Y2FjZXJ0Lm9yZzAeFw0wMzAzMzAxMjI5NDlaFw0zMzAzMjkxMjI5NDlaMHkxEDAO -BgNVBAoTB1Jvb3QgQ0ExHjAcBgNVBAsTFWh0dHA6Ly93d3cuY2FjZXJ0Lm9yZzEi -MCAGA1UEAxMZQ0EgQ2VydCBTaWduaW5nIEF1dGhvcml0eTEhMB8GCSqGSIb3DQEJ -ARYSc3VwcG9ydEBjYWNlcnQub3JnMIICIjANBgkqhkiG9w0BAQEFAAOCAg8AMIIC -CgKCAgEAziLA4kZ97DYoB1CW8qAzQIxL8TtmPzHlawI229Z89vGIj053NgVBlfkJ -8BLPRoZzYLdufujAWGSuzbCtRRcMY/pnCujW0r8+55jE8Ez64AO7NV1sId6eINm6 -zWYyN3L69wj1x81YyY7nDl7qPv4coRQKFWyGhFtkZip6qUtTefWIonvuLwphK42y -fk1WpRPs6tqSnqxEQR5YYGUFZvjARL3LlPdCfgv3ZWiYUQXw8wWRBB0bF4LsyFe7 -w2t6iPGwcswlWyCR7BYCEo8y6RcYSNDHBS4CMEK4JZwFaz+qOqfrU0j36NK2B5jc -G8Y0f3/JHIJ6BVgrCFvzOKKrF11myZjXnhCLotLddJr3cQxyYN/Nb5gznZY0dj4k -epKwDpUeb+agRThHqtdB7Uq3EvbXG4OKDy7YCbZZ16oE/9KTfWgu3YtLq1i6L43q -laegw1SJpfvbi1EinbLDvhG+LJGGi5Z4rSDTii8aP8bQUWWHIbEZAWV/RRyH9XzQ -QUxPKZgh/TMfdQwEUfoZd9vUFBzugcMd9Zi3aQaRIt0AUMyBMawSB3s42mhb5ivU -fslfrejrckzzAeVLIL+aplfKkQABi6F1ITe1Yw1nPkZPcCBnzsXWWdsC4PDSy826 -YreQQejdIOQpvGQpQsgi3Hia/0PsmBsJUUtaWsJx8cTLc6nloQsCAwEAAaOCAc4w -ggHKMB0GA1UdDgQWBBQWtTIb1Mfz4OaO873SsDrusjkY0TCBowYDVR0jBIGbMIGY -gBQWtTIb1Mfz4OaO873SsDrusjkY0aF9pHsweTEQMA4GA1UEChMHUm9vdCBDQTEe -MBwGA1UECxMVaHR0cDovL3d3dy5jYWNlcnQub3JnMSIwIAYDVQQDExlDQSBDZXJ0 -IFNpZ25pbmcgQXV0aG9yaXR5MSEwHwYJKoZIhvcNAQkBFhJzdXBwb3J0QGNhY2Vy -dC5vcmeCAQAwDwYDVR0TAQH/BAUwAwEB/zAyBgNVHR8EKzApMCegJaAjhiFodHRw -czovL3d3dy5jYWNlcnQub3JnL3Jldm9rZS5jcmwwMAYJYIZIAYb4QgEEBCMWIWh0 -dHBzOi8vd3d3LmNhY2VydC5vcmcvcmV2b2tlLmNybDA0BglghkgBhvhCAQgEJxYl -aHR0cDovL3d3dy5jYWNlcnQub3JnL2luZGV4LnBocD9pZD0xMDBWBglghkgBhvhC -AQ0ESRZHVG8gZ2V0IHlvdXIgb3duIGNlcnRpZmljYXRlIGZvciBGUkVFIGhlYWQg -b3ZlciB0byBodHRwOi8vd3d3LmNhY2VydC5vcmcwDQYJKoZIhvcNAQEEBQADggIB -ACjH7pyCArpcgBLKNQodgW+JapnM8mgPf6fhjViVPr3yBsOQWqy1YPaZQwGjiHCc -nWKdpIevZ1gNMDY75q1I08t0AoZxPuIrA2jxNGJARjtT6ij0rPtmlVOKTV39O9lg -18p5aTuxZZKmxoGCXJzN600BiqXfEVWqFcofN8CCmHBh22p8lqOOLlQ+TyGpkO/c -gr/c6EWtTZBzCDyUZbAEmXZ/4rzCahWqlwQ3JNgelE5tDlG+1sSPypZt90Pf6DBl -Jzt7u0NDY8RD97LsaMzhGY4i+5jhe1o+ATc7iwiwovOVThrLm82asduycPAtStvY -sONvRUgzEv/+PDIqVPfE94rwiCPCR/5kenHA0R6mY7AHfqQv0wGP3J8rtsYIqQ+T -SCX8Ev2fQtzzxD72V7DX3WnRBnc0CkvSyqD/HMaMyRa+xMwyN2hzXwj7UfdJUzYF -CpUCTPJ5GhD22Dp1nPMd8aINcGeGG7MW9S/lpOt5hvk9C8JzC6WZrG/8Z7jlLwum -GCSNe9FINSkYQKyTYOGWhlC0elnYjyELn8+CkcY7v2vcB5G5l1YjqrZslMZIBjzk -zk6q5PYvCdxTby78dOs6Y5nCpqyJvKeyRKANihDjbPIky/qbn3BHLt4Ui9SyIAmW -omTxJBzcoTWcFbLUvFUufQb1nA5V9FrWk9p2rSVzTMVD ------END CERTIFICATE----- diff --git a/Lib/test/selfsigned_pythontestdotnet.pem b/Lib/test/selfsigned_pythontestdotnet.pem --- a/Lib/test/selfsigned_pythontestdotnet.pem +++ b/Lib/test/selfsigned_pythontestdotnet.pem @@ -1,5 +1,5 @@ -----BEGIN CERTIFICATE----- -MIIChzCCAfCgAwIBAgIJAKGU95wKR8pSMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV +MIIClTCCAf6gAwIBAgIJAKGU95wKR8pTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV BAYTAlhZMRcwFQYDVQQHDA5DYXN0bGUgQW50aHJheDEjMCEGA1UECgwaUHl0aG9u IFNvZnR3YXJlIEZvdW5kYXRpb24xIzAhBgNVBAMMGnNlbGYtc2lnbmVkLnB5dGhv bnRlc3QubmV0MB4XDTE0MTEwMjE4MDkyOVoXDTI0MTAzMDE4MDkyOVowcDELMAkG @@ -8,9 +8,9 @@ aG9udGVzdC5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANDXQXW9tjyZ Xt0Iv2tLL1+jinr4wGg36ioLDLFkMf+2Y1GL0v0BnKYG4N1OKlAU15LXGeGer8vm Sv/yIvmdrELvhAbbo3w4a9TMYQA4XkIVLdvu3mvNOAet+8PMJxn26dbDhG809ALv -EHY57lQsBS3G59RZyBPVqAqmImWNJnVzAgMBAAGjKTAnMCUGA1UdEQQeMByCGnNl -bGYtc2lnbmVkLnB5dGhvbnRlc3QubmV0MA0GCSqGSIb3DQEBBQUAA4GBAIOXmdtM -eG9qzP9TiXW/Gc/zI4cBfdCpC+Y4gOfC9bQUC7hefix4iO3+iZjgy3X/FaRxUUoV -HKiXcXIaWqTSUWp45cSh0MbwZXudp6JIAptzdAhvvCrPKeC9i9GvxsPD4LtDAL97 -vSaxQBezA7hdxZd90/EeyMgVZgAnTCnvAWX9 +EHY57lQsBS3G59RZyBPVqAqmImWNJnVzAgMBAAGjNzA1MCUGA1UdEQQeMByCGnNl +bGYtc2lnbmVkLnB5dGhvbnRlc3QubmV0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN +AQEFBQADgYEAIuzAhgMouJpNdf3URCHIineyoSt6WK/9+eyUcjlKOrDoXNZaD72h +TXMeKYoWvJyVcSLKL8ckPtDobgP2OTt0UkyAaj0n+ZHaqq1lH2yVfGUA1ILJv515 +C8BqbvVZuqm3i7ygmw3bqE/lYMgOrYtXXnqOrz6nvsE6Yc9V9rFflOM= -----END CERTIFICATE----- diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -57,7 +57,8 @@ SIGNED_CERTFILE2 = data_file("keycert4.pem") SIGNING_CA = data_file("pycacert.pem") -SVN_PYTHON_ORG_ROOT_CERT = data_file("https_svn_python_org_root.pem") +REMOTE_HOST = "self-signed.pythontest.net" +REMOTE_ROOT_CERT = data_file("selfsigned_pythontestdotnet.pem") EMPTYCERT = data_file("nullcert.pem") BADCERT = data_file("badcert.pem") @@ -246,7 +247,7 @@ self.assertEqual(p['subjectAltName'], san) def test_DER_to_PEM(self): - with open(SVN_PYTHON_ORG_ROOT_CERT, 'r') as f: + with open(CAFILE_CACERT, 'r') as f: pem = f.read() d1 = ssl.PEM_cert_to_DER_cert(pem) p2 = ssl.DER_cert_to_PEM_cert(d1) @@ -808,7 +809,7 @@ # Mismatching key and cert ctx = ssl.SSLContext(ssl.PROTOCOL_TLSv1) with self.assertRaisesRegexp(ssl.SSLError, "key values mismatch"): - ctx.load_cert_chain(SVN_PYTHON_ORG_ROOT_CERT, ONLYKEY) + ctx.load_cert_chain(CAFILE_CACERT, ONLYKEY) # Password protected key and cert ctx.load_cert_chain(CERTFILE_PROTECTED, password=KEY_PASSWORD) ctx.load_cert_chain(CERTFILE_PROTECTED, password=KEY_PASSWORD.encode()) @@ -1033,7 +1034,7 @@ ctx.load_verify_locations(CERTFILE) self.assertEqual(ctx.cert_store_stats(), {'x509_ca': 0, 'crl': 0, 'x509': 2}) - ctx.load_verify_locations(SVN_PYTHON_ORG_ROOT_CERT) + ctx.load_verify_locations(REMOTE_ROOT_CERT) self.assertEqual(ctx.cert_store_stats(), {'x509_ca': 1, 'crl': 0, 'x509': 2}) @@ -1043,8 +1044,8 @@ # CERTFILE is not flagged as X509v3 Basic Constraints: CA:TRUE ctx.load_verify_locations(CERTFILE) self.assertEqual(ctx.get_ca_certs(), []) - # but SVN_PYTHON_ORG_ROOT_CERT is a CA cert - ctx.load_verify_locations(SVN_PYTHON_ORG_ROOT_CERT) + # but CAFILE_CACERT is a CA cert + ctx.load_verify_locations(CAFILE_CACERT) self.assertEqual(ctx.get_ca_certs(), [{'version': 3, 'serialNumber': 0L, @@ -1064,7 +1065,7 @@ # see this sample code on how we might be able to decode: # https://svn.apache.org/repos/asf/cxf/tags/cxf-2.4.4/distribution/src/main/release/samples/sts_issue_operation/src/main/java/demo/sts/provider/cert/CRLVerifier.java - with open(SVN_PYTHON_ORG_ROOT_CERT) as f: + with open(CAFILE_CACERT) as f: pem = f.read() der = ssl.PEM_cert_to_DER_cert(pem) self.assertEqual(ctx.get_ca_certs(True), [der]) @@ -1091,7 +1092,7 @@ env["SSL_CERT_DIR"] = CAPATH env["SSL_CERT_FILE"] = CERTFILE ctx.load_default_certs() - self.assertEqual(ctx.cert_store_stats(), {"crl": 0, "x509": 3, "x509_ca": 0}) + self.assertEqual(ctx.cert_store_stats(), {"crl": 0, "x509": 4, "x509_ca": 0}) @unittest.skipUnless(sys.platform == "win32", "Windows specific") def test_load_default_certs_env_windows(self): @@ -1241,11 +1242,11 @@ class NetworkedTests(unittest.TestCase): def test_connect(self): - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_NONE) try: - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) self.assertEqual({}, s.getpeercert()) finally: s.close() @@ -1254,27 +1255,27 @@ s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED) self.assertRaisesRegexp(ssl.SSLError, "certificate verify failed", - s.connect, ("svn.python.org", 443)) + s.connect, (REMOTE_HOST, 443)) s.close() # this should succeed because we specify the root cert s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, - ca_certs=SVN_PYTHON_ORG_ROOT_CERT) + ca_certs=REMOTE_ROOT_CERT) try: - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) self.assertTrue(s.getpeercert()) finally: s.close() def test_connect_ex(self): # Issue #11326: check connect_ex() implementation - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, - ca_certs=SVN_PYTHON_ORG_ROOT_CERT) + ca_certs=REMOTE_ROOT_CERT) try: - self.assertEqual(0, s.connect_ex(("svn.python.org", 443))) + self.assertEqual(errno.EISCONN, s.connect_ex((REMOTE_HOST, 443))) self.assertTrue(s.getpeercert()) finally: s.close() @@ -1282,14 +1283,14 @@ def test_non_blocking_connect_ex(self): # Issue #11326: non-blocking connect_ex() should allow handshake # to proceed after the socket gets ready. - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, - ca_certs=SVN_PYTHON_ORG_ROOT_CERT, + ca_certs=REMOTE_ROOT_CERT, do_handshake_on_connect=False) try: s.setblocking(False) - rc = s.connect_ex(('svn.python.org', 443)) + rc = s.connect_ex((REMOTE_HOST, 443)) # EWOULDBLOCK under Windows, EINPROGRESS elsewhere # Jython added EALREADY, as in Jython connect may have already happened self.assertIn(rc, (0, errno.EINPROGRESS, errno.EALREADY, errno.EWOULDBLOCK)) @@ -1312,58 +1313,62 @@ def test_timeout_connect_ex(self): # Issue #12065: on a timeout, connect_ex() should return the original # errno (mimicking the behaviour of non-SSL sockets). - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, - ca_certs=SVN_PYTHON_ORG_ROOT_CERT, + ca_certs=REMOTE_ROOT_CERT, do_handshake_on_connect=False) try: s.settimeout(0.0000001) - rc = s.connect_ex(('svn.python.org', 443)) - if rc == 0: - self.skipTest("svn.python.org responded too quickly") - self.assertIn(rc, (errno.EAGAIN, errno.EWOULDBLOCK)) + rc = s.connect_ex((REMOTE_HOST, 443)) + if rc == errno.EISCONN: + self.skipTest("REMOTE_HOST responded too quickly") + self.assertIn(rc, (errno.ETIMEDOUT, errno.EAGAIN, errno.EWOULDBLOCK)) finally: s.close() def test_connect_ex_error(self): - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): s = ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_REQUIRED, - ca_certs=SVN_PYTHON_ORG_ROOT_CERT) + ca_certs=REMOTE_ROOT_CERT) try: - rc = s.connect_ex(("svn.python.org", 444)) + rc = s.connect_ex((REMOTE_HOST, 444)) # Issue #19919: Windows machines or VMs hosted on Windows # machines sometimes return EWOULDBLOCK. - self.assertIn(rc, (errno.ECONNREFUSED, errno.EWOULDBLOCK)) + errors = ( + errno.ECONNREFUSED, errno.EHOSTUNREACH, errno.ETIMEDOUT, + errno.EWOULDBLOCK, + ) + self.assertIn(rc, errors) finally: s.close() def test_connect_with_context(self): - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): # Same as test_connect, but with a separately created context ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) s = ctx.wrap_socket(socket.socket(socket.AF_INET)) - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) try: self.assertEqual({}, s.getpeercert()) finally: s.close() # Same with a server hostname s = ctx.wrap_socket(socket.socket(socket.AF_INET), - server_hostname="svn.python.org") - s.connect(("svn.python.org", 443)) + server_hostname=REMOTE_HOST) + s.connect((REMOTE_HOST, 443)) s.close() # This should fail because we have no verification certs ctx.verify_mode = ssl.CERT_REQUIRED s = ctx.wrap_socket(socket.socket(socket.AF_INET)) self.assertRaisesRegexp(ssl.SSLError, "certificate verify failed", - s.connect, ("svn.python.org", 443)) + s.connect, (REMOTE_HOST, 443)) s.close() # This should succeed because we specify the root cert - ctx.load_verify_locations(SVN_PYTHON_ORG_ROOT_CERT) + ctx.load_verify_locations(REMOTE_ROOT_CERT) s = ctx.wrap_socket(socket.socket(socket.AF_INET)) - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) try: cert = s.getpeercert() self.assertTrue(cert) @@ -1376,12 +1381,12 @@ # OpenSSL 0.9.8n and 1.0.0, as a result the capath directory must # contain both versions of each certificate (same content, different # filename) for this test to be portable across OpenSSL releases. - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ctx.verify_mode = ssl.CERT_REQUIRED ctx.load_verify_locations(capath=CAPATH) s = ctx.wrap_socket(socket.socket(socket.AF_INET)) - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) try: cert = s.getpeercert() self.assertTrue(cert) @@ -1392,7 +1397,7 @@ ctx.verify_mode = ssl.CERT_REQUIRED ctx.load_verify_locations(capath=BYTES_CAPATH) s = ctx.wrap_socket(socket.socket(socket.AF_INET)) - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) try: cert = s.getpeercert() self.assertTrue(cert) @@ -1400,15 +1405,15 @@ s.close() def test_connect_cadata(self): - with open(CAFILE_CACERT) as f: + with open(REMOTE_ROOT_CERT) as f: pem = f.read().decode('ascii') der = ssl.PEM_cert_to_DER_cert(pem) - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ctx.verify_mode = ssl.CERT_REQUIRED ctx.load_verify_locations(cadata=pem) with closing(ctx.wrap_socket(socket.socket(socket.AF_INET))) as s: - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) cert = s.getpeercert() self.assertTrue(cert) @@ -1417,7 +1422,7 @@ ctx.verify_mode = ssl.CERT_REQUIRED ctx.load_verify_locations(cadata=der) with closing(ctx.wrap_socket(socket.socket(socket.AF_INET))) as s: - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) cert = s.getpeercert() self.assertTrue(cert) @@ -1427,9 +1432,9 @@ # Issue #5238: creating a file-like object with makefile() shouldn't # delay closing the underlying "real socket" (here tested with its # file descriptor, hence skipping the test under Windows). - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): ss = ssl.wrap_socket(socket.socket(socket.AF_INET)) - ss.connect(("svn.python.org", 443)) + ss.connect((REMOTE_HOST, 443)) fd = ss.fileno() f = ss.makefile() f.close() @@ -1443,9 +1448,9 @@ self.assertEqual(e.exception.errno, errno.EBADF) def test_non_blocking_handshake(self): - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): s = socket.socket(socket.AF_INET) - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) s.setblocking(False) s = ssl.wrap_socket(s, cert_reqs=ssl.CERT_NONE, @@ -1488,13 +1493,13 @@ if support.verbose: sys.stdout.write("\nVerified certificate for %s:%s is\n%s\n" % (host, port ,pem)) - _test_get_server_certificate('svn.python.org', 443, SVN_PYTHON_ORG_ROOT_CERT) + _test_get_server_certificate(REMOTE_HOST, 443, REMOTE_ROOT_CERT) if support.IPV6_ENABLED: _test_get_server_certificate('ipv6.google.com', 443) @unittest.skipIf(support.is_jython, "Currently not supported") def test_ciphers(self): - remote = ("svn.python.org", 443) + remote = (REMOTE_HOST, 443) with support.transient_internet(remote[0]): with closing(ssl.wrap_socket(socket.socket(socket.AF_INET), cert_reqs=ssl.CERT_NONE, ciphers="ALL")) as s: @@ -1540,13 +1545,13 @@ @unittest.skipIf(support.is_jython, "On jython preloaded TODO") def test_get_ca_certs_capath(self): # capath certs are loaded on request - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): ctx = ssl.SSLContext(ssl.PROTOCOL_SSLv23) ctx.verify_mode = ssl.CERT_REQUIRED ctx.load_verify_locations(capath=CAPATH) self.assertEqual(ctx.get_ca_certs(), []) s = ctx.wrap_socket(socket.socket(socket.AF_INET)) - s.connect(("svn.python.org", 443)) + s.connect((REMOTE_HOST, 443)) try: cert = s.getpeercert() self.assertTrue(cert) @@ -1557,12 +1562,12 @@ @needs_sni def test_context_setget(self): # Check that the context of a connected socket can be replaced. - with support.transient_internet("svn.python.org"): + with support.transient_internet(REMOTE_HOST): ctx1 = ssl.SSLContext(ssl.PROTOCOL_TLSv1) ctx2 = ssl.SSLContext(ssl.PROTOCOL_SSLv23) s = socket.socket(socket.AF_INET) with closing(ctx1.wrap_socket(s)) as ss: - ss.connect(("svn.python.org", 443)) + ss.connect((REMOTE_HOST, 443)) self.assertIs(ss.context, ctx1) self.assertIs(ss._sslobj.context, ctx1) ss.context = ctx2 @@ -3058,7 +3063,7 @@ pass for filename in [ - CERTFILE, SVN_PYTHON_ORG_ROOT_CERT, BYTES_CERTFILE, + CERTFILE, REMOTE_ROOT_CERT, BYTES_CERTFILE, ONLYCERT, ONLYKEY, BYTES_ONLYCERT, BYTES_ONLYKEY, SIGNED_CERTFILE, SIGNED_CERTFILE2, SIGNING_CA, BADCERT, BADKEY, EMPTYCERT]: diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -46,7 +46,7 @@ "threading_cleanup", "reap_children", "cpython_only", "check_impl_detail", "get_attribute", "py3k_bytes", "import_fresh_module", "threading_cleanup", "reap_children", - "strip_python_stderr"] + "strip_python_stderr", "IPV6_ENABLED"] # We use these extensively in adapting the regression tests for Jython @@ -309,6 +309,7 @@ raise ResourceDenied(msg) HOST = 'localhost' +HOSTv6 = "::1" def find_unused_port(family=socket.AF_INET, socktype=socket.SOCK_STREAM): """Returns an unused port that should be suitable for binding. This is @@ -414,6 +415,24 @@ port = sock.getsockname()[1] return port + +def _is_ipv6_enabled(): + """Check whether IPv6 is enabled on this host.""" + if socket.has_ipv6: + sock = None + try: + sock = socket.socket(socket.AF_INET6, socket.SOCK_STREAM) + sock.bind((HOSTv6, 0)) + return True + except OSError: + pass + finally: + if sock: + sock.close() + return False + +IPV6_ENABLED = False #_is_ipv6_enabled() + FUZZ = 1e-6 def fcmp(x, y): # fuzzy comparison function -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Wed Jan 20 21:17:44 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Thu, 21 Jan 2016 02:17:44 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Forgot_to_add_additional_ce?= =?utf-8?q?rtificates_from_http=3A//bugs=2Epython=2Eorg/issue25940?= Message-ID: <20160121021744.5435.96514@psf.io> https://hg.python.org/jython/rev/a0f1e5a692fe changeset: 7879:a0f1e5a692fe user: Darjus Loktevic date: Thu Jan 21 13:17:40 2016 +1100 summary: Forgot to add additional certificates from http://bugs.python.org/issue25940 files: Lib/test/capath/0e4015b9.0 | 16 ++++++++++++++++ Lib/test/capath/ce7b8643.0 | 16 ++++++++++++++++ 2 files changed, 32 insertions(+), 0 deletions(-) diff --git a/Lib/test/capath/0e4015b9.0 b/Lib/test/capath/0e4015b9.0 new file mode 100644 --- /dev/null +++ b/Lib/test/capath/0e4015b9.0 @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIIClTCCAf6gAwIBAgIJAKGU95wKR8pTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV +BAYTAlhZMRcwFQYDVQQHDA5DYXN0bGUgQW50aHJheDEjMCEGA1UECgwaUHl0aG9u +IFNvZnR3YXJlIEZvdW5kYXRpb24xIzAhBgNVBAMMGnNlbGYtc2lnbmVkLnB5dGhv +bnRlc3QubmV0MB4XDTE0MTEwMjE4MDkyOVoXDTI0MTAzMDE4MDkyOVowcDELMAkG +A1UEBhMCWFkxFzAVBgNVBAcMDkNhc3RsZSBBbnRocmF4MSMwIQYDVQQKDBpQeXRo +b24gU29mdHdhcmUgRm91bmRhdGlvbjEjMCEGA1UEAwwac2VsZi1zaWduZWQucHl0 +aG9udGVzdC5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANDXQXW9tjyZ +Xt0Iv2tLL1+jinr4wGg36ioLDLFkMf+2Y1GL0v0BnKYG4N1OKlAU15LXGeGer8vm +Sv/yIvmdrELvhAbbo3w4a9TMYQA4XkIVLdvu3mvNOAet+8PMJxn26dbDhG809ALv +EHY57lQsBS3G59RZyBPVqAqmImWNJnVzAgMBAAGjNzA1MCUGA1UdEQQeMByCGnNl +bGYtc2lnbmVkLnB5dGhvbnRlc3QubmV0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN +AQEFBQADgYEAIuzAhgMouJpNdf3URCHIineyoSt6WK/9+eyUcjlKOrDoXNZaD72h +TXMeKYoWvJyVcSLKL8ckPtDobgP2OTt0UkyAaj0n+ZHaqq1lH2yVfGUA1ILJv515 +C8BqbvVZuqm3i7ygmw3bqE/lYMgOrYtXXnqOrz6nvsE6Yc9V9rFflOM= +-----END CERTIFICATE----- diff --git a/Lib/test/capath/ce7b8643.0 b/Lib/test/capath/ce7b8643.0 new file mode 100644 --- /dev/null +++ b/Lib/test/capath/ce7b8643.0 @@ -0,0 +1,16 @@ +-----BEGIN CERTIFICATE----- +MIIClTCCAf6gAwIBAgIJAKGU95wKR8pTMA0GCSqGSIb3DQEBBQUAMHAxCzAJBgNV +BAYTAlhZMRcwFQYDVQQHDA5DYXN0bGUgQW50aHJheDEjMCEGA1UECgwaUHl0aG9u +IFNvZnR3YXJlIEZvdW5kYXRpb24xIzAhBgNVBAMMGnNlbGYtc2lnbmVkLnB5dGhv +bnRlc3QubmV0MB4XDTE0MTEwMjE4MDkyOVoXDTI0MTAzMDE4MDkyOVowcDELMAkG +A1UEBhMCWFkxFzAVBgNVBAcMDkNhc3RsZSBBbnRocmF4MSMwIQYDVQQKDBpQeXRo +b24gU29mdHdhcmUgRm91bmRhdGlvbjEjMCEGA1UEAwwac2VsZi1zaWduZWQucHl0 +aG9udGVzdC5uZXQwgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJAoGBANDXQXW9tjyZ +Xt0Iv2tLL1+jinr4wGg36ioLDLFkMf+2Y1GL0v0BnKYG4N1OKlAU15LXGeGer8vm +Sv/yIvmdrELvhAbbo3w4a9TMYQA4XkIVLdvu3mvNOAet+8PMJxn26dbDhG809ALv +EHY57lQsBS3G59RZyBPVqAqmImWNJnVzAgMBAAGjNzA1MCUGA1UdEQQeMByCGnNl +bGYtc2lnbmVkLnB5dGhvbnRlc3QubmV0MAwGA1UdEwQFMAMBAf8wDQYJKoZIhvcN +AQEFBQADgYEAIuzAhgMouJpNdf3URCHIineyoSt6WK/9+eyUcjlKOrDoXNZaD72h +TXMeKYoWvJyVcSLKL8ckPtDobgP2OTt0UkyAaj0n+ZHaqq1lH2yVfGUA1ILJv515 +C8BqbvVZuqm3i7ygmw3bqE/lYMgOrYtXXnqOrz6nvsE6Yc9V9rFflOM= +-----END CERTIFICATE----- -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 21 16:33:16 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Thu, 21 Jan 2016 21:33:16 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Somethimes_/proc/pid/cmdlin?= =?utf-8?q?e_is_too_long_and_bits_of_it_are_truncated_which?= Message-ID: <20160121213315.5455.69740@psf.io> https://hg.python.org/jython/rev/8b66fb32e339 changeset: 7880:8b66fb32e339 user: Darjus Loktevic date: Fri Jan 22 08:25:13 2016 +1100 summary: Somethimes /proc/pid/cmdline is too long and bits of it are truncated which manifests in this test failing, reducing restrictions a bit as all we're doing is testing if we can read it ttp://stackoverflow.com/questions/199130/how-do-i-increase-the-proc-pid-cmdline-4096-byte-limit files: Lib/test/test_file_jy.py | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_file_jy.py b/Lib/test/test_file_jy.py --- a/Lib/test/test_file_jy.py +++ b/Lib/test/test_file_jy.py @@ -62,7 +62,7 @@ @unittest.skipUnless(System.getProperty('os.name') == u'Linux', 'Linux required') def test_can_read_proc_filesystem(self): with open('/proc/{}/cmdline'.format(os.getpid())) as f: - self.assertIn('org.python.util.jython', f.read()) + self.assertIn('jython', f.read()) def test_main(): -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 21 16:33:16 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Thu, 21 Jan 2016 21:33:16 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Skip_test=5Fmhlib=2Etest=5F?= =?utf-8?q?listfolders_because_it_fails_on_circleci=2C_but_that=27s_OK?= Message-ID: <20160121213316.18435.48787@psf.io> https://hg.python.org/jython/rev/af62885b4820 changeset: 7881:af62885b4820 user: Darjus Loktevic date: Fri Jan 22 08:31:27 2016 +1100 summary: Skip test_mhlib.test_listfolders because it fails on circleci, but that's OK since mhlib is deprecated files: Lib/test/test_mhlib.py | 2 ++ 1 files changed, 2 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_mhlib.py b/Lib/test/test_mhlib.py --- a/Lib/test/test_mhlib.py +++ b/Lib/test/test_mhlib.py @@ -169,6 +169,8 @@ eq(inbox.getmessagefilename(1), os.path.join(os.path.abspath(_mhpath), 'inbox', '1')) + @unittest.skipIf(is_jython, "Test does not work when running on circleci, " + "but that's OK since mhlib is deprecated") def test_listfolders(self): mh = getMH() eq = self.assertEqual -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 21 16:33:19 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Thu, 21 Jan 2016 21:33:19 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Improve_test=5Fweakset=2Ete?= =?utf-8?q?st=5Fweak=5Fdestroy=5Fand=5Fmutate=5Fwhile=5Fiterating_resilien?= =?utf-8?q?ce_by?= Message-ID: <20160121213316.121298.8169@psf.io> https://hg.python.org/jython/rev/df609091b999 changeset: 7882:df609091b999 user: Darjus Loktevic date: Fri Jan 22 08:33:05 2016 +1100 summary: Improve test_weakset.test_weak_destroy_and_mutate_while_iterating resilience by doing an extra gc.collect() (fixes test failures on circleci) files: Lib/test/test_weakset.py | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py --- a/Lib/test/test_weakset.py +++ b/Lib/test/test_weakset.py @@ -415,6 +415,7 @@ finally: it = None # should commit all removals + gc.collect() # final before asserts with testcontext() as u: self.assertNotIn(u, s) with testcontext() as u: -- Repository URL: https://hg.python.org/jython From jython-checkins at python.org Thu Jan 21 23:28:19 2016 From: jython-checkins at python.org (darjus.loktevic) Date: Fri, 22 Jan 2016 04:28:19 +0000 Subject: [Jython-checkins] =?utf-8?q?jython=3A_Add_some_more_gc=2Ecollect?= =?utf-8?q?=28=29_to_test=5Fweakset=2C_does_not_seem_to_be_failing_in?= Message-ID: <20160122042819.64100.4715@psf.io> https://hg.python.org/jython/rev/f58d86b21716 changeset: 7883:f58d86b21716 user: Darjus Loktevic date: Fri Jan 22 15:28:14 2016 +1100 summary: Add some more gc.collect() to test_weakset, does not seem to be failing in circleci anymore under the matrix of JVMs files: Lib/test/test_weakset.py | 3 ++- 1 files changed, 2 insertions(+), 1 deletions(-) diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py --- a/Lib/test/test_weakset.py +++ b/Lib/test/test_weakset.py @@ -415,7 +415,7 @@ finally: it = None # should commit all removals - gc.collect() # final before asserts + gc.collect(); gc.collect() # final before asserts with testcontext() as u: self.assertNotIn(u, s) with testcontext() as u: @@ -447,6 +447,7 @@ n1 = len(s) del it gc.collect() + gc.collect() n2 = len(s) # one item may be kept alive inside the iterator self.assertIn(n1, (0, 1)) -- Repository URL: https://hg.python.org/jython From Stefan.Richthofer at gmx.de Fri Jan 22 03:04:34 2016 From: Stefan.Richthofer at gmx.de (Stefan Richthofer) Date: Fri, 22 Jan 2016 09:04:34 +0100 Subject: [Jython-checkins] jython: Add some more gc.collect() to test_weakset, does not seem to be failing in In-Reply-To: <20160122042819.64100.4715@psf.io> References: <20160122042819.64100.4715@psf.io> Message-ID: Did you alternatively try to put some wait-time behind the collect call? It usually runs asynchronously and I suspect calling it twice only adds the sufficient wait time implicitly. > Gesendet: Freitag, 22. Januar 2016 um 05:28 Uhr > Von: "darjus.loktevic" > An: jython-checkins at python.org > Betreff: [Jython-checkins] jython: Add some more gc.collect() to test_weakset, does not seem to be failing in > > https://hg.python.org/jython/rev/f58d86b21716 > changeset: 7883:f58d86b21716 > user: Darjus Loktevic > date: Fri Jan 22 15:28:14 2016 +1100 > summary: > Add some more gc.collect() to test_weakset, does not seem to be failing in circleci anymore under the matrix of JVMs > > files: > Lib/test/test_weakset.py | 3 ++- > 1 files changed, 2 insertions(+), 1 deletions(-) > > > diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py > --- a/Lib/test/test_weakset.py > +++ b/Lib/test/test_weakset.py > @@ -415,7 +415,7 @@ > finally: > it = None # should commit all removals > > - gc.collect() # final before asserts > + gc.collect(); gc.collect() # final before asserts > with testcontext() as u: > self.assertNotIn(u, s) > with testcontext() as u: > @@ -447,6 +447,7 @@ > n1 = len(s) > del it > gc.collect() > + gc.collect() > n2 = len(s) > # one item may be kept alive inside the iterator > self.assertIn(n1, (0, 1)) > > -- > Repository URL: https://hg.python.org/jython > _______________________________________________ > Jython-checkins mailing list > Jython-checkins at python.org > https://mail.python.org/mailman/listinfo/jython-checkins > From pjenvey at underboss.org Thu Jan 28 16:52:45 2016 From: pjenvey at underboss.org (Philip Jenvey) Date: Thu, 28 Jan 2016 13:52:45 -0800 Subject: [Jython-checkins] jython: Add some more gc.collect() to test_weakset, does not seem to be failing in In-Reply-To: References: <20160122042819.64100.4715@psf.io> Message-ID: <0546DED2-AC7C-4FD4-AAC3-529CBD1C7BB7@underboss.org> FYI there is a test_support.gc_collect which should be used instead. It calls collect multiple times with a pause in between for Jython. -- Philip Jenvey > On Jan 22, 2016, at 12:04 AM, Stefan Richthofer wrote: > > Did you alternatively try to put some wait-time behind the collect call? It usually runs asynchronously and I suspect calling it twice only adds the sufficient wait time implicitly. > > >> Gesendet: Freitag, 22. Januar 2016 um 05:28 Uhr >> Von: "darjus.loktevic" >> An: jython-checkins at python.org >> Betreff: [Jython-checkins] jython: Add some more gc.collect() to test_weakset, does not seem to be failing in >> >> https://hg.python.org/jython/rev/f58d86b21716 >> changeset: 7883:f58d86b21716 >> user: Darjus Loktevic >> date: Fri Jan 22 15:28:14 2016 +1100 >> summary: >> Add some more gc.collect() to test_weakset, does not seem to be failing in circleci anymore under the matrix of JVMs >> >> files: >> Lib/test/test_weakset.py | 3 ++- >> 1 files changed, 2 insertions(+), 1 deletions(-) >> >> >> diff --git a/Lib/test/test_weakset.py b/Lib/test/test_weakset.py >> --- a/Lib/test/test_weakset.py >> +++ b/Lib/test/test_weakset.py >> @@ -415,7 +415,7 @@ >> finally: >> it = None # should commit all removals >> >> - gc.collect() # final before asserts >> + gc.collect(); gc.collect() # final before asserts >> with testcontext() as u: >> self.assertNotIn(u, s) >> with testcontext() as u: >> @@ -447,6 +447,7 @@ >> n1 = len(s) >> del it >> gc.collect() >> + gc.collect() >> n2 = len(s) >> # one item may be kept alive inside the iterator >> self.assertIn(n1, (0, 1)) >> >> -- >> Repository URL: https://hg.python.org/jython >> _______________________________________________ >> Jython-checkins mailing list >> Jython-checkins at python.org >> https://mail.python.org/mailman/listinfo/jython-checkins >> > _______________________________________________ > Jython-checkins mailing list > Jython-checkins at python.org > https://mail.python.org/mailman/listinfo/jython-checkins