1. cherrypy
  2. CherryPy

Commits

Robert Brewer  committed db2d04a

New wsgiserver.socket_errors_nonblocking, plus a new plat_specific_errors function to help generate it and socket_errors_to_ignore.

  • Participants
  • Parent commits c78e2dd
  • Branches default

Comments (0)

Files changed (1)

File cherrypy/wsgiserver/__init__.py

View file
  • Ignore whitespace
     SSL = None
 
 import errno
-socket_errors_to_ignore = []
-# Not all of these names will be defined for every platform.
-for _ in ("EPIPE", "ETIMEDOUT", "ECONNREFUSED", "ECONNRESET",
-          "EHOSTDOWN", "EHOSTUNREACH",
-          "WSAECONNABORTED", "WSAECONNREFUSED", "WSAECONNRESET",
-          "WSAENETRESET", "WSAETIMEDOUT"):
-    if _ in dir(errno):
-        socket_errors_to_ignore.append(getattr(errno, _))
-# de-dupe the list
-socket_errors_to_ignore = dict.fromkeys(socket_errors_to_ignore).keys()
+
+def plat_specific_errors(*errnames):
+    """Return error numbers for all errors in errnames on this platform.
+    
+    The 'errno' module contains different global constants depending on
+    the specific platform (OS). This function will return the list of
+    numeric values for a given list of potential names.
+    """
+    errno_names = dir(errno)
+    nums = [getattr(errno, k) for k in errnames if k in errno_names]
+    # de-dupe the list
+    return dict.fromkeys(nums).keys()
+
+socket_errors_to_ignore = plat_specific_errors(
+    "EPIPE", "ETIMEDOUT", "ECONNREFUSED", "ECONNRESET",
+    "EHOSTDOWN", "EHOSTUNREACH",
+    "WSAECONNABORTED", "WSAECONNREFUSED", "WSAECONNRESET",
+    "WSAENETRESET", "WSAETIMEDOUT")
 socket_errors_to_ignore.append("timed out")
 
+socket_errors_nonblocking = plat_specific_errors(
+    'EAGAIN', 'EWOULDBLOCK', 'WSAEWOULDBLOCK')
+
 comma_separated_headers = ['ACCEPT', 'ACCEPT-CHARSET', 'ACCEPT-ENCODING',
     'ACCEPT-LANGUAGE', 'ACCEPT-RANGES', 'ALLOW', 'CACHE-CONTROL',
     'CONNECTION', 'CONTENT-ENCODING', 'CONTENT-LANGUAGE', 'EXPECT',