Python errno module availability

While looking at the system library implementation, socket.pyI came across this code

try:
    import errno
except ImportError:
    errno = None
EBADF = getattr(errno, 'EBADF', 9)
EINTR = getattr(errno, 'EINTR', 4)

Is this code just a relic of a bygone age or are there platforms / implementations for which there is no module errno?

To be more explicit, is it safe import errnowithout an exception handler?

I am interested in the answers for both python 2.x and 3.x.

Edit

To clarify the question: I need to check the error codes encoded in the IOErrorexceptions created inside the module socket. The above code, which is in the cpython code database , made me suspicious of known situations in which it socketis available, but import errnofail. Maybe a secondary question, but I would like to avoid unnecessary code.

+4
source share
2 answers

errno Python 1.4. , ENOENT, : errno ifdef. "errno.h" ./configure, (, WinCE), import errno.

, errno=None:

 try:
-    from errno import EBADF
+    import errno
 except ImportError:
-    EBADF = 9
+    errno = None
+EBADF = getattr(errno, 'EBADF', 9)
+EINTR = getattr(errno, 'EINTR', 4)

: from errno import EBADF ImportError, EBADF . , . , import errno CPython .

+1

, , errno . , , python, -Unix-, windows, symbian... python, (, REPL) javascript.

, errno , , , , , , , .

+1

Source: https://habr.com/ru/post/1539764/


All Articles