summaryrefslogtreecommitdiffstats
path: root/Lib/urllib/request.py
diff options
context:
space:
mode:
authorMartin Panter <vadmium+py@gmail.com>2016-02-06 01:08:40 (GMT)
committerMartin Panter <vadmium+py@gmail.com>2016-02-06 01:08:40 (GMT)
commita3643c280f7ed819d2caaa52cb0094a8f2267000 (patch)
tree4f5d41959d2148414552bf03a784b3fd8f9c39c9 /Lib/urllib/request.py
parentab8d4fba6d0657420b53b2988cf3810c3f2ace67 (diff)
parenta03702252f591e477db0576bea589d21afdfa601 (diff)
downloadcpython-a3643c280f7ed819d2caaa52cb0094a8f2267000.zip
cpython-a3643c280f7ed819d2caaa52cb0094a8f2267000.tar.gz
cpython-a3643c280f7ed819d2caaa52cb0094a8f2267000.tar.bz2
Issue #12923: Merge FancyURLopener fix from 3.5
Diffstat (limited to 'Lib/urllib/request.py')
-rw-r--r--Lib/urllib/request.py24
1 files changed, 13 insertions, 11 deletions
diff --git a/Lib/urllib/request.py b/Lib/urllib/request.py
index 88326f8..4c2b9fe 100644
--- a/Lib/urllib/request.py
+++ b/Lib/urllib/request.py
@@ -2110,18 +2110,20 @@ class FancyURLopener(URLopener):
def http_error_302(self, url, fp, errcode, errmsg, headers, data=None):
"""Error 302 -- relocated (temporarily)."""
self.tries += 1
- if self.maxtries and self.tries >= self.maxtries:
- if hasattr(self, "http_error_500"):
- meth = self.http_error_500
- else:
- meth = self.http_error_default
+ try:
+ if self.maxtries and self.tries >= self.maxtries:
+ if hasattr(self, "http_error_500"):
+ meth = self.http_error_500
+ else:
+ meth = self.http_error_default
+ return meth(url, fp, 500,
+ "Internal Server Error: Redirect Recursion",
+ headers)
+ result = self.redirect_internal(url, fp, errcode, errmsg,
+ headers, data)
+ return result
+ finally:
self.tries = 0
- return meth(url, fp, 500,
- "Internal Server Error: Redirect Recursion", headers)
- result = self.redirect_internal(url, fp, errcode, errmsg, headers,
- data)
- self.tries = 0
- return result
def redirect_internal(self, url, fp, errcode, errmsg, headers, data):
if 'location' in headers: