1 __all__ = ['BlockingIOError', 'BrokenPipeError', 'ChildProcessError',
2 'ConnectionRefusedError', 'ConnectionResetError',
3 'InterruptedError', 'ConnectionAbortedError', 'PermissionError',
4 'FileNotFoundError', 'ProcessLookupError',
16 from .compat import PY33
20 BlockingIOError = builtins.BlockingIOError
21 BrokenPipeError = builtins.BrokenPipeError
22 ChildProcessError = builtins.ChildProcessError
23 ConnectionRefusedError = builtins.ConnectionRefusedError
24 ConnectionResetError = builtins.ConnectionResetError
25 InterruptedError = builtins.InterruptedError
26 ConnectionAbortedError = builtins.ConnectionAbortedError
27 PermissionError = builtins.PermissionError
28 FileNotFoundError = builtins.FileNotFoundError
29 ProcessLookupError = builtins.ProcessLookupError
33 class BlockingIOError(OSError):
36 class BrokenPipeError(OSError):
39 class ChildProcessError(OSError):
42 class ConnectionRefusedError(OSError):
45 class InterruptedError(OSError):
48 class ConnectionResetError(OSError):
51 class ConnectionAbortedError(OSError):
54 class PermissionError(OSError):
57 class FileNotFoundError(OSError):
60 class ProcessLookupError(OSError):
65 errno.EACCES: PermissionError,
66 errno.EAGAIN: BlockingIOError,
67 errno.EALREADY: BlockingIOError,
68 errno.ECHILD: ChildProcessError,
69 errno.ECONNABORTED: ConnectionAbortedError,
70 errno.ECONNREFUSED: ConnectionRefusedError,
71 errno.ECONNRESET: ConnectionResetError,
72 errno.EINPROGRESS: BlockingIOError,
73 errno.EINTR: InterruptedError,
74 errno.ENOENT: FileNotFoundError,
75 errno.EPERM: PermissionError,
76 errno.EPIPE: BrokenPipeError,
77 errno.ESHUTDOWN: BrokenPipeError,
78 errno.EWOULDBLOCK: BlockingIOError,
79 errno.ESRCH: ProcessLookupError,
82 if sys.platform == 'win32':
83 from trollius import _overlapped
85 _overlapped.ERROR_CONNECTION_REFUSED: ConnectionRefusedError,
86 _overlapped.ERROR_CONNECTION_ABORTED: ConnectionAbortedError,
87 _overlapped.ERROR_NETNAME_DELETED: ConnectionResetError,
91 def get_error_class(key, default):
92 return _MAP_ERRNO.get(key, default)
95 if sys.version_info >= (3,):
96 def reraise(tp, value, tb=None):
97 if value.__traceback__ is not tb:
98 raise value.with_traceback(tb)
101 exec("""def reraise(tp, value, tb=None):
106 def _wrap_error(exc, mapping, key):
107 if key not in mapping:
109 new_err_cls = mapping[key]
110 new_err = new_err_cls(*exc.args)
112 # raise a new exception with the original traceback
113 if hasattr(exc, '__traceback__'):
114 traceback = exc.__traceback__
116 traceback = sys.exc_info()[2]
117 reraise(new_err_cls, new_err, traceback)
121 def wrap_error(func, *args, **kw):
123 Wrap socket.error, IOError, OSError, select.error to raise new specialized
124 exceptions of Python 3.3 like InterruptedError (PEP 3151).
127 return func(*args, **kw)
128 except (socket.error, IOError, OSError) as exc:
129 if ssl is not None and isinstance(exc, ssl.SSLError):
131 if hasattr(exc, 'winerror'):
132 _wrap_error(exc, _MAP_ERRNO, exc.winerror)
133 # _MAP_ERRNO does not contain all Windows errors.
134 # For some errors like "file not found", exc.errno should
135 # be used (ex: ENOENT).
136 _wrap_error(exc, _MAP_ERRNO, exc.errno)
138 except select.error as exc:
140 _wrap_error(exc, _MAP_ERRNO, exc.args[0])
143 def wrap_error(func, *args, **kw):
144 return func(*args, **kw)