Skip to content

Commit 38077d1

Browse files
committed
Fix Async import problem on Posix
Windows only seems to return WSAE* errors, so we need to check for these errors on Windows. However the WSAE* error definitions only exist on Windows, they do not exist on Posix. Trying to import them causes a failure on Posix. On Posix, we now just reassign the WSAE* error values to the normal E* values, letting the code compile.
1 parent 7031989 commit 38077d1

File tree

1 file changed

+18
-3
lines changed

1 file changed

+18
-3
lines changed

Lib/asyncore.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,24 @@
5555
import os
5656
from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \
5757
ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \
58-
errorcode, \
59-
WSAEWOULDBLOCK, WSAENOTCONN, WSAEINPROGRESS, WSAEALREADY, WSAEISCONN, \
60-
WSAECONNABORTED, WSAENOTCONN, WSAEBADF
58+
errorcode
59+
60+
if sys.platform[:3] == 'win':
61+
# On Windows, handle the Windows error numbers
62+
from errno import \
63+
WSAEWOULDBLOCK, WSAENOTCONN, WSAEINPROGRESS, WSAEALREADY, WSAEISCONN, \
64+
WSAECONNABORTED, WSAENOTCONN, WSAEBADF
65+
else:
66+
# On Posix the error codes aren't duplicated, with different numbers
67+
WSAEWOULDBLOCK = EWOULDBLOCK
68+
WSAENOTCONN = ENOTCONN
69+
WSAEINPROGRESS = EINPROGRESS
70+
WSAEALREADY = EALREADY
71+
WSAEISCONN = EISCONN
72+
WSAECONNABORTED = ECONNABORTED
73+
WSAENOTCONN = ENOTCONN
74+
WSAEBADF = EBADF
75+
6176

6277
_DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE,
6378
EBADF, WSAENOTCONN, WSAECONNABORTED, WSAEBADF))

0 commit comments

Comments
 (0)