[pypy-commit] pypy py3.6: merge default into py3.6
mattip
pypy.commits at gmail.com
Thu Aug 15 12:35:48 EDT 2019
Author: Matti Picus <matti.picus at gmail.com>
Branch: py3.6
Changeset: r97187:c5962a500215
Date: 2019-08-15 19:35 +0300
http://bitbucket.org/pypy/pypy/changeset/c5962a500215/
Log: merge default into py3.6
diff --git a/extra_tests/ctypes_tests/test_cast.py b/extra_tests/ctypes_tests/test_cast.py
--- a/extra_tests/ctypes_tests/test_cast.py
+++ b/extra_tests/ctypes_tests/test_cast.py
@@ -30,9 +30,11 @@
assert x.value is True
def test_cast_array():
+ import sys
data = b'data'
ubyte = c_ubyte * len(data)
byteslike = ubyte.from_buffer_copy(data)
m = memoryview(byteslike)
- b = m.cast('B')
- assert bytes(b) == data
+ if sys.version_info > (3, 3):
+ b = m.cast('B')
+ assert bytes(b) == data
diff --git a/lib-python/3.2/test/test_tools.py b/lib-python/3.2/test/test_tools.py
new file mode 100644
--- /dev/null
+++ b/lib-python/3.2/test/test_tools.py
@@ -0,0 +1,433 @@
+"""Tests for scripts in the Tools directory.
+
+This file contains regression tests for some of the scripts found in the
+Tools directory of a Python checkout or tarball, such as reindent.py.
+"""
+
+import os
+import sys
+import imp
+import unittest
+import shutil
+import subprocess
+import sysconfig
+import tempfile
+import textwrap
+from test import support
+from test.script_helper import assert_python_ok, temp_dir
+
+if not sysconfig.is_python_build():
+ # XXX some installers do contain the tools, should we detect that
+ # and run the tests in that case too?
+ raise unittest.SkipTest('test irrelevant for an installed Python')
+
+basepath = os.path.join(os.path.dirname(os.path.dirname(os.path.dirname(__file__))),
+ 'Tools')
+scriptsdir = os.path.join(basepath, 'scripts')
+
+
+class ReindentTests(unittest.TestCase):
+ script = os.path.join(scriptsdir, 'reindent.py')
+
+ def test_noargs(self):
+ assert_python_ok(self.script)
+
+ def test_help(self):
+ rc, out, err = assert_python_ok(self.script, '-h')
+ self.assertEqual(out, b'')
+ self.assertGreater(err, b'')
+
+
+class PindentTests(unittest.TestCase):
+ script = os.path.join(scriptsdir, 'pindent.py')
+
+ def assertFileEqual(self, fn1, fn2):
+ with open(fn1) as f1, open(fn2) as f2:
+ self.assertEqual(f1.readlines(), f2.readlines())
+
+ def pindent(self, source, *args):
+ with subprocess.Popen(
+ (sys.executable, self.script) + args,
+ stdin=subprocess.PIPE, stdout=subprocess.PIPE,
+ universal_newlines=True) as proc:
+ out, err = proc.communicate(source)
+ self.assertIsNone(err)
+ return out
+
+ def lstriplines(self, data):
+ return '\n'.join(line.lstrip() for line in data.splitlines()) + '\n'
+
+ def test_selftest(self):
+ self.maxDiff = None
+ with temp_dir() as directory:
+ data_path = os.path.join(directory, '_test.py')
+ with open(self.script) as f:
+ closed = f.read()
+ with open(data_path, 'w') as f:
+ f.write(closed)
+
+ rc, out, err = assert_python_ok(self.script, '-d', data_path)
+ self.assertEqual(out, b'')
+ self.assertEqual(err, b'')
+ backup = data_path + '~'
+ self.assertTrue(os.path.exists(backup))
+ with open(backup) as f:
+ self.assertEqual(f.read(), closed)
+ with open(data_path) as f:
+ clean = f.read()
+ compile(clean, '_test.py', 'exec')
+ self.assertEqual(self.pindent(clean, '-c'), closed)
+ self.assertEqual(self.pindent(closed, '-d'), clean)
+
+ rc, out, err = assert_python_ok(self.script, '-c', data_path)
+ self.assertEqual(out, b'')
+ self.assertEqual(err, b'')
+ with open(backup) as f:
+ self.assertEqual(f.read(), clean)
+ with open(data_path) as f:
+ self.assertEqual(f.read(), closed)
+
+ broken = self.lstriplines(closed)
+ with open(data_path, 'w') as f:
+ f.write(broken)
+ rc, out, err = assert_python_ok(self.script, '-r', data_path)
+ self.assertEqual(out, b'')
+ self.assertEqual(err, b'')
+ with open(backup) as f:
+ self.assertEqual(f.read(), broken)
+ with open(data_path) as f:
+ indented = f.read()
+ compile(indented, '_test.py', 'exec')
+ self.assertEqual(self.pindent(broken, '-r'), indented)
+
+ def pindent_test(self, clean, closed):
+ self.assertEqual(self.pindent(clean, '-c'), closed)
+ self.assertEqual(self.pindent(closed, '-d'), clean)
+ broken = self.lstriplines(closed)
+ self.assertEqual(self.pindent(broken, '-r', '-e', '-s', '4'), closed)
+
+ def test_statements(self):
+ clean = textwrap.dedent("""\
+ if a:
+ pass
+
+ if a:
+ pass
+ else:
+ pass
+
+ if a:
+ pass
+ elif:
+ pass
+ else:
+ pass
+
+ while a:
+ break
+
+ while a:
+ break
+ else:
+ pass
+
+ for i in a:
+ break
+
+ for i in a:
+ break
+ else:
+ pass
+
+ try:
+ pass
+ finally:
+ pass
+
+ try:
+ pass
+ except TypeError:
+ pass
+ except ValueError:
+ pass
+ else:
+ pass
+
+ try:
+ pass
+ except TypeError:
+ pass
+ except ValueError:
+ pass
+ finally:
+ pass
+
+ with a:
+ pass
+
+ class A:
+ pass
+
+ def f():
+ pass
+ """)
+
+ closed = textwrap.dedent("""\
+ if a:
+ pass
+ # end if
+
+ if a:
+ pass
+ else:
+ pass
+ # end if
+
+ if a:
+ pass
+ elif:
+ pass
+ else:
+ pass
+ # end if
+
+ while a:
+ break
+ # end while
+
+ while a:
+ break
+ else:
+ pass
+ # end while
+
+ for i in a:
+ break
+ # end for
+
+ for i in a:
+ break
+ else:
+ pass
+ # end for
+
+ try:
+ pass
+ finally:
+ pass
+ # end try
+
+ try:
+ pass
+ except TypeError:
+ pass
+ except ValueError:
+ pass
+ else:
+ pass
+ # end try
+
+ try:
+ pass
+ except TypeError:
+ pass
+ except ValueError:
+ pass
+ finally:
+ pass
+ # end try
+
+ with a:
+ pass
+ # end with
+
+ class A:
+ pass
+ # end class A
+
+ def f():
+ pass
+ # end def f
+ """)
+ self.pindent_test(clean, closed)
+
+ def test_multilevel(self):
+ clean = textwrap.dedent("""\
+ def foobar(a, b):
+ if a == b:
+ a = a+1
+ elif a < b:
+ b = b-1
+ if b > a: a = a-1
+ else:
+ print 'oops!'
+ """)
+ closed = textwrap.dedent("""\
+ def foobar(a, b):
+ if a == b:
+ a = a+1
+ elif a < b:
+ b = b-1
+ if b > a: a = a-1
+ # end if
+ else:
+ print 'oops!'
+ # end if
+ # end def foobar
+ """)
+ self.pindent_test(clean, closed)
+
+ def test_preserve_indents(self):
+ clean = textwrap.dedent("""\
+ if a:
+ if b:
+ pass
+ """)
+ closed = textwrap.dedent("""\
+ if a:
+ if b:
+ pass
+ # end if
+ # end if
+ """)
+ self.assertEqual(self.pindent(clean, '-c'), closed)
+ self.assertEqual(self.pindent(closed, '-d'), clean)
+ broken = self.lstriplines(closed)
+ self.assertEqual(self.pindent(broken, '-r', '-e', '-s', '9'), closed)
+ clean = textwrap.dedent("""\
+ if a:
+ \tif b:
+ \t\tpass
+ """)
+ closed = textwrap.dedent("""\
+ if a:
+ \tif b:
+ \t\tpass
+ \t# end if
+ # end if
+ """)
+ self.assertEqual(self.pindent(clean, '-c'), closed)
+ self.assertEqual(self.pindent(closed, '-d'), clean)
+ broken = self.lstriplines(closed)
+ self.assertEqual(self.pindent(broken, '-r'), closed)
+
+ def test_escaped_newline(self):
+ clean = textwrap.dedent("""\
+ class\\
+ \\
+ A:
+ def\
+ \\
+ f:
+ pass
+ """)
+ closed = textwrap.dedent("""\
+ class\\
+ \\
+ A:
+ def\
+ \\
+ f:
+ pass
+ # end def f
+ # end class A
+ """)
+ self.assertEqual(self.pindent(clean, '-c'), closed)
+ self.assertEqual(self.pindent(closed, '-d'), clean)
+
+ def test_empty_line(self):
+ clean = textwrap.dedent("""\
+ if a:
+
+ pass
+ """)
+ closed = textwrap.dedent("""\
+ if a:
+
+ pass
+ # end if
+ """)
+ self.pindent_test(clean, closed)
+
+ def test_oneline(self):
+ clean = textwrap.dedent("""\
+ if a: pass
+ """)
+ closed = textwrap.dedent("""\
+ if a: pass
+ # end if
+ """)
+ self.pindent_test(clean, closed)
+
+
+class TestSundryScripts(unittest.TestCase):
+ # At least make sure the rest don't have syntax errors. When tests are
+ # added for a script it should be added to the whitelist below.
+
+ # scripts that have independent tests.
+ whitelist = ['reindent.py']
+ # scripts that can't be imported without running
+ blacklist = ['make_ctype.py']
+ # scripts that use windows-only modules
+ windows_only = ['win_add2path.py']
+ # blacklisted for other reasons
+ other = ['analyze_dxp.py']
+
+ skiplist = blacklist + whitelist + windows_only + other
+
+ def setUp(self):
+ cm = support.DirsOnSysPath(scriptsdir)
+ cm.__enter__()
+ self.addCleanup(cm.__exit__)
+
+ def test_sundry(self):
+ for fn in os.listdir(scriptsdir):
+ if fn.endswith('.py') and fn not in self.skiplist:
+ __import__(fn[:-3])
+
+ @unittest.skipIf(sys.platform != "win32", "Windows-only test")
+ def test_sundry_windows(self):
+ for fn in self.windows_only:
+ __import__(fn[:-3])
+
+ @unittest.skipIf(not support.threading, "test requires _thread module")
+ def test_analyze_dxp_import(self):
+ if hasattr(sys, 'getdxp'):
+ import analyze_dxp
+ else:
+ with self.assertRaises(RuntimeError):
+ import analyze_dxp
+
+
+class PdepsTests(unittest.TestCase):
+
+ @classmethod
+ def setUpClass(self):
+ path = os.path.join(scriptsdir, 'pdeps.py')
+ self.pdeps = imp.load_source('pdeps', path)
+
+ @classmethod
+ def tearDownClass(self):
+ if 'pdeps' in sys.modules:
+ del sys.modules['pdeps']
+
+ def test_process_errors(self):
+ # Issue #14492: m_import.match(line) can be None.
+ with tempfile.TemporaryDirectory() as tmpdir:
+ fn = os.path.join(tmpdir, 'foo')
+ with open(fn, 'w') as stream:
+ stream.write("#!/this/will/fail")
+ self.pdeps.process(fn, {})
+
+ def test_inverse_attribute_error(self):
+ # Issue #14492: this used to fail with an AttributeError.
+ self.pdeps.inverse({'a': []})
+
+
+def test_main():
+ support.run_unittest(*[obj for obj in globals().values()
+ if isinstance(obj, type)])
+
+
+if __name__ == '__main__':
+ unittest.main()
diff --git a/lib-python/3/test/test_ssl.py b/lib-python/3/test/test_ssl.py
--- a/lib-python/3/test/test_ssl.py
+++ b/lib-python/3/test/test_ssl.py
@@ -2844,6 +2844,10 @@
else:
s.close()
+ def test_socketserver_urlib_uses_bisect(self):
+ b = urllib.request.bisect
+ raise ValueError('urllib.request.bisect is %s' % str(b))
+
def test_socketserver(self):
"""Using socketserver to create and manage SSL connections."""
server = make_https_server(self, certfile=CERTFILE)
diff --git a/lib_pypy/_cffi_ssl/_cffi_src/openssl/nid.py b/lib_pypy/_cffi_ssl/_cffi_src/openssl/nid.py
--- a/lib_pypy/_cffi_ssl/_cffi_src/openssl/nid.py
+++ b/lib_pypy/_cffi_ssl/_cffi_src/openssl/nid.py
@@ -23,6 +23,7 @@
static const int NID_ED448;
static const int NID_poly1305;
+static const int NID_X9_62_prime256v1;
static const int NID_info_access;
static const int NID_subject_alt_name;
static const int NID_crl_distribution_points;
diff --git a/lib_pypy/_cffi_ssl/_cffi_src/openssl/pem.py b/lib_pypy/_cffi_ssl/_cffi_src/openssl/pem.py
--- a/lib_pypy/_cffi_ssl/_cffi_src/openssl/pem.py
+++ b/lib_pypy/_cffi_ssl/_cffi_src/openssl/pem.py
@@ -44,8 +44,6 @@
X509_CRL *PEM_read_bio_X509_CRL(BIO *, X509_CRL **, pem_password_cb *, void *);
-X509 *PEM_read_bio_X509_AUX(BIO *, X509 **, pem_password_cb *, void *);
-
int PEM_write_bio_X509_CRL(BIO *, X509_CRL *);
PKCS7 *PEM_read_bio_PKCS7(BIO *, PKCS7 **, pem_password_cb *, void *);
diff --git a/lib_pypy/_cffi_ssl/_cffi_src/openssl/pypy_win32_extra.py b/lib_pypy/_cffi_ssl/_cffi_src/openssl/pypy_win32_extra.py
new file mode 100644
--- /dev/null
+++ b/lib_pypy/_cffi_ssl/_cffi_src/openssl/pypy_win32_extra.py
@@ -0,0 +1,84 @@
+#
+# An extra bit of logic for the Win32-only functionality that is missing from the
+# version from cryptography.
+#
+
+import sys
+
+INCLUDES = """
+#include <Wincrypt.h>
+"""
+
+TYPES = """
+typedef ... *HCERTSTORE;
+typedef ... *HCRYPTPROV_LEGACY;
+
+typedef struct {
+ DWORD dwCertEncodingType;
+ BYTE *pbCertEncoded;
+ DWORD cbCertEncoded;
+ ...;
+} CERT_CONTEXT, *PCCERT_CONTEXT;
+
+typedef struct {
+ DWORD dwCertEncodingType;
+ BYTE *pbCrlEncoded;
+ DWORD cbCrlEncoded;
+ ...;
+} CRL_CONTEXT, *PCCRL_CONTEXT;
+
+typedef struct {
+ DWORD cUsageIdentifier;
+ LPSTR *rgpszUsageIdentifier;
+ ...;
+} CERT_ENHKEY_USAGE, *PCERT_ENHKEY_USAGE;
+"""
+
+FUNCTIONS = """
+HCERTSTORE WINAPI CertOpenStore(
+ LPCSTR lpszStoreProvider,
+ DWORD dwMsgAndCertEncodingType,
+ HCRYPTPROV_LEGACY hCryptProv,
+ DWORD dwFlags,
+ const char *pvPara
+);
+PCCERT_CONTEXT WINAPI CertEnumCertificatesInStore(
+ HCERTSTORE hCertStore,
+ PCCERT_CONTEXT pPrevCertContext
+);
+BOOL WINAPI CertFreeCertificateContext(
+ PCCERT_CONTEXT pCertContext
+);
+BOOL WINAPI CertFreeCRLContext(
+ PCCRL_CONTEXT pCrlContext
+);
+BOOL WINAPI CertCloseStore(
+ HCERTSTORE hCertStore,
+ DWORD dwFlags
+);
+BOOL WINAPI CertGetEnhancedKeyUsage(
+ PCCERT_CONTEXT pCertContext,
+ DWORD dwFlags,
+ PCERT_ENHKEY_USAGE pUsage,
+ DWORD *pcbUsage
+);
+PCCRL_CONTEXT WINAPI CertEnumCRLsInStore(
+ HCERTSTORE hCertStore,
+ PCCRL_CONTEXT pPrevCrlContext
+);
+"""
+
+MACROS = """
+#define CERT_STORE_READONLY_FLAG ...
+#define CERT_SYSTEM_STORE_LOCAL_MACHINE ...
+#define CRYPT_E_NOT_FOUND ...
+#define CERT_FIND_PROP_ONLY_ENHKEY_USAGE_FLAG ...
+#define CERT_FIND_EXT_ONLY_ENHKEY_USAGE_FLAG ...
+#define X509_ASN_ENCODING ...
+#define PKCS_7_ASN_ENCODING ...
+
+static const LPCSTR CERT_STORE_PROV_SYSTEM_A;
+"""
+
+CUSTOMIZATIONS = """
+"""
diff --git a/lib_pypy/_cffi_ssl/_stdssl/__init__.py b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
--- a/lib_pypy/_cffi_ssl/_stdssl/__init__.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/__init__.py
@@ -82,8 +82,15 @@
if lib.Cryptography_HAS_SSL2:
PROTOCOL_SSLv2 = 0
+SSLv3_method_ok = False
if lib.Cryptography_HAS_SSL3_METHOD:
- PROTOCOL_SSLv3 = 1
+ # Some Ubuntu systems disable SSLv3
+ ctx = lib.SSL_CTX_new(lib.SSLv3_method())
+ if ctx:
+ PROTOCOL_SSLv3 = 1
+ lib.SSL_CTX_free(ctx)
+ SSLv3_method_ok = True
+
PROTOCOL_SSLv23 = 2
PROTOCOL_TLS = PROTOCOL_SSLv23
PROTOCOL_TLSv1 = 3
@@ -857,7 +864,7 @@
method = lib.TLSv1_1_method()
elif lib.Cryptography_HAS_TLSv1_2 and protocol == PROTOCOL_TLSv1_2 :
method = lib.TLSv1_2_method()
- elif lib.Cryptography_HAS_SSL3_METHOD and protocol == PROTOCOL_SSLv3:
+ elif SSLv3_method_ok and protocol == PROTOCOL_SSLv3:
method = lib.SSLv3_method()
elif lib.Cryptography_HAS_SSL2 and protocol == PROTOCOL_SSLv2:
method = lib.SSLv2_method()
@@ -888,7 +895,7 @@
options = lib.SSL_OP_ALL & ~lib.SSL_OP_DONT_INSERT_EMPTY_FRAGMENTS
if not lib.Cryptography_HAS_SSL2 or protocol != PROTOCOL_SSLv2:
options |= lib.SSL_OP_NO_SSLv2
- if not lib.Cryptography_HAS_SSL3_METHOD or protocol != PROTOCOL_SSLv3:
+ if not SSLv3_method_ok or protocol != PROTOCOL_SSLv3:
options |= lib.SSL_OP_NO_SSLv3
# Minimal security flags for server and client side context.
# Client sockets ignore server-side parameters.
diff --git a/lib_pypy/_cffi_ssl/_stdssl/certificate.py b/lib_pypy/_cffi_ssl/_stdssl/certificate.py
--- a/lib_pypy/_cffi_ssl/_stdssl/certificate.py
+++ b/lib_pypy/_cffi_ssl/_stdssl/certificate.py
@@ -296,7 +296,7 @@
lib.BIO_free(cert)
raise ssl_error("Can't open file")
- x = lib.PEM_read_bio_X509_AUX(cert, ffi.NULL, ffi.NULL, ffi.NULL)
+ x = lib.PEM_read_bio_X509(cert, ffi.NULL, ffi.NULL, ffi.NULL)
if x is ffi.NULL:
ssl_error("Error decoding PEM-encoded file")
diff --git a/lib_pypy/_ssl_build.py b/lib_pypy/_ssl_build.py
--- a/lib_pypy/_ssl_build.py
+++ b/lib_pypy/_ssl_build.py
@@ -53,7 +53,6 @@
"callbacks",
] + pypy_win32_extra,
libraries=_get_openssl_libraries(sys.platform),
- extra_compile_args=['-DOPENSSL_NO_SSL3_METHOD'],
extra_link_args=extra_link_args(compiler_type()),
)
More information about the pypy-commit
mailing list