Issue #12923: Reset FancyURLopener's redirect counter even on exception
Based on patches by Brian Brazil and Daniel Rocco.
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py
index adffb57..e14cccc 100644
--- a/Lib/test/test_urllib.py
+++ b/Lib/test/test_urllib.py
@@ -209,10 +209,26 @@
Content-Type: text/html; charset=iso-8859-1
""")
try:
- self.assertRaises(IOError, urllib.urlopen, "http://python.org/")
+ msg = "Redirection to url 'file:"
+ with self.assertRaisesRegexp(IOError, msg):
+ urllib.urlopen("http://python.org/")
finally:
self.unfakehttp()
+ def test_redirect_limit_independent(self):
+ # Ticket #12923: make sure independent requests each use their
+ # own retry limit.
+ for i in range(urllib.FancyURLopener().maxtries):
+ self.fakehttp(b'''HTTP/1.1 302 Found
+Location: file://guidocomputer.athome.com:/python/license
+Connection: close
+''')
+ try:
+ self.assertRaises(IOError, urllib.urlopen,
+ "http://something")
+ finally:
+ self.unfakehttp()
+
def test_empty_socket(self):
# urlopen() raises IOError if the underlying socket does not send any
# data. (#1680230)