diff options
author | Christian Heimes <christian@python.org> | 2017-09-07 21:18:21 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-09-07 21:18:21 (GMT) |
commit | 888bbdc192ec4db888a294ef758cf5510442dc9a (patch) | |
tree | 3b4be0554916502e37ef83efd8ea7e11e6ef8c70 /Lib/ssl.py | |
parent | 17c9ac927b97472dd080174fde709d9234848195 (diff) | |
download | cpython-888bbdc192ec4db888a294ef758cf5510442dc9a.zip cpython-888bbdc192ec4db888a294ef758cf5510442dc9a.tar.gz cpython-888bbdc192ec4db888a294ef758cf5510442dc9a.tar.bz2 |
bpo-27340: Use memoryview in SSLSocket.sendall() (#3384)
* 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>
Diffstat (limited to 'Lib/ssl.py')
-rw-r--r-- | Lib/ssl.py | 9 |
1 files changed, 5 insertions, 4 deletions
@@ -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) |