Author: Carl Friedrich Bolz-Tereick <[email protected]>
Branch: py3.6
Changeset: r94600:455b5c86ee7b
Date: 2018-05-16 14:38 +0200
http://bitbucket.org/pypy/pypy/changeset/455b5c86ee7b/
Log: merge py3.5
diff --git a/lib-python/conftest.py b/lib-python/conftest.py
--- a/lib-python/conftest.py
+++ b/lib-python/conftest.py
@@ -423,6 +423,7 @@
RegrTest('test_sys_setprofile.py', core=True),
RegrTest('test_sys_settrace.py', core=True),
RegrTest('test_sysconfig.py'),
+ RegrTest('test_sysconfig_pypy.py'),
RegrTest('test_syslog.py'),
RegrTest('test_tarfile.py'),
RegrTest('test_tcl.py'),
diff --git a/pypy/interpreter/astcompiler/test/test_validate.py
b/pypy/interpreter/astcompiler/test/test_validate.py
--- a/pypy/interpreter/astcompiler/test/test_validate.py
+++ b/pypy/interpreter/astcompiler/test/test_validate.py
@@ -1,4 +1,5 @@
import os
+from pytest import raises
from pypy.interpreter.error import OperationError
from pypy.interpreter.baseobjspace import W_Root
from pypy.interpreter.astcompiler import ast
diff --git a/pypy/interpreter/test/test_app_main.py
b/pypy/interpreter/test/test_app_main.py
--- a/pypy/interpreter/test/test_app_main.py
+++ b/pypy/interpreter/test/test_app_main.py
@@ -375,7 +375,7 @@
child.expect('>>>')
def test_atexit(self):
- skip("Python3 atexit is a builtin module")
+ py.test.skip("Python3 atexit is a builtin module")
child = self.spawn([])
child.expect('>>> ')
child.sendline('def f(): print("foobye")')
@@ -525,9 +525,9 @@
def test_options_i_m(self, monkeypatch):
if sys.platform == "win32":
- skip("close_fds is not supported on Windows platforms")
+ py.test.skip("close_fds is not supported on Windows platforms")
if not hasattr(runpy, '_run_module_as_main'):
- skip("requires CPython >= 2.6")
+ py.test.skip("requires CPython >= 2.6")
p = os.path.join(os.path.realpath(os.path.dirname(__file__)),
'mymodule.py')
p = os.path.abspath(p)
monkeypatch.chdir(os.path.dirname(app_main))
@@ -557,7 +557,7 @@
def test_options_u_i(self):
if sys.platform == "win32":
- skip("close_fds is not supported on Windows platforms")
+ py.test.skip("close_fds is not supported on Windows platforms")
import subprocess, select, os
pipe = subprocess.Popen([get_python3(), app_main, "-u", "-i"],
stdout=subprocess.PIPE,
@@ -614,7 +614,7 @@
del os.environ['PYTHONINSPECT_']
def test_stdout_flushes_before_stdin_blocks(self):
- skip("Python3 does not implement this behavior")
+ py.test.skip("Python3 does not implement this behavior")
# This doesn't really test app_main.py, but a behavior that
# can only be checked on top of py.py with pexpect.
path = getscript("""
@@ -632,7 +632,7 @@
def test_no_space_before_argument(self, monkeypatch):
if not hasattr(runpy, '_run_module_as_main'):
- skip("requires CPython >= 2.6")
+ py.test.skip("requires CPython >= 2.6")
child = self.spawn(['-cprint("hel" + "lo")'])
child.expect('hello')
@@ -753,7 +753,7 @@
def test_option_m(self, monkeypatch):
if not hasattr(runpy, '_run_module_as_main'):
- skip("requires CPython >= 2.6")
+ py.test.skip("requires CPython >= 2.6")
p = os.path.join(os.path.realpath(os.path.dirname(__file__)),
'mymodule.py')
p = os.path.abspath(p)
monkeypatch.chdir(os.path.dirname(app_main))
@@ -767,7 +767,7 @@
def test_option_m_package(self, monkeypatch):
if not hasattr(runpy, '_run_module_as_main'):
- skip("requires CPython >= 2.6")
+ py.test.skip("requires CPython >= 2.6")
p = os.path.join(os.path.realpath(os.path.dirname(__file__)),
'mypackage', '__main__.py')
p = os.path.abspath(p)
diff --git a/pypy/interpreter/unicodehelper.py
b/pypy/interpreter/unicodehelper.py
--- a/pypy/interpreter/unicodehelper.py
+++ b/pypy/interpreter/unicodehelper.py
@@ -168,6 +168,222 @@
return decode_utf8(space, string, allow_surrogates=True)
# ____________________________________________________________
+# utf-16
+
+def str_decode_utf_16(s, size, errors, final=True,
+ errorhandler=None):
+ result, length, byteorder = str_decode_utf_16_helper(s, size, errors,
final,
+ errorhandler,
"native",
+ 'utf-16-' +
BYTEORDER2)
+ return result, length
+
+def str_decode_utf_16_be(s, size, errors, final=True,
+ errorhandler=None):
+ result, length, byteorder = str_decode_utf_16_helper(s, size, errors,
final,
+ errorhandler, "big",
+ 'utf-16-be')
+ return result, length
+
+def str_decode_utf_16_le(s, size, errors, final=True,
+ errorhandler=None):
+ result, length, byteorder = str_decode_utf_16_helper(s, size, errors,
final,
+ errorhandler,
"little",
+ 'utf-16-le')
+ return result, length
+
+def str_decode_utf_16_helper(s, size, errors, final=True,
+ errorhandler=None,
+ byteorder="native",
+ public_encoding_name='utf16'):
+ if errorhandler is None:
+ errorhandler = default_unicode_error_decode
+ bo = 0
+
+ if BYTEORDER == 'little':
+ ihi = 1
+ ilo = 0
+ else:
+ ihi = 0
+ ilo = 1
+
+ # Check for BOM marks (U+FEFF) in the input and adjust current
+ # byte order setting accordingly. In native mode, the leading BOM
+ # mark is skipped, in all other modes, it is copied to the output
+ # stream as-is (giving a ZWNBSP character).
+ pos = 0
+ if byteorder == 'native':
+ if size >= 2:
+ bom = (ord(s[ihi]) << 8) | ord(s[ilo])
+ if BYTEORDER == 'little':
+ if bom == 0xFEFF:
+ pos += 2
+ bo = -1
+ elif bom == 0xFFFE:
+ pos += 2
+ bo = 1
+ else:
+ if bom == 0xFEFF:
+ pos += 2
+ bo = 1
+ elif bom == 0xFFFE:
+ pos += 2
+ bo = -1
+ elif byteorder == 'little':
+ bo = -1
+ else:
+ bo = 1
+ if size == 0:
+ return u'', 0, bo
+ if bo == -1:
+ # force little endian
+ ihi = 1
+ ilo = 0
+
+ elif bo == 1:
+ # force big endian
+ ihi = 0
+ ilo = 1
+
+ result = UnicodeBuilder(size // 2)
+
+ #XXX I think the errors are not correctly handled here
+ while pos < size:
+ # remaining bytes at the end? (size should be even)
+ if len(s) - pos < 2:
+ if not final:
+ break
+ r, pos = errorhandler(errors, public_encoding_name,
+ "truncated data",
+ s, pos, len(s))
+ result.append(r)
+ if len(s) - pos < 2:
+ break
+ ch = (ord(s[pos + ihi]) << 8) | ord(s[pos + ilo])
+ pos += 2
+ if ch < 0xD800 or ch > 0xDFFF:
+ result.append(unichr(ch))
+ continue
+ # UTF-16 code pair:
+ if len(s) - pos < 2:
+ pos -= 2
+ if not final:
+ break
+ errmsg = "unexpected end of data"
+ r, pos = errorhandler(errors, public_encoding_name,
+ errmsg, s, pos, len(s))
+ result.append(r)
+ if len(s) - pos < 2:
+ break
+ elif 0xD800 <= ch <= 0xDBFF:
+ ch2 = (ord(s[pos+ihi]) << 8) | ord(s[pos+ilo])
+ pos += 2
+ if 0xDC00 <= ch2 <= 0xDFFF:
+ if MAXUNICODE < 65536:
+ result.append(unichr(ch))
+ result.append(unichr(ch2))
+ else:
+ result.append(UNICHR((((ch & 0x3FF)<<10) |
+ (ch2 & 0x3FF)) + 0x10000))
+ continue
+ else:
+ r, pos = errorhandler(errors, public_encoding_name,
+ "illegal UTF-16 surrogate",
+ s, pos - 4, pos - 2)
+ result.append(r)
+ else:
+ r, pos = errorhandler(errors, public_encoding_name,
+ "illegal encoding",
+ s, pos - 2, pos)
+ result.append(r)
+ return result.build(), pos, bo
+
+def _STORECHAR(result, CH, byteorder):
+ hi = chr(((CH) >> 8) & 0xff)
+ lo = chr((CH) & 0xff)
+ if byteorder == 'little':
+ result.append(lo)
+ result.append(hi)
+ else:
+ result.append(hi)
+ result.append(lo)
+
+def unicode_encode_utf_16_helper(s, size, errors,
+ errorhandler=None,
+ allow_surrogates=True,
+ byteorder='little',
+ public_encoding_name='utf16'):
+ if errorhandler is None:
+ errorhandler = default_unicode_error_encode
+ if size == 0:
+ if byteorder == 'native':
+ result = StringBuilder(2)
+ _STORECHAR(result, 0xFEFF, BYTEORDER)
+ return result.build()
+ return ""
+
+ result = StringBuilder(size * 2 + 2)
+ if byteorder == 'native':
+ _STORECHAR(result, 0xFEFF, BYTEORDER)
+ byteorder = BYTEORDER
+
+ pos = 0
+ while pos < size:
+ ch = ord(s[pos])
+ pos += 1
+
+ if ch < 0xD800:
+ _STORECHAR(result, ch, byteorder)
+ elif ch >= 0x10000:
+ _STORECHAR(result, 0xD800 | ((ch-0x10000) >> 10), byteorder)
+ _STORECHAR(result, 0xDC00 | ((ch-0x10000) & 0x3FF), byteorder)
+ elif ch >= 0xE000 or allow_surrogates:
+ _STORECHAR(result, ch, byteorder)
+ else:
+ ru, rs, pos = errorhandler(errors, public_encoding_name,
+ 'surrogates not allowed',
+ s, pos-1, pos)
+ if rs is not None:
+ # py3k only
+ if len(rs) % 2 != 0:
+ errorhandler('strict', public_encoding_name,
+ 'surrogates not allowed',
+ s, pos-1, pos)
+ result.append(rs)
+ continue
+ for ch in ru:
+ if ord(ch) < 0xD800:
+ _STORECHAR(result, ord(ch), byteorder)
+ else:
+ errorhandler('strict', public_encoding_name,
+ 'surrogates not allowed',
+ s, pos-1, pos)
+ continue
+
+ return result.build()
+
+def unicode_encode_utf_16(s, size, errors,
+ errorhandler=None,
+ allow_surrogates=True):
+ return unicode_encode_utf_16_helper(s, size, errors, errorhandler,
+ allow_surrogates, "native",
+ 'utf-16-' + BYTEORDER2)
+
+def unicode_encode_utf_16_be(s, size, errors,
+ errorhandler=None,
+ allow_surrogates=True):
+ return unicode_encode_utf_16_helper(s, size, errors, errorhandler,
+ allow_surrogates, "big",
+ 'utf-16-be')
+
+def unicode_encode_utf_16_le(s, size, errors,
+ errorhandler=None,
+ allow_surrogates=True):
+ return unicode_encode_utf_16_helper(s, size, errors, errorhandler,
+ allow_surrogates, "little",
+ 'utf-16-le')
+
+
+# ____________________________________________________________
# utf-32
def str_decode_utf_32(s, size, errors, final=True,
diff --git a/pypy/module/_codecs/interp_codecs.py
b/pypy/module/_codecs/interp_codecs.py
--- a/pypy/module/_codecs/interp_codecs.py
+++ b/pypy/module/_codecs/interp_codecs.py
@@ -621,8 +621,6 @@
try:
func = getattr(unicodehelper, impl_name)
except AttributeError:
- if hasattr(runicode, 'py3k_' + impl_name):
- impl_name = 'py3k_' + impl_name
func = getattr(runicode, impl_name)
return func
diff --git a/pypy/objspace/std/test/test_iterobject.py
b/pypy/objspace/std/test/test_iterobject.py
--- a/pypy/objspace/std/test/test_iterobject.py
+++ b/pypy/objspace/std/test/test_iterobject.py
@@ -1,3 +1,4 @@
+import pytest
from pypy.objspace.std.iterobject import W_SeqIterObject
from pypy.interpreter.error import OperationError
@@ -11,8 +12,8 @@
self.body0(w_iter)
def body0(self, w_iter):
- raises(OperationError, self.space.next, w_iter)
- raises(OperationError, self.space.next, w_iter)
+ pytest.raises(OperationError, self.space.next, w_iter)
+ pytest.raises(OperationError, self.space.next, w_iter)
def test_iter(self):
w = self.space.wrap
diff --git a/pypy/objspace/std/test/test_listobject.py
b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -120,8 +120,8 @@
assert self.space.eq_w(self.space.next(w_iter), w(5))
assert self.space.eq_w(self.space.next(w_iter), w(3))
assert self.space.eq_w(self.space.next(w_iter), w(99))
- raises(OperationError, self.space.next, w_iter)
- raises(OperationError, self.space.next, w_iter)
+ py.test.raises(OperationError, self.space.next, w_iter)
+ py.test.raises(OperationError, self.space.next, w_iter)
def test_contains(self):
w = self.space.wrap
diff --git a/pypy/objspace/std/test/test_setstrategies.py
b/pypy/objspace/std/test/test_setstrategies.py
--- a/pypy/objspace/std/test/test_setstrategies.py
+++ b/pypy/objspace/std/test/test_setstrategies.py
@@ -1,3 +1,4 @@
+import pytest
from pypy.objspace.std.setobject import W_SetObject
from pypy.objspace.std.setobject import (
BytesIteratorImplementation, BytesSetStrategy, EmptySetStrategy,
@@ -58,7 +59,7 @@
s1 = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
s2 = W_SetObject(self.space, self.wrapped([4,5, "six", "seven"]))
s3 = s1.intersect(s2)
- skip("for now intersection with ObjectStrategy always results in
another ObjectStrategy")
+ pytest.skip("for now intersection with ObjectStrategy always results
in another ObjectStrategy")
assert s3.strategy is self.space.fromcache(IntegerSetStrategy)
def test_clear(self):
@@ -93,7 +94,7 @@
s1 = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
s1.descr_discard(self.space, self.space.wrap("five"))
- skip("currently not supported")
+ pytest.skip("currently not supported")
assert s1.strategy is self.space.fromcache(IntegerSetStrategy)
set_discard__Set_ANY(self.space, s1, self.space.wrap(FakeInt(5)))
@@ -112,7 +113,7 @@
s1 = W_SetObject(self.space, self.wrapped([1,2,3,4,5]))
assert not s1.has_key(self.space.wrap("five"))
- skip("currently not supported")
+ pytest.skip("currently not supported")
assert s1.strategy is self.space.fromcache(IntegerSetStrategy)
assert s1.has_key(self.space.wrap(FakeInt(2)))
diff --git a/pypy/objspace/std/test/test_tupleobject.py
b/pypy/objspace/std/test/test_tupleobject.py
--- a/pypy/objspace/std/test/test_tupleobject.py
+++ b/pypy/objspace/std/test/test_tupleobject.py
@@ -1,3 +1,4 @@
+import pytest
from pypy.interpreter.error import OperationError
from pypy.objspace.std.tupleobject import W_TupleObject
@@ -42,8 +43,8 @@
assert self.space.eq_w(self.space.next(w_iter), w(5))
assert self.space.eq_w(self.space.next(w_iter), w(3))
assert self.space.eq_w(self.space.next(w_iter), w(99))
- raises(OperationError, self.space.next, w_iter)
- raises(OperationError, self.space.next, w_iter)
+ pytest.raises(OperationError, self.space.next, w_iter)
+ pytest.raises(OperationError, self.space.next, w_iter)
def test_contains(self):
w = self.space.wrap
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit