diff options
author | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-02-02 06:40:54 -0800 |
---|---|---|
committer | Jean-Paul Calderone <exarkun@twistedmatrix.com> | 2014-02-02 06:40:54 -0800 |
commit | ce27d79ec1d93dd428d09f5e6df79b12534423a3 (patch) | |
tree | e4cd1d95ad08951387bed3e9c1be3c16438f11f8 | |
parent | df454990b0c25a7a39d717328f384eb71128aba3 (diff) | |
parent | 541150de73400d0fea36e241ea76a34596996347 (diff) | |
download | pyopenssl-ce27d79ec1d93dd428d09f5e6df79b12534423a3.tar.gz |
Merge pull request #25 from longaccess/fix_test_closed
Use `getwinerror` to look up a syscall error code on Windows. Fixes `test_closed` on Windows.
-rw-r--r-- | OpenSSL/SSL.py | 9 | ||||
-rw-r--r-- | OpenSSL/test/test_ssl.py | 7 |
2 files changed, 11 insertions, 5 deletions
diff --git a/OpenSSL/SSL.py b/OpenSSL/SSL.py index ce2cc29..811c4de 100644 --- a/OpenSSL/SSL.py +++ b/OpenSSL/SSL.py @@ -1,4 +1,4 @@ - +from sys import platform from functools import wraps, partial from itertools import count from weakref import WeakValueDictionary @@ -856,8 +856,11 @@ class Connection(object): elif error == _lib.SSL_ERROR_SYSCALL: if _lib.ERR_peek_error() == 0: if result < 0: - raise SysCallError( - _ffi.errno, errorcode[_ffi.errno]) + if platform == "win32": + errno = _ffi.getwinerror()[0] + else: + errno = _ffi.errno + raise SysCallError(errno, errorcode[errno]) else: raise SysCallError(-1, "Unexpected EOF") else: diff --git a/OpenSSL/test/test_ssl.py b/OpenSSL/test/test_ssl.py index e366b47..e3518c5 100644 --- a/OpenSSL/test/test_ssl.py +++ b/OpenSSL/test/test_ssl.py @@ -6,7 +6,7 @@ Unit tests for :py:obj:`OpenSSL.SSL`. """ from gc import collect, get_referrers -from errno import ECONNREFUSED, EINPROGRESS, EWOULDBLOCK, EPIPE +from errno import ECONNREFUSED, EINPROGRESS, EWOULDBLOCK, EPIPE, ESHUTDOWN from sys import platform, version_info from socket import SHUT_RDWR, error, socket from os import makedirs @@ -1935,7 +1935,10 @@ class ConnectionSendallTests(TestCase, _LoopbackMixin): server, client = self._loopback() server.sock_shutdown(2) exc = self.assertRaises(SysCallError, server.sendall, b"hello, world") - self.assertEqual(exc.args[0], EPIPE) + if platform == "win32": + self.assertEqual(exc.args[0], ESHUTDOWN) + else: + self.assertEqual(exc.args[0], EPIPE) |