From 38077d109cd35acb0c8ae3e50aa82a7d0505b69d Mon Sep 17 00:00:00 2001 From: Frederick Price Date: Wed, 26 Jun 2024 16:39:03 -0400 Subject: [PATCH] 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. --- Lib/asyncore.py | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) diff --git a/Lib/asyncore.py b/Lib/asyncore.py index 3134ddb6164c1e..9909a6dd63d4a0 100644 --- a/Lib/asyncore.py +++ b/Lib/asyncore.py @@ -55,9 +55,24 @@ import os from errno import EALREADY, EINPROGRESS, EWOULDBLOCK, ECONNRESET, EINVAL, \ ENOTCONN, ESHUTDOWN, EINTR, EISCONN, EBADF, ECONNABORTED, EPIPE, EAGAIN, \ - errorcode, \ - WSAEWOULDBLOCK, WSAENOTCONN, WSAEINPROGRESS, WSAEALREADY, WSAEISCONN, \ - WSAECONNABORTED, WSAENOTCONN, WSAEBADF + errorcode + +if sys.platform[:3] == 'win': + # On Windows, handle the Windows error numbers + from errno import \ + WSAEWOULDBLOCK, WSAENOTCONN, WSAEINPROGRESS, WSAEALREADY, WSAEISCONN, \ + WSAECONNABORTED, WSAENOTCONN, WSAEBADF +else: + # On Posix the error codes aren't duplicated, with different numbers + WSAEWOULDBLOCK = EWOULDBLOCK + WSAENOTCONN = ENOTCONN + WSAEINPROGRESS = EINPROGRESS + WSAEALREADY = EALREADY + WSAEISCONN = EISCONN + WSAECONNABORTED = ECONNABORTED + WSAENOTCONN = ENOTCONN + WSAEBADF = EBADF + _DISCONNECTED = frozenset((ECONNRESET, ENOTCONN, ESHUTDOWN, ECONNABORTED, EPIPE, EBADF, WSAENOTCONN, WSAECONNABORTED, WSAEBADF))