[Python-checkins] r81678 - in python/trunk: Lib/test/test_support.py Misc/NEWS
r.david.murray
python-checkins at python.org
Thu Jun 3 22:19:25 CEST 2010
Author: r.david.murray
Date: Thu Jun 3 22:19:25 2010
New Revision: 81678
Log:
#8889: rewrite transient_internet so we don't use EAI_NODATA on FreeBSD.
FreeBSD doesn't have socket.EAI_NODATA. I rewrote the routine because
there's no easy way to conditionally include a context manager in a
with statement. As a side benefit, instead of a stack of context
managers there's now only one.
Modified:
python/trunk/Lib/test/test_support.py
python/trunk/Misc/NEWS
Modified: python/trunk/Lib/test/test_support.py
==============================================================================
--- python/trunk/Lib/test/test_support.py (original)
+++ python/trunk/Lib/test/test_support.py Thu Jun 3 22:19:25 2010
@@ -750,17 +750,32 @@
raise ResourceDenied("an optional resource is not available")
+_transients = {
+ IOError: (errno.ECONNRESET, errno.ETIMEDOUT),
+ socket.error: (errno.ECONNRESET,),
+ socket.gaierror: [getattr(socket, t)
+ for t in ('EAI_NODATA', 'EAI_NONAME')
+ if hasattr(socket, t)],
+ }
@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)
- dns_nodata = TransientResource(socket.gaierror, errno=socket.EAI_NODATA)
- dns_noname = TransientResource(socket.gaierror, errno=socket.EAI_NONAME)
- with time_out, socket_peer_reset, ioerror_peer_reset, dns_nodata, dns_noname:
+ with the Internet connection manifest themselves as exceptions.
+
+ Errors caught:
+ timeout IOError errno = ETIMEDOUT
+ socket reset socket.error, IOError errno = ECONNRESET
+ dns no data socket.gaierror errno = EAI_NODATA
+ dns no name socket.gaierror errno = EAI_NONAME
+ """
+ try:
yield
+ except tuple(_transients) as err:
+ for errtype in _transients:
+ if isinstance(err, errtype) and err.errno in _transients[errtype]:
+ raise ResourceDenied("could not establish network "
+ "connection ({})".format(err))
+ raise
@contextlib.contextmanager
Modified: python/trunk/Misc/NEWS
==============================================================================
--- python/trunk/Misc/NEWS (original)
+++ python/trunk/Misc/NEWS Thu Jun 3 22:19:25 2010
@@ -105,7 +105,10 @@
Tests
-----
-- Issue #8835: test_support.transient_internet() catchs gaierror(EAI_NONAME)
+- Issue #8889: test_support.transient_internet rewritten so that the new
+ checks also work on FreeBSD, which lacks EAI_NODATA.
+
+- Issue #8835: test_support.transient_internet() catches gaierror(EAI_NONAME)
and gaierror(EAI_NODATA)
- Issue #7449: Skip test_socketserver if threading support is disabled
More information about the Python-checkins
mailing list