diff options
| author | Martin Panter <vadmium+py@gmail.com> | 2016-02-06 01:08:40 (GMT) |
|---|---|---|
| committer | Martin Panter <vadmium+py@gmail.com> | 2016-02-06 01:08:40 (GMT) |
| commit | a3643c280f7ed819d2caaa52cb0094a8f2267000 (patch) | |
| tree | 4f5d41959d2148414552bf03a784b3fd8f9c39c9 /Lib/test/test_urllib.py | |
| parent | ab8d4fba6d0657420b53b2988cf3810c3f2ace67 (diff) | |
| parent | a03702252f591e477db0576bea589d21afdfa601 (diff) | |
| download | cpython-a3643c280f7ed819d2caaa52cb0094a8f2267000.zip cpython-a3643c280f7ed819d2caaa52cb0094a8f2267000.tar.gz cpython-a3643c280f7ed819d2caaa52cb0094a8f2267000.tar.bz2 | |
Issue #12923: Merge FancyURLopener fix from 3.5
Diffstat (limited to 'Lib/test/test_urllib.py')
| -rw-r--r-- | Lib/test/test_urllib.py | 31 |
1 files changed, 25 insertions, 6 deletions
diff --git a/Lib/test/test_urllib.py b/Lib/test/test_urllib.py index 57eeeaa..e197a3f 100644 --- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -39,10 +39,7 @@ def urlopen(url, data=None, proxies=None): if proxies is not None: opener = urllib.request.FancyURLopener(proxies=proxies) elif not _urlopener: - with support.check_warnings( - ('FancyURLopener style of invoking requests is deprecated.', - DeprecationWarning)): - opener = urllib.request.FancyURLopener() + opener = FancyURLopener() _urlopener = opener else: opener = _urlopener @@ -52,6 +49,13 @@ def urlopen(url, data=None, proxies=None): return opener.open(url, data) +def FancyURLopener(): + with support.check_warnings( + ('FancyURLopener style of invoking requests is deprecated.', + DeprecationWarning)): + return urllib.request.FancyURLopener() + + def fakehttp(fakedata): class FakeSocket(io.BytesIO): io_refs = 1 @@ -291,11 +295,26 @@ Connection: close Content-Type: text/html; charset=iso-8859-1 ''') try: - self.assertRaises(urllib.error.HTTPError, urlopen, - "http://python.org/") + msg = "Redirection to url 'file:" + with self.assertRaisesRegex(urllib.error.HTTPError, msg): + 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(FancyURLopener().maxtries): + self.fakehttp(b'''HTTP/1.1 302 Found +Location: file://guidocomputer.athome.com:/python/license +Connection: close +''') + try: + self.assertRaises(urllib.error.HTTPError, urlopen, + "http://something") + finally: + self.unfakehttp() + def test_empty_socket(self): # urlopen() raises OSError if the underlying socket does not send any # data. (#1680230) |
