diff options
author | Christian Heimes <christian@python.org> | 2017-09-07 23:59:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-07 23:59:17 (GMT) |
commit | 9423f5d68874ff2e500cbe072c25f883cf754be8 (patch) | |
tree | dd2a51514097619ac5ccc9fa11339585e7797e59 /Lib/test/test_ssl.py | |
parent | 6c99b652f7909f86753b9e567ea18c95ee736e83 (diff) | |
download | cpython-9423f5d68874ff2e500cbe072c25f883cf754be8.zip cpython-9423f5d68874ff2e500cbe072c25f883cf754be8.tar.gz cpython-9423f5d68874ff2e500cbe072c25f883cf754be8.tar.bz2 |
[3.6] bpo-27340: Use memoryview in SSLSocket.sendall() (GH-3384) (#3434)
* bpo-27340: Use memoryview in SSLSocket.sendall()
SSLSocket.sendall() now uses memoryview to create slices of data. This fix
support for all bytes-like object. It is also more efficient and avoids
costly copies.
Signed-off-by: Christian Heimes <christian@python.org>
* Cast view to bytes, fix typo
Signed-off-by: Christian Heimes <christian@python.org>.
(cherry picked from commit 888bbdc192ec4db888a294ef758cf5510442dc9a)
Diffstat (limited to 'Lib/test/test_ssl.py')
-rw-r--r-- | Lib/test/test_ssl.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/test/test_ssl.py b/Lib/test/test_ssl.py index 4191d90..157e6ce 100644 --- a/Lib/test/test_ssl.py +++ b/Lib/test/test_ssl.py @@ -18,6 +18,10 @@ import asyncore import weakref import platform import functools +try: + import ctypes +except ImportError: + ctypes = None ssl = support.import_module("ssl") @@ -2882,7 +2886,13 @@ if _have_threads: s.send(data) buffer = bytearray(len(data)) self.assertEqual(s.read(-1, buffer), len(data)) - self.assertEqual(buffer, data) + self.assertEqual(buffer, data) # sendall accepts bytes-like objects + + if ctypes is not None: + ubyte = ctypes.c_ubyte * len(data) + byteslike = ubyte.from_buffer_copy(data) + s.sendall(byteslike) + self.assertEqual(s.read(), data) # Make sure sendmsg et al are disallowed to avoid # inadvertent disclosure of data and/or corruption |