mirror of
https://github.com/python/cpython.git
synced 2025-08-30 21:48:47 +00:00
Also catch some gaierrors
This commit is contained in:
parent
cc6aac60da
commit
2673c5bf5e
1 changed files with 10 additions and 1 deletions
|
@ -793,16 +793,25 @@ def transient_internet(resource_name, *, timeout=30.0, errnos=()):
|
||||||
('ENETUNREACH', 101),
|
('ENETUNREACH', 101),
|
||||||
('ETIMEDOUT', 110),
|
('ETIMEDOUT', 110),
|
||||||
]
|
]
|
||||||
|
default_gai_errnos = [
|
||||||
|
('EAI_NONAME', -2),
|
||||||
|
('EAI_NODATA', -5),
|
||||||
|
]
|
||||||
|
|
||||||
denied = ResourceDenied("Resource '%s' is not available" % resource_name)
|
denied = ResourceDenied("Resource '%s' is not available" % resource_name)
|
||||||
captured_errnos = errnos
|
captured_errnos = errnos
|
||||||
|
gai_errnos = []
|
||||||
if not captured_errnos:
|
if not captured_errnos:
|
||||||
captured_errnos = [getattr(errno, name, num)
|
captured_errnos = [getattr(errno, name, num)
|
||||||
for (name, num) in default_errnos]
|
for (name, num) in default_errnos]
|
||||||
|
gai_errnos = [getattr(socket, name, num)
|
||||||
|
for (name, num) in default_gai_errnos]
|
||||||
|
|
||||||
def filter_error(err):
|
def filter_error(err):
|
||||||
|
n = getattr(err, 'errno', None)
|
||||||
if (isinstance(err, socket.timeout) or
|
if (isinstance(err, socket.timeout) or
|
||||||
getattr(err, 'errno', None) in captured_errnos):
|
(isinstance(err, socket.gaierror) and n in gai_errnos) or
|
||||||
|
n in captured_errnos):
|
||||||
if not verbose:
|
if not verbose:
|
||||||
sys.stderr.write(denied.args[0] + "\n")
|
sys.stderr.write(denied.args[0] + "\n")
|
||||||
raise denied from err
|
raise denied from err
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue