| 68 | | socket_errors_to_ignore = [] |
|---|
| 69 | | # Not all of these names will be defined for every platform. |
|---|
| 70 | | for _ in ("EPIPE", "ETIMEDOUT", "ECONNREFUSED", "ECONNRESET", |
|---|
| 71 | | "EHOSTDOWN", "EHOSTUNREACH", |
|---|
| 72 | | "WSAECONNABORTED", "WSAECONNREFUSED", "WSAECONNRESET", |
|---|
| 73 | | "WSAENETRESET", "WSAETIMEDOUT"): |
|---|
| 74 | | if _ in dir(errno): |
|---|
| 75 | | socket_errors_to_ignore.append(getattr(errno, _)) |
|---|
| 76 | | # de-dupe the list |
|---|
| 77 | | socket_errors_to_ignore = dict.fromkeys(socket_errors_to_ignore).keys() |
|---|
| | 68 | |
|---|
| | 69 | def plat_specific_errors(*errnames): |
|---|
| | 70 | """Return error numbers for all errors in errnames on this platform. |
|---|
| | 71 | |
|---|
| | 72 | The 'errno' module contains different global constants depending on |
|---|
| | 73 | the specific platform (OS). This function will return the list of |
|---|
| | 74 | numeric values for a given list of potential names. |
|---|
| | 75 | """ |
|---|
| | 76 | errno_names = dir(errno) |
|---|
| | 77 | nums = [getattr(errno, k) for k in errnames if k in errno_names] |
|---|
| | 78 | # de-dupe the list |
|---|
| | 79 | return dict.fromkeys(nums).keys() |
|---|
| | 80 | |
|---|
| | 81 | socket_errors_to_ignore = plat_specific_errors( |
|---|
| | 82 | "EPIPE", "ETIMEDOUT", "ECONNREFUSED", "ECONNRESET", |
|---|
| | 83 | "EHOSTDOWN", "EHOSTUNREACH", |
|---|
| | 84 | "WSAECONNABORTED", "WSAECONNREFUSED", "WSAECONNRESET", |
|---|
| | 85 | "WSAENETRESET", "WSAETIMEDOUT") |
|---|