Commit 077812b2 authored by Daniel Campora's avatar Daniel Campora
Browse files

py: Add TimeoutError exception subclassed from OSError.

The TimeoutError is useful for some modules, specially the the
socket module. TimeoutError can then be alised to socket.timeout
and then Python code can differentiate between socket.error and
socket.timeout.
parent bdf958df
......@@ -462,6 +462,11 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_RANGE_ATTRS (1)
#endif
// Whether to support timeout exceptions (like socket.timeout)
#ifndef MICROPY_PY_BUILTINS_TIMEOUTERROR
#define MICROPY_PY_BUILTINS_TIMEOUTERROR (0)
#endif
// Whether to support complete set of special methods
// for user classes, otherwise only the most used
#ifndef MICROPY_PY_ALL_SPECIAL_METHODS
......
......@@ -426,6 +426,7 @@ extern const mp_obj_type_t mp_type_MemoryError;
extern const mp_obj_type_t mp_type_NameError;
extern const mp_obj_type_t mp_type_NotImplementedError;
extern const mp_obj_type_t mp_type_OSError;
extern const mp_obj_type_t mp_type_TimeoutError;
extern const mp_obj_type_t mp_type_OverflowError;
extern const mp_obj_type_t mp_type_RuntimeError;
extern const mp_obj_type_t mp_type_StopIteration;
......
......@@ -221,8 +221,11 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
MP_DEFINE_EXCEPTION(UnboundLocalError, NameError)
*/
MP_DEFINE_EXCEPTION(OSError, Exception)
/*
#if MICROPY_PY_BUILTINS_TIMEOUTERROR
MP_DEFINE_EXCEPTION_BASE(OSError)
MP_DEFINE_EXCEPTION(TimeoutError, OSError)
#endif
/*
MP_DEFINE_EXCEPTION(BlockingIOError, OSError)
MP_DEFINE_EXCEPTION(ChildProcessError, OSError)
MP_DEFINE_EXCEPTION(ConnectionError, OSError)
......@@ -235,7 +238,6 @@ MP_DEFINE_EXCEPTION(Exception, BaseException)
MP_DEFINE_EXCEPTION(NotADirectoryError, OSError)
MP_DEFINE_EXCEPTION(PermissionError, OSError)
MP_DEFINE_EXCEPTION(ProcessLookupError, OSError)
MP_DEFINE_EXCEPTION(TimeoutError, OSError)
MP_DEFINE_EXCEPTION(FileExistsError, OSError)
MP_DEFINE_EXCEPTION(FileNotFoundError, OSError)
MP_DEFINE_EXCEPTION(ReferenceError, Exception)
......
......@@ -140,6 +140,9 @@ Q(MemoryError)
Q(NameError)
Q(NotImplementedError)
Q(OSError)
#if MICROPY_PY_BUILTINS_TIMEOUTERROR
Q(TimeoutError)
#endif
Q(OverflowError)
Q(RuntimeError)
Q(SyntaxError)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment