[pypy-svn] pypy default: Maybe fix test_ftplib: a closed socket doesn't raise an exception on s.fileno(), it just returns -1
amauryfa
commits-noreply at bitbucket.org
Thu Jan 27 20:49:53 CET 2011
Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch:
Changeset: r41411:59a012e9c775
Date: 2011-01-27 20:49 +0100
http://bitbucket.org/pypy/pypy/changeset/59a012e9c775/
Log: Maybe fix test_ftplib: a closed socket doesn't raise an exception on
s.fileno(), it just returns -1
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
@@ -70,6 +70,16 @@
else:
assert exc.value.errno == 32 # Broken pipe
+ def test_async_closed(self):
+ import _ssl, _socket
+ s = _socket.socket()
+ s.settimeout(3)
+ ss = _ssl.sslwrap(s, 0)
+ s.close()
+ exc = raises(_ssl.SSLError, ss.write, "data")
+ assert exc.value.message == "Underlying socket has been closed."
+
+
class AppTestConnectedSSL:
def setup_class(cls):
space = gettestobjspace(usemodules=('_ssl', '_socket'))
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
@@ -459,13 +459,12 @@
return SOCKET_IS_NONBLOCKING
sock_timeout = space.float_w(w_timeout)
+ sock_fd = space.int_w(space.call_method(w_sock, "fileno"))
+
# guard against closed socket
- try:
- space.call_method(w_sock, "fileno")
- except:
+ if sock_fd < 0:
return SOCKET_HAS_BEEN_CLOSED
- sock_fd = space.int_w(space.call_method(w_sock, "fileno"))
# see if the socket is ready
More information about the Pypy-commit
mailing list