[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-12-07 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88948:a94a5155d64a
Date: 2016-12-07 16:31 +0100
http://bitbucket.org/pypy/pypy/changeset/a94a5155d64a/

Log:merge py3.5

diff --git a/lib-python/3/test/test_builtin.py 
b/lib-python/3/test/test_builtin.py
--- a/lib-python/3/test/test_builtin.py
+++ b/lib-python/3/test/test_builtin.py
@@ -16,7 +16,8 @@
 import warnings
 from operator import neg
 from test.support import (
-TESTFN, unlink,  run_unittest, check_warnings, check_impl_detail)
+TESTFN, unlink,  run_unittest, check_warnings, check_impl_detail,
+cpython_only)
 from test.support.script_helper import assert_python_ok
 try:
 import pty, signal
@@ -1640,6 +1641,8 @@
 
 class ShutdownTest(unittest.TestCase):
 
+# PyPy doesn't do a gc.collect() at shutdown
+@cpython_only
 def test_cleanup(self):
 # Issue #19255: builtins are still available at shutdown
 code = """if 1:
diff --git a/lib-python/3/test/test_exceptions.py 
b/lib-python/3/test/test_exceptions.py
--- a/lib-python/3/test/test_exceptions.py
+++ b/lib-python/3/test/test_exceptions.py
@@ -1049,6 +1049,7 @@
 obj = test_class()
 with captured_stderr() as stderr:
 del obj
+gc_collect()
 report = stderr.getvalue()
 self.assertIn("Exception ignored", report)
 if test_class is BrokenRepr:
@@ -1059,7 +1060,12 @@
 self.assertIn("raise exc", report)
 if test_class is BrokenExceptionDel:
 self.assertIn("BrokenStrException", report)
-self.assertIn("", report)
+if check_impl_detail(pypy=False):
+self.assertIn("", report)
+else:
+# pypy: this is what lib-python's traceback.py gives
+self.assertIn("",
+  report)
 else:
 self.assertIn("ValueError", report)
 self.assertIn("del is broken", report)
@@ -1081,7 +1087,12 @@
 self.assertIn("raise exc", report)
 self.assertIn(exc_type.__name__, report)
 if exc_type is BrokenStrException:
-self.assertIn("", report)
+if check_impl_detail(pypy=False):
+self.assertIn("", report)
+else:
+# pypy: this is what lib-python's traceback.py gives
+self.assertIn("",
+  report)
 else:
 self.assertIn("test message", report)
 self.assertTrue(report.endswith("\n"))
diff --git a/lib-python/3/test/test_super.py b/lib-python/3/test/test_super.py
--- a/lib-python/3/test/test_super.py
+++ b/lib-python/3/test/test_super.py
@@ -105,14 +105,16 @@
 def f():
 __class__""", globals(), {})
 self.assertIs(type(e.exception), NameError) # Not UnboundLocalError
-class X:
-global __class__
-__class__ = 42
-def f():
-__class__
-self.assertEqual(globals()["__class__"], 42)
-del globals()["__class__"]
-self.assertNotIn("__class__", X.__dict__)
+# XXX the following uses 'global __class__', which pypy doesn't
+# XXX implement at all for now
+#class X:
+#global __class__
+#__class__ = 42
+#def f():
+#__class__
+#self.assertEqual(globals()["__class__"], 42)
+#del globals()["__class__"]
+#self.assertNotIn("__class__", X.__dict__)
 class X:
 nonlocal __class__
 __class__ = 42
diff --git a/lib_pypy/audioop.py b/lib_pypy/audioop.py
--- a/lib_pypy/audioop.py
+++ b/lib_pypy/audioop.py
@@ -375,7 +375,7 @@
 sample_count = _sample_count(cp, size)
 
 rv = ffi.new("unsigned char[]", len(cp) * 2)
-lib.tostereo(rv, cp, len(cp), size, fac1, fac2)
+lib.tostereo(rv, ffi.from_buffer(cp), len(cp), size, fac1, fac2)
 return ffi.buffer(rv)[:]
 
 
