summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFacundo Batista <facundobatista@gmail.com>2008-06-07 13:36:36 (GMT)
committerFacundo Batista <facundobatista@gmail.com>2008-06-07 13:36:36 (GMT)
commit6a5a177cba3aa36e53438901a1a52149b9010e92 (patch)
tree37bd4bda566371a73260ab4a64bb641134ba2991
parent0144f27602944fb1ef6cb561333f65fef50e79cc (diff)
downloadcpython-6a5a177cba3aa36e53438901a1a52149b9010e92.zip
cpython-6a5a177cba3aa36e53438901a1a52149b9010e92.tar.gz
cpython-6a5a177cba3aa36e53438901a1a52149b9010e92.tar.bz2
Finished bug #2451. Fixed the retrying part to make it
more robust.
-rw-r--r--Lib/test/test_urllib2net.py24
1 files changed, 16 insertions, 8 deletions
diff --git a/Lib/test/test_urllib2net.py b/Lib/test/test_urllib2net.py
index ee21c55..3d01b31 100644
--- a/Lib/test/test_urllib2net.py
+++ b/Lib/test/test_urllib2net.py
@@ -11,18 +11,24 @@ import os
import mimetools
-def _urlopen_with_retry(host, *args, **kwargs):
- # Connecting to remote hosts is flaky. Make it more robust
- # by retrying the connection several times.
+def _retry_thrice(func, exc, *args, **kwargs):
for i in range(3):
try:
- return urllib2.urlopen(host, *args, **kwargs)
- except urllib2.URLError, last_exc:
+ return func(*args, **kwargs)
+ except exc, last_exc:
continue
except:
raise
raise last_exc
+def _wrap_with_retry_thrice(func, exc):
+ def wrapped(*args, **kwargs):
+ return _retry_thrice(func, exc, *args, **kwargs)
+ return wrapped
+
+# Connecting to remote hosts is flaky. Make it more robust by retrying
+# the connection several times.
+_urlopen_with_retry = _wrap_with_retry_thrice(urllib2.urlopen, urllib2.URLError)
class AuthTests(unittest.TestCase):
@@ -115,7 +121,7 @@ class OtherNetworkTests(unittest.TestCase):
'file:'+sanepathname2url(os.path.abspath(TESTFN)),
('file:///nonsensename/etc/passwd', None, urllib2.URLError),
]
- self._test_urls(urls, self._extra_handlers(), urllib2.urlopen)
+ self._test_urls(urls, self._extra_handlers(), retry=True)
finally:
os.remove(TESTFN)
@@ -147,13 +153,15 @@ class OtherNetworkTests(unittest.TestCase):
## self._test_urls(urls, self._extra_handlers()+[bauth, dauth])
- def _test_urls(self, urls, handlers, urlopen=_urlopen_with_retry):
+ def _test_urls(self, urls, handlers, retry=True):
import socket
import time
import logging
debug = logging.getLogger("test_urllib2").debug
- urllib2.install_opener(urllib2.build_opener(*handlers))
+ urlopen = urllib2.build_opener(*handlers).open
+ if retry:
+ urlopen = _wrap_with_retry_thrice(urlopen, urllib2.URLError)
for url in urls:
if isinstance(url, tuple):