summaryrefslogtreecommitdiffstats
path: root/Lib/ssl.py
diff options
context:
space:
mode:
authorChristian Heimes <christian@python.org>2017-09-07 23:59:17 (GMT)
committerGitHub <noreply@github.com>2017-09-07 23:59:17 (GMT)
commit9423f5d68874ff2e500cbe072c25f883cf754be8 (patch)
treedd2a51514097619ac5ccc9fa11339585e7797e59 /Lib/ssl.py
parent6c99b652f7909f86753b9e567ea18c95ee736e83 (diff)
downloadcpython-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/ssl.py')
-rw-r--r--Lib/ssl.py9
1 files changed, 5 insertions, 4 deletions
diff --git a/Lib/ssl.py b/Lib/ssl.py
index 8ad4a33..7a574dc 100644
--- a/Lib/ssl.py
+++ b/Lib/ssl.py
@@ -959,11 +959,12 @@ class SSLSocket(socket):
raise ValueError(
"non-zero flags not allowed in calls to sendall() on %s" %
self.__class__)
- amount = len(data)
count = 0
- while (count < amount):
- v = self.send(data[count:])
- count += v
+ with memoryview(data) as view, view.cast("B") as byte_view:
+ amount = len(byte_view)
+ while count < amount:
+ v = self.send(byte_view[count:])
+ count += v
else:
return socket.sendall(self, data, flags)