bpo-36629: Add support.get_socket_conn_refused_errs() (GH-12834) · python/cpython@3c7931e (original) (raw)

`@@ -1477,6 +1477,22 @@ def exit(self, type_=None, value=None, traceback=None):

`

1477

1477

`ioerror_peer_reset = TransientResource(OSError, errno=errno.ECONNRESET)

`

1478

1478

``

1479

1479

``

``

1480

`+

def get_socket_conn_refused_errs():

`

``

1481

`+

"""

`

``

1482

`+

Get the different socket error numbers ('errno') which can be received

`

``

1483

`+

when a connection is refused.

`

``

1484

`+

"""

`

``

1485

`+

errors = [errno.ECONNREFUSED]

`

``

1486

`+

if hasattr(errno, 'ENETUNREACH'):

`

``

1487

`+

On Solaris, ENETUNREACH is returned sometimes instead of ECONNREFUSED

`

``

1488

`+

errors.append(errno.ENETUNREACH)

`

``

1489

`+

if hasattr(errno, 'EADDRNOTAVAIL'):

`

``

1490

`+

bpo-31910: socket.create_connection() fails randomly

`

``

1491

`+

with EADDRNOTAVAIL on Travis CI

`

``

1492

`+

errors.append(errno.EADDRNOTAVAIL)

`

``

1493

`+

return errors

`

``

1494

+

``

1495

+

1480

1496

`@contextlib.contextmanager

`

1481

1497

`def transient_internet(resource_name, *, timeout=30.0, errnos=()):

`

1482

1498

`"""Return a context manager that raises ResourceDenied when various issues

`