Use new form of with-statement instead of contextlib.nested().

This commit is contained in:
Raymond Hettinger 2009-06-04 00:11:54 +00:00
parent a678d94d58
commit 686057b8fa
4 changed files with 11 additions and 12 deletions

View file

@ -591,13 +591,11 @@ class TransientResource(object):
raise ResourceDenied("an optional resource is not available")
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)
# Context managers that raise 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)
@contextlib.contextmanager