@contextlib.contextmanager<EOL>def transient_internet(resource_name, timeout=<NUM_LIT>, errnos=()):
default_errnos = [<EOL>('<STR_LIT>', <NUM_LIT>),<EOL>('<STR_LIT>', <NUM_LIT>),<EOL>('<STR_LIT>', <NUM_LIT>),<EOL>('<STR_LIT>', <NUM_LIT>),<EOL>('<STR_LIT>', <NUM_LIT>),<EOL>]<EOL>default_gai_errnos = [<EOL>('<STR_LIT>', -<NUM_LIT:2>),<EOL>('<STR_LIT>', -<NUM_LIT:5>),<EOL>]<EOL>denied = ResourceDenied("<STR_LIT>" % resource_name)<EOL>captured_errnos = errnos<EOL>gai_errnos = []<EOL>if not captured_errnos:<EOL><INDENT>captured_errnos = [getattr(errno, name, num)<EOL>for (name, num) in default_errnos]<EOL>gai_errnos = [getattr(socket, name, num)<EOL>for (name, num) in default_gai_errnos]<EOL><DEDENT>def filter_error(err):<EOL><INDENT>n = getattr(err, '<STR_LIT>', None)<EOL>if (isinstance(err, socket.timeout) or<EOL>(isinstance(err, socket.gaierror) and n in gai_errnos) or<EOL>n in captured_errnos):<EOL><INDENT>if not verbose:<EOL><INDENT>sys.stderr.write(denied.args[<NUM_LIT:0>] + "<STR_LIT:\n>")<EOL><DEDENT>raise denied<EOL><DEDENT><DEDENT>old_timeout = socket.getdefaulttimeout()<EOL>try:<EOL><INDENT>if timeout is not None:<EOL><INDENT>socket.setdefaulttimeout(timeout)<EOL><DEDENT>yield<EOL><DEDENT>except IOError as err:<EOL><INDENT>while True:<EOL><INDENT>a = err.args<EOL>if len(a) >= <NUM_LIT:1> and isinstance(a[<NUM_LIT:0>], IOError):<EOL><INDENT>err = a[<NUM_LIT:0>]<EOL><DEDENT>elif len(a) >= <NUM_LIT:2> and isinstance(a[<NUM_LIT:1>], IOError):<EOL><INDENT>err = a[<NUM_LIT:1>]<EOL><DEDENT>else:<EOL><INDENT>break<EOL><DEDENT><DEDENT>filter_error(err)<EOL>raise<EOL><DEDENT>finally:<EOL><INDENT>socket.setdefaulttimeout(old_timeout)<EOL><DEDENT>
Return a context manager that raises ResourceDenied when various issues
    with the Internet connection manifest themselves as exceptions.