@@ -386,7 +386,7 @@
 raise error("Lengths should be the same")
 
 rv = ffi.new("unsigned char[]", len(cp1))
-lib.add(rv, cp1, cp2, len(cp1), size)
+lib.add(rv, ffi.from_buffer(cp1), ffi.from_buffer(cp2), len(cp1), size)
 return ffi.buffer(rv)[:]
 
 
@@ -569,7 +569,7 @@
 state = _check_state(state)
 rv = ffi.new("unsigned char[]", len(cp) * size * 2)
 state_ptr = ffi.new("int[]", state)
-lib.adcpm2lin(rv, cp, len(cp), size, state_ptr)
+lib.adcpm2lin(rv, ffi.from_buffer(cp), len(cp), size, state_ptr)
 return ffi.buffer(rv)[:], tuple(state_ptr)
 
 def byteswap(cp, size):
diff --git a/pypy/interpreter/astcompiler/assemble.py 
b/pypy/interpreter/astcompiler/assemble.py
--- 

[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-12-07 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88931:d4951c9a2236
Date: 2016-12-07 11:52 +0100
http://bitbucket.org/pypy/pypy/changeset/d4951c9a2236/

Log:merge py3.5

diff too long, truncating to 2000 out of 4 lines

diff --git a/extra_tests/README.txt b/extra_tests/README.txt
new file mode 100644
--- /dev/null
+++ b/extra_tests/README.txt
@@ -0,0 +1,5 @@
+The tests in this directory are a complement to lib-python/3/test/.
+
+They are meant to run on top of a compiled pypy3 or CPython3.5 in an
+environment containing at least pytest and hypothesis, using a command like
+'pytest extra_tests/'.
diff --git a/extra_tests/pytest.ini b/extra_tests/pytest.ini
new file mode 100644
diff --git a/extra_tests/test_bufferedreader.py 
b/extra_tests/test_bufferedreader.py
new file mode 100644
--- /dev/null
+++ b/extra_tests/test_bufferedreader.py
@@ -0,0 +1,99 @@
+import io
+from cffi import FFI
+
+import pytest
+from hypothesis import strategies as st
+from hypothesis import given, assume, settings
+from hypothesis.stateful import (
+RuleBasedStateMachine, Bundle, rule, run_state_machine_as_test, 
precondition)
+ffi = FFI()
+
+MAX_READ_SIZE = 1024
+MIN_READ_SIZE = 1
+MAX_SIZE = 0x
+
+@st.composite
+def data_and_sizes(draw, reads=st.lists(st.integers(MIN_READ_SIZE, 
MAX_READ_SIZE))):
+reads = draw(reads)
+total_size = sum(reads)
+assume(0 < total_size < MAX_SIZE)
+data = draw(st.binary(min_size=total_size, max_size=total_size))
+return data, reads
+
+class Stream(io.RawIOBase):
+def __init__(self, data, read_sizes):
+assert sum(read_sizes) == len(data)
+self.data = data
+self.n = 0
+self.read_sizes = iter(read_sizes)
+self.partial_read = 0
+
+def readinto(self, buf):
+if self.n == len(self.data):
+return 0
+if self.partial_read:
+read_size = self.partial_read
+else:
+read_size = next(self.read_sizes)
+if len(buf) < read_size:
+self.partial_read = read_size - len(buf)
+read_size = len(buf)
+else:
+self.partial_read = 0
+self.update_buffer(buf, self.data[self.n:self.n + read_size])
+self.n += read_size
+return read_size
+
+def update_buffer(self, buf, data):
+n = len(data)
+buf[:n] = data
+
+def readable(self):
+return True
+
+class StreamCFFI(Stream):
+def update_buffer(self, buf, data):
+n = len(data)
+ffi.buffer(ffi.from_buffer(buf), n)[:] = data
+
+
+@pytest.mark.parametrize('StreamCls', [Stream, StreamCFFI])
+@given(params=data_and_sizes(), chunk_size=st.integers(MIN_READ_SIZE, 8192))
+def test_buf(params, chunk_size, StreamCls):
+data, sizes = params
+stream = StreamCls(data, sizes)
+assert io.BufferedReader(stream, chunk_size).read(len(data)) == data
+
+class StateMachine(RuleBasedStateMachine):
+def __init__(self, stream, reference):
+super().__init__()
+self.stream = stream
+self.reference = reference
+
+@rule(size=st.integers(MIN_READ_SIZE, MAX_READ_SIZE))
+def read(self, size):
+expected = self.reference.read(size)
+assert self.stream.read(size) == expected
+
+@rule(size=st.integers(MIN_READ_SIZE, MAX_READ_SIZE))
+def readinto(self, size):
+expected = self.reference.read(size)
+buf = bytearray(size)
+n = self.stream.readinto(buf)
+assert buf[:n] == expected
+
+@rule()
+def readline(self):
+expected = self.reference.readline(80)
+assert self.stream.readline(80) == expected
+
+@pytest.mark.parametrize('StreamCls', [Stream, StreamCFFI])
+@settings(max_examples=50)
+@given(params=data_and_sizes(), chunk_size=st.integers(MIN_READ_SIZE, 8192))
+def test_stateful(params, chunk_size, StreamCls):
+data, sizes = params
+raw_stream = StreamCls(data, sizes)
+reference = io.BytesIO(data)
+stream = io.BufferedReader(raw_stream, chunk_size)
+sm = StateMachine(stream, reference)
+run_state_machine_as_test(lambda: sm)
diff --git a/lib-python/3/_collections_abc.py b/lib-python/3/_collections_abc.py
--- a/lib-python/3/_collections_abc.py
+++ b/lib-python/3/_collections_abc.py
@@ -156,7 +156,7 @@
 __slots__ = ()
 
 @abstractmethod
-async def __aiter__(self):
+def __aiter__(self):
 return AsyncIterator()
 
 @classmethod
@@ -176,7 +176,7 @@
 """Return the next item or raise StopAsyncIteration when exhausted."""
 raise StopAsyncIteration
 
-async def __aiter__(self):
+def __aiter__(self):
 return self
 
 @classmethod
diff --git a/lib-python/3/_compat_pickle.py b/lib-python/3/_compat_pickle.py
--- a/lib-python/3/_compat_pickle.py
+++ b/lib-python/3/_compat_pickle.py
@@ -177,6 +177,13 @@
 'DocXMLRPCServer': 'xmlrpc.server',
 'SimpleHTTPServer': 'http.server',
 'CGIHTTPServer': 'http.server',
+# For 

[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-12-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88788:c75ec5f968ae
Date: 2016-12-01 12:51 +0100
http://bitbucket.org/pypy/pypy/changeset/c75ec5f968ae/

Log:merge py3.5

diff --git a/lib-python/3/distutils/sysconfig_pypy.py 
b/lib-python/3/distutils/sysconfig_pypy.py
--- a/lib-python/3/distutils/sysconfig_pypy.py
+++ b/lib-python/3/distutils/sysconfig_pypy.py
@@ -60,6 +60,8 @@
 
 def _init_posix():
 """Initialize the module as appropriate for POSIX systems."""
+so_list = [s[0] for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION]
+so_ext = (so_list or ['.so'])[0]
 g = {}
 g['CC'] = "gcc -pthread"
 g['CXX'] = "g++ -pthread"
@@ -67,7 +69,7 @@
 g['CFLAGS'] = "-DNDEBUG -O2"
 g['CCSHARED'] = "-fPIC"
 g['LDSHARED'] = "gcc -pthread -shared"
-g['SO'] = [s[0] for s in imp.get_suffixes() if s[2] == imp.C_EXTENSION][0]
+g['SO'] = so_ext
 g['SHLIB_SUFFIX'] = g['SO']
 g['AR'] = "ar"
 g['ARFLAGS'] = "rc"
diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -192,6 +192,14 @@
 assert self._finalize_.im_func is not W_Root._finalize_.im_func
 space.finalizer_queue.register_finalizer(self)
 
+def may_unregister_rpython_finalizer(self, space):
+"""Optimization hint only: if there is no user-defined __del__()
+method, pass the hint ``don't call any finalizer'' to rgc.
+"""
+if not self.getclass(space).hasuserdel:
+from rpython.rlib import rgc
+rgc.may_ignore_finalizer(self)
+
 # hooks that the mapdict implementations needs:
 def _get_mapdict_map(self):
 return None
diff --git a/pypy/interpreter/generator.py b/pypy/interpreter/generator.py
--- a/pypy/interpreter/generator.py
+++ b/pypy/interpreter/generator.py
@@ -3,7 +3,7 @@
 from pypy.interpreter.pyopcode import LoopBlock, SApplicationException, Yield
 from pypy.interpreter.pycode import CO_YIELD_INSIDE_TRY
 from pypy.interpreter.astcompiler import consts
-from rpython.rlib import jit
+from rpython.rlib import jit, rgc
 from rpython.rlib.objectmodel import specialize
 from rpython.rlib.rarithmetic import r_uint
 
@@ -20,7 +20,7 @@
 self.running = False
 self._name = name   # may be null, use get_name()
 self._qualname = qualname   # may be null, use get_qualname()
-if (isinstance(self, Coroutine)# XXX would be cool not to need this
+if (isinstance(self, Coroutine)
 or self.pycode.co_flags & CO_YIELD_INSIDE_TRY):
 self.register_finalizer(self.space)
 self.saved_operr = None
@@ -89,7 +89,7 @@
 
 # if the frame is now marked as finished, it was RETURNed from
 if frame.frame_finished_execution:
-self.frame = None
+self.frame_is_finished()
 if space.is_w(w_result, space.w_None):
 raise OperationError(space.w_StopIteration, space.w_None)
 else:
@@ -107,6 +107,14 @@
 if self.saved_operr is not None:
 ec.set_sys_exc_info(self.saved_operr)
 self.saved_operr = None
+#
+# Optimization only: after we've started a Coroutine without
+# CO_YIELD_INSIDE_TRY, then Coroutine._finalize_() will be a no-op
+if (isinstance(self, Coroutine)
+and frame.last_instr == -1
+and not (self.pycode.co_flags & CO_YIELD_INSIDE_TRY)):
+rgc.may_ignore_finalizer(self)
+#
 self.running = True
 try:
 w_result = frame.execute_frame(self, w_arg_or_err)
@@ -116,7 +124,7 @@
 if e.match(space, space.w_StopIteration):
 self._leak_stopiteration(e)
 finally:
-self.frame = None
+self.frame_is_finished()
 raise
 finally:
 frame.f_backref = jit.vref_None
@@ -323,6 +331,10 @@
 break
 block = block.previous
 
+def frame_is_finished(self):
+self.frame = None
+rgc.may_ignore_finalizer(self)
+
 
 class GeneratorIterator(GeneratorOrCoroutine):
 "An iterator created by a generator."
@@ -364,7 +376,7 @@
 break
 # if the frame is now marked as finished, it was RETURNed from
 if frame.frame_finished_execution:
-self.frame = None
+self.frame_is_finished()
 break
 results.append(w_result) # YIELDed
 return unpack_into
diff --git a/pypy/interpreter/module.py b/pypy/interpreter/module.py
--- a/pypy/interpreter/module.py
+++ b/pypy/interpreter/module.py
@@ -121,31 +121,8 @@
 return space.newtuple(tup_return)
 
 def descr_module__repr__(self, space):
-w_loader = space.finditem(self.w_dict, 

[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-11-29 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88738:709cadb7f491
Date: 2016-11-29 13:02 +0100
http://bitbucket.org/pypy/pypy/changeset/709cadb7f491/

Log:merge py3.5

diff too long, truncating to 2000 out of 2056 lines

diff --git a/lib-python/2.7/distutils/sysconfig_pypy.py 
b/lib-python/2.7/distutils/sysconfig_pypy.py
--- a/lib-python/2.7/distutils/sysconfig_pypy.py
+++ b/lib-python/2.7/distutils/sysconfig_pypy.py
@@ -74,6 +74,19 @@
 g['LIBDIR'] = os.path.join(sys.prefix, 'lib')
 g['VERSION'] = get_python_version()
 
+if sys.platform[:6] == "darwin":
+import platform
+if platform.machine() == 'i386':
+if platform.architecture()[0] == '32bit':
+arch = 'i386'
+else:
+arch = 'x86_64'
+else:
+# just a guess
+arch = platform.machine()
+g['LDSHARED'] += ' -undefined dynamic_lookup'
+g['CC'] += ' -arch %s' % (arch,)
+
 global _config_vars
 _config_vars = g
 
@@ -109,6 +122,12 @@
 _config_vars['prefix'] = PREFIX
 _config_vars['exec_prefix'] = EXEC_PREFIX
 
+# OS X platforms require special customization to handle
+# multi-architecture, multi-os-version installers
+if sys.platform == 'darwin':
+import _osx_support
+_osx_support.customize_config_vars(_config_vars)
+
 if args:
 vals = []
 for name in args:
diff --git a/lib-python/3/_weakrefset.py b/lib-python/3/_weakrefset.py
--- a/lib-python/3/_weakrefset.py
+++ b/lib-python/3/_weakrefset.py
@@ -65,7 +65,14 @@
 yield item
 
 def __len__(self):
-return len(self.data) - len(self._pending_removals)
+# PyPy change: we can't rely on len(self.data) at all, because
+# the weakref callbacks may be called at an unknown later time.
+#return len(self.data) - len(self._pending_removals)
+#
+result = 0
+for wr in self.data:
+result += (wr() is not None)
+return result
 
 def __contains__(self, item):
 try:
diff --git a/lib-python/3/test/test_asyncio/test_base_events.py 
b/lib-python/3/test/test_asyncio/test_base_events.py
--- a/lib-python/3/test/test_asyncio/test_base_events.py
+++ b/lib-python/3/test/test_asyncio/test_base_events.py
@@ -510,6 +510,7 @@
 fut.add_done_callback(lambda *args: self.loop.stop())
 self.loop.run_forever()
 fut = None # Trigger Future.__del__ or futures._TracebackLogger
+support.gc_collect()
 if PY34:
 # Future.__del__ in Python 3.4 logs error with
 # an actual exception context
diff --git a/lib-python/3/test/test_asyncio/test_futures.py 
b/lib-python/3/test/test_asyncio/test_futures.py
--- a/lib-python/3/test/test_asyncio/test_futures.py
+++ b/lib-python/3/test/test_asyncio/test_futures.py
@@ -238,6 +238,7 @@
 fut.set_exception(RuntimeError('boom'))
 del fut
 test_utils.run_briefly(self.loop)
+support.gc_collect()
 self.assertTrue(m_log.error.called)
 
 @mock.patch('asyncio.base_events.logger')
diff --git a/lib-python/3/test/test_complex.py 
b/lib-python/3/test/test_complex.py
--- a/lib-python/3/test/test_complex.py
+++ b/lib-python/3/test/test_complex.py
@@ -310,7 +310,7 @@
 self.assertRaises(TypeError, float, 5+3j)
 self.assertRaises(ValueError, complex, "")
 self.assertRaises(TypeError, complex, None)
-self.assertRaisesRegex(TypeError, "not 'NoneType'", complex, None)
+self.assertRaisesRegex(TypeError, " 'NoneType'", complex, None)
 self.assertRaises(ValueError, complex, "\0")
 self.assertRaises(ValueError, complex, "3\09")
 self.assertRaises(TypeError, complex, "1", "2")
diff --git a/lib-python/3/test/test_exceptions.py 
b/lib-python/3/test/test_exceptions.py
--- a/lib-python/3/test/test_exceptions.py
+++ b/lib-python/3/test/test_exceptions.py
@@ -1013,6 +1013,7 @@
 self.assertNotEqual(wr(), None)
 else:
 self.fail("RecursionError not raised")
+gc_collect()
 self.assertEqual(wr(), None)
 
 def test_errno_ENOTDIR(self):
diff --git a/lib-python/3/test/test_sys.py b/lib-python/3/test/test_sys.py
--- a/lib-python/3/test/test_sys.py
+++ b/lib-python/3/test/test_sys.py
@@ -811,7 +811,12 @@
 ref = AtExit()
 """
 rc, stdout, stderr = assert_python_ok('-c', code)
-self.assertEqual(stdout.rstrip(), b'True')
+if test.support.check_impl_detail(cpython=True):
+self.assertEqual(stdout.rstrip(), b'True')
+else:
+# the __del__ method may or may not have been called
+# in other Python implementations
+self.assertIn(stdout.rstrip(), {b'True', b''})
 
 
 @test.support.cpython_only
diff --git a/lib-python/3/test/test_weakref.py 
b/lib-python/3/test/test_weakref.py

[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-11-21 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88509:363e082d0436
Date: 2016-11-21 11:24 +0100
http://bitbucket.org/pypy/pypy/changeset/363e082d0436/

Log:merge py3.5

diff too long, truncating to 2000 out of 20922 lines

diff --git a/_pytest/__init__.py b/_pytest/__init__.py
--- a/_pytest/__init__.py
+++ b/_pytest/__init__.py
@@ -1,2 +1,2 @@
 #
-__version__ = '2.5.2'
+__version__ = '2.9.2'
diff --git a/_pytest/_argcomplete.py b/_pytest/_argcomplete.py
--- a/_pytest/_argcomplete.py
+++ b/_pytest/_argcomplete.py
@@ -88,9 +88,6 @@
 return completion
 
 if os.environ.get('_ARGCOMPLETE'):
-# argcomplete 0.5.6 is not compatible with python 2.5.6: print/with/format
-if sys.version_info[:2] < (2, 6):
-sys.exit(1)
 try:
 import argcomplete.completers
 except ImportError:
diff --git a/_pytest/_code/__init__.py b/_pytest/_code/__init__.py
new file mode 100644
--- /dev/null
+++ b/_pytest/_code/__init__.py
@@ -0,0 +1,12 @@
+""" python inspection/code generation API """
+from .code import Code  # noqa
+from .code import ExceptionInfo  # noqa
+from .code import Frame  # noqa
+from .code import Traceback  # noqa
+from .code import getrawcode  # noqa
+from .code import patch_builtins  # noqa
+from .code import unpatch_builtins  # noqa
+from .source import Source  # noqa
+from .source import compile_ as compile  # noqa
+from .source import getfslineno  # noqa
+
diff --git a/_pytest/_code/_py2traceback.py b/_pytest/_code/_py2traceback.py
new file mode 100644
--- /dev/null
+++ b/_pytest/_code/_py2traceback.py
@@ -0,0 +1,81 @@
+# copied from python-2.7.3's traceback.py
+# CHANGES:
+# - some_str is replaced, trying to create unicode strings
+#
+import types
+
+def format_exception_only(etype, value):
+"""Format the exception part of a traceback.
+
+The arguments are the exception type and value such as given by
+sys.last_type and sys.last_value. The return value is a list of
+strings, each ending in a newline.
+
+Normally, the list contains a single string; however, for
+SyntaxError exceptions, it contains several lines that (when
+printed) display detailed information about where the syntax
+error occurred.
+
+The message indicating which exception occurred is always the last
+string in the list.
+
+"""
+
+# An instance should not have a meaningful value parameter, but
+# sometimes does, particularly for string exceptions, such as
+# >>> raise string1, string2  # deprecated
+#
+# Clear these out first because issubtype(string1, SyntaxError)
+# would throw another exception and mask the original problem.
+if (isinstance(etype, BaseException) or
+isinstance(etype, types.InstanceType) or
+etype is None or type(etype) is str):
+return [_format_final_exc_line(etype, value)]
+
+stype = etype.__name__
+
+if not issubclass(etype, SyntaxError):
+return [_format_final_exc_line(stype, value)]
+
+# It was a syntax error; show exactly where the problem was found.
+lines = []
+try:
+msg, (filename, lineno, offset, badline) = value.args
+except Exception:
+pass
+else:
+filename = filename or ""
+lines.append('  File "%s", line %d\n' % (filename, lineno))
+if badline is not None:
+if isinstance(badline, bytes):  # python 2 only
+badline = badline.decode('utf-8', 'replace')
+lines.append(u'%s\n' % badline.strip())
+if offset is not None:
+caretspace = badline.rstrip('\n')[:offset].lstrip()
+# non-space whitespace (likes tabs) must be kept for alignment
+caretspace = ((c.isspace() and c or ' ') for c in caretspace)
+# only three spaces to account for offset1 == pos 0
+lines.append('   %s^\n' % ''.join(caretspace))
+value = msg
+
+lines.append(_format_final_exc_line(stype, value))
+return lines
+
+def _format_final_exc_line(etype, value):
+"""Return a list of a single line -- normal case for 
format_exception_only"""
+valuestr = _some_str(value)
+if value is None or not valuestr:
+line = "%s\n" % etype
+else:
+line = "%s: %s\n" % (etype, valuestr)
+return line
+
+def _some_str(value):
+try:
+return unicode(value)
+except Exception:
+try:
+return str(value)
+except Exception:
+pass
+return '' % type(value).__name__
diff --git a/_pytest/_code/code.py b/_pytest/_code/code.py
new file mode 100644
--- /dev/null
+++ b/_pytest/_code/code.py
@@ -0,0 +1,805 @@
+import sys
+from inspect import CO_VARARGS, CO_VARKEYWORDS
+
+import py
+
+builtin_repr = repr
+
+reprlib = py.builtin._tryimport('repr', 'reprlib')
+
+if sys.version_info[0] >= 3:
+from traceback import format_exception_only
+else:
+from ._py2traceback import format_exception_only
+
+class 

[pypy-commit] pypy py3.5-ssl: merge py3.5

2016-11-01 Thread plan_rich
Author: Richard Plangger 
Branch: py3.5-ssl
Changeset: r88030:89ea2e4a319d
Date: 2016-11-01 14:36 +0100
http://bitbucket.org/pypy/pypy/changeset/89ea2e4a319d/

Log:merge py3.5

diff too long, truncating to 2000 out of 2128 lines

diff --git a/lib-python/3/test/test_copy.py b/lib-python/3/test/test_copy.py
--- a/lib-python/3/test/test_copy.py
+++ b/lib-python/3/test/test_copy.py
@@ -7,6 +7,7 @@
 from operator import le, lt, ge, gt, eq, ne
 
 import unittest
+from test import support
 
 order_comparisons = le, lt, ge, gt
 equality_comparisons = eq, ne
diff --git a/lib-python/3/test/test_long.py b/lib-python/3/test/test_long.py
--- a/lib-python/3/test/test_long.py
+++ b/lib-python/3/test/test_long.py
@@ -967,7 +967,7 @@
 self.assertIs(type(got), int)
 
 # bad second argument
-bad_exponents = ('brian', 2.0, 0j, None)
+bad_exponents = ('brian', 2.0, 0j)
 for e in bad_exponents:
 self.assertRaises(TypeError, round, 3, e)
 
diff --git a/lib-python/3/test/test_weakset.py 
b/lib-python/3/test/test_weakset.py
--- a/lib-python/3/test/test_weakset.py
+++ b/lib-python/3/test/test_weakset.py
@@ -11,6 +11,7 @@
 from collections import UserString as ustr
 import gc
 import contextlib
+from test import support
 
 
 class Foo:
diff --git a/lib-python/3/test/test_xml_etree.py 
b/lib-python/3/test/test_xml_etree.py
--- a/lib-python/3/test/test_xml_etree.py
+++ b/lib-python/3/test/test_xml_etree.py
@@ -2085,12 +2085,14 @@
 self.assertEqual(self._ilist(doc), all_tags)
 self.assertEqual(self._ilist(doc, '*'), all_tags)
 
+@impl_detail
 def test_copy(self):
 a = ET.Element('a')
 it = a.iter()
 with self.assertRaises(TypeError):
 copy.copy(it)
 
+@impl_detail
 def test_pickle(self):
 a = ET.Element('a')
 it = a.iter()
diff --git a/lib_pypy/_tkinter/tclobj.py b/lib_pypy/_tkinter/tclobj.py
--- a/lib_pypy/_tkinter/tclobj.py
+++ b/lib_pypy/_tkinter/tclobj.py
@@ -160,7 +160,7 @@
 encoded = value.encode('utf-16')[2:]
 buf = tkffi.new("char[]", encoded)
 inbuf = tkffi.cast("Tcl_UniChar*", buf)
-return tklib.Tcl_NewUnicodeObj(inbuf, len(encoded)/2)
+return tklib.Tcl_NewUnicodeObj(inbuf, len(encoded)//2)
 if isinstance(value, Tcl_Obj):
 tklib.Tcl_IncrRefCount(value._value)
 return value._value
diff --git a/lib_pypy/cffi/cparser.py b/lib_pypy/cffi/cparser.py
--- a/lib_pypy/cffi/cparser.py
+++ b/lib_pypy/cffi/cparser.py
@@ -334,6 +334,8 @@
 realtype, quals = self._get_type_and_quals(
 decl.type, name=decl.name, partial_length_ok=True)
 self._declare('typedef ' + decl.name, realtype, 
quals=quals)
+elif decl.__class__.__name__ == 'Pragma':
+pass# skip pragma, only in pycparser 2.15
 else:
 raise api.CDefError("unrecognized construct", decl)
 except api.FFIError as e:
diff --git a/lib_pypy/cffi/model.py b/lib_pypy/cffi/model.py
--- a/lib_pypy/cffi/model.py
+++ b/lib_pypy/cffi/model.py
@@ -519,10 +519,18 @@
 smallest_value = min(self.enumvalues)
 largest_value = max(self.enumvalues)
 else:
-raise api.CDefError("%r has no values explicitly defined: "
-"refusing to guess which integer type it is "
-"meant to be (unsigned/signed, int/long)"
-% self._get_c_name())
+import warnings
+try:
+# XXX!  The goal is to ensure that the warnings.warn()
+# will not suppress the warning.  We want to get it
+# several times if we reach this point several times.
+__warningregistry__.clear()
+except NameError:
+pass
+warnings.warn("%r has no values explicitly defined; "
+  "guessing that it is equivalent to 'unsigned int'"
+  % self._get_c_name())
+smallest_value = largest_value = 0
 if smallest_value < 0:   # needs a signed type
 sign = 1
 candidate1 = PrimitiveType("int")
diff --git a/lib_pypy/cffi/setuptools_ext.py b/lib_pypy/cffi/setuptools_ext.py
--- a/lib_pypy/cffi/setuptools_ext.py
+++ b/lib_pypy/cffi/setuptools_ext.py
@@ -1,4 +1,5 @@
 import os
+import sys
 
 try:
 basestring
@@ -74,8 +75,13 @@
 Add py_limited_api to kwds if setuptools >= 26 is in use.
 Do not alter the setting if it already exists.
 Setuptools takes care of ignoring the flag on Python 2 and PyPy.
+
+CPython itself should ignore the flag in a debugging version
+(by not listing .abi3.so in the extensions it supports), but
+it doesn't so far, creating troubles.  That's why we check
+for "not sys.flags.debug". (http://bugs.python.org/issue28401)