[pypy-commit] pypy py3k: Fix ssl.read() when a buffer is passed and 0 bytes are read.
amauryfa
noreply at buildbot.pypy.org
Sun Dec 9 22:59:02 CET 2012
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3k
Changeset: r59379:7e232bb78c20
Date: 2012-12-09 18:04 +0100
http://bitbucket.org/pypy/pypy/changeset/7e232bb78c20/
Log: Fix ssl.read() when a buffer is passed and 0 bytes are read.
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
@@ -417,7 +417,10 @@
raise ssl_error(space, "Underlying socket too large for select().")
elif sockstate == SOCKET_HAS_BEEN_CLOSED:
if libssl_SSL_get_shutdown(self.ssl) == SSL_RECEIVED_SHUTDOWN:
- return space.wrapbytes('')
+ if space.is_none(w_buf):
+ return space.wrapbytes('')
+ else:
+ return space.wrap(0)
raise ssl_error(space, "Socket closed without SSL shutdown handshake")
rwbuffer = None
@@ -441,7 +444,10 @@
space, w_socket, True)
elif (err == SSL_ERROR_ZERO_RETURN and
libssl_SSL_get_shutdown(self.ssl) == SSL_RECEIVED_SHUTDOWN):
- return space.wrapbytes('')
+ if space.is_none(w_buf):
+ return space.wrapbytes('')
+ else:
+ return space.wrap(0)
else:
sockstate = SOCKET_OPERATION_OK
diff --git a/pypy/module/_ssl/test/test_ssl.py b/pypy/module/_ssl/test/test_ssl.py
--- a/pypy/module/_ssl/test/test_ssl.py
+++ b/pypy/module/_ssl/test/test_ssl.py
@@ -1,7 +1,7 @@
from pypy.tool.udir import udir
class AppTestSSL:
- spaceconfig = dict(usemodules=('_ssl', '_socket'))
+ spaceconfig = dict(usemodules=('_ssl', '_socket', 'binascii'))
def test_init_module(self):
import _ssl
@@ -129,6 +129,8 @@
b = bytearray(8)
read = ss.read(10, b)
assert read == 8
+ read = ss.read(10, b)
+ assert read == 0
self.s.close()
del ss; gc.collect()
More information about the pypy-commit
mailing list