diff options
author | Victor Stinner <victor.stinner@gmail.com> | 2014-01-04 01:55:46 +0100 |
---|---|---|
committer | Victor Stinner <victor.stinner@gmail.com> | 2014-01-04 01:55:46 +0100 |
commit | 59d4fc79033c0344a5832f301f6ab07839c00018 (patch) | |
tree | 5a2595eae60caabb9ffcc978746ac183a64e4b8d | |
parent | d7a38623e7015c6aae0978b86ad68c0349d6ce81 (diff) | |
download | trollius-59d4fc79033c0344a5832f301f6ab07839c00018.tar.gz |
wrap_ssl_error() now keeps the original traceback
-rw-r--r-- | asyncio/backport.py | 13 | ||||
-rw-r--r-- | asyncio/backport_ssl.py | 22 |
2 files changed, 15 insertions, 20 deletions
diff --git a/asyncio/backport.py b/asyncio/backport.py index 2270b39..5a9e7b9 100644 --- a/asyncio/backport.py +++ b/asyncio/backport.py @@ -35,9 +35,6 @@ __builtins__['ConnectionResetError'] = ConnectionResetError __builtins__['ConnectionRefusedError'] = ConnectionRefusedError __builtins__['ConnectionAbortedError'] = ConnectionAbortedError -_BLOCKING_ERRORS = set(( -)) - _MAP_ERRNO = { errno.ECHILD: ChildProcessError, errno.EINTR: InterruptedError, @@ -50,10 +47,10 @@ _MAP_ERRNO = { errno.EPIPE: BrokenPipeError, } -def _wrap_errno(number, err_args): - if number not in _MAP_ERRNO: +def _wrap_error(mapping, key, err_args): + if key not in mapping: return - new_err_cls = _MAP_ERRNO[number] + new_err_cls = mapping[key] new_err = new_err_cls(err_args) # raise a new exception with the original traceback @@ -68,9 +65,9 @@ def wrap_error(func, *args, **kw): try: return func(*args, **kw) except (socket.error, IOError, OSError) as err: - _wrap_errno(err.errno, err.args) + _wrap_error(_MAP_ERRNO, err.errno, err.args) raise except select.error as err: - _wrap_errno(err.args[0], err.args) + _wrap_error(_MAP_ERRNO, err.args[0], err.args) raise diff --git a/asyncio/backport_ssl.py b/asyncio/backport_ssl.py index 14ec96b..c6c38a4 100644 --- a/asyncio/backport_ssl.py +++ b/asyncio/backport_ssl.py @@ -1,4 +1,5 @@ import ssl +from asyncio.backport import _wrap_error # SSL constants copied from /usr/include/openssl/ssl.h of Fedora 19 #define SSL_ERROR_ZERO_RETURN 6 @@ -40,19 +41,16 @@ ssl.SSLWantReadError = SSLWantReadError ssl.SSLWantWriteError = SSLWantWriteError ssl.SSLContext = SSLContext +_MAP_ERRORS = { + ssl.SSL_ERROR_WANT_READ: SSLWantReadError, + ssl.SSL_ERROR_WANT_WRITE: SSLWantWriteError, + ssl.SSL_ERROR_EOF: SSLEOFError, +} + def wrap_ssl_error(func, *args, **kw): try: return func(*args, **kw) except ssl.SSLError as err: - if not err.args: - raise - code = err.args[0] - # FIXME: keep original traceback - if code == ssl.SSL_ERROR_WANT_READ: - raise SSLWantReadError(*err.args) - elif code == ssl.SSL_ERROR_WANT_WRITE: - raise SSLWantWriteError(*err.args) - elif code == ssl.SSL_ERROR_EOF: - raise SSLEOFError(*err.args) - else: - raise + if err.args: + _wrap_error(_MAP_ERRORS, err.args[0], err.args) + raise |