Author: Amaury Forgeot d'Arc <[email protected]>
Branch: stdlib-2.7.9
Changeset: r75522:d70a221356f9
Date: 2015-01-25 22:55 +0100
http://bitbucket.org/pypy/pypy/changeset/d70a221356f9/
Log: SSLSocket.read() accepts a buffer, and works like a readinto()
diff --git a/pypy/module/_ssl/interp_ssl.py b/pypy/module/_ssl/interp_ssl.py
--- a/pypy/module/_ssl/interp_ssl.py
+++ b/pypy/module/_ssl/interp_ssl.py
@@ -316,7 +316,7 @@
return space.wrap(count)
@unwrap_spec(num_bytes=int)
- def read(self, space, num_bytes):
+ def read(self, space, num_bytes, w_buffer=None):
"""read([len]) -> string
Read up to len bytes from the SSL socket."""
@@ -334,6 +334,12 @@
raise ssl_error(space,
"Socket closed without SSL shutdown handshake")
+ if w_buffer:
+ rwbuffer = space.getarg_w('w*', w_buffer)
+ num_bytes = min(num_bytes, rwbuffer.getlength())
+ else:
+ rwbuffer = None
+
with rffi.scoped_alloc_buffer(num_bytes) as buf:
while True:
err = 0
@@ -347,7 +353,10 @@
sockstate = checkwait(space, self.w_socket, True)
elif (err == SSL_ERROR_ZERO_RETURN and
libssl_SSL_get_shutdown(self.ssl) ==
SSL_RECEIVED_SHUTDOWN):
- return space.wrap("")
+ if rwbuffer:
+ return space.wrap(0)
+ else:
+ return space.wrap("")
else:
sockstate = SOCKET_OPERATION_OK
@@ -366,7 +375,11 @@
result = buf.str(count)
- return space.wrap(result)
+ if rwbuffer:
+ rwbuffer.setslice(0, result)
+ return space.wrap(count)
+ else:
+ return space.wrap(result)
def _refresh_nonblocking(self, space):
# just in case the blocking state of the socket has been changed
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit