From: Nick Coghlan Date: Sun, 18 Oct 2009 10:29:10 +0000 (+0000) Subject: Silence a deprecation warning by using the appropriate replacement construct X-Git-Tag: v2.7a1~312 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f317019c079d2bb4646a1cde1785c73880b50d00;p=python Silence a deprecation warning by using the appropriate replacement construct --- diff --git a/Lib/test/test_support.py b/Lib/test/test_support.py index 048c527db9..d97e150c34 100644 --- a/Lib/test/test_support.py +++ b/Lib/test/test_support.py @@ -630,13 +630,15 @@ class TransientResource(object): raise ResourceDenied("an optional resource is not available") +@contextlib.contextmanager def transient_internet(): """Return a context manager that raises ResourceDenied when various issues with the Internet connection manifest themselves as exceptions.""" time_out = TransientResource(IOError, errno=errno.ETIMEDOUT) socket_peer_reset = TransientResource(socket.error, errno=errno.ECONNRESET) ioerror_peer_reset = TransientResource(IOError, errno=errno.ECONNRESET) - return contextlib.nested(time_out, socket_peer_reset, ioerror_peer_reset) + with time_out, socket_peer_reset, ioerror_peer_reset: + yield @contextlib.contextmanager