cpython: 2ca415cbf2ac (original) (raw)

--- a/Lib/test/test_urllib.py +++ b/Lib/test/test_urllib.py @@ -36,6 +36,44 @@ def urlopen(url, data=None, proxies=None else: return opener.open(url, data) + +class FakeHTTPMixin(object):

+

+

+

+

+

+

+

+ + class urlopen_FileTests(unittest.TestCase): """Test urlopen() opening a temporary file. @@ -139,35 +177,9 @@ class ProxyTests(unittest.TestCase): self.env.set('NO_PROXY', 'localhost, anotherdomain.com, newdomain.com') self.assertTrue(urllib.request.proxy_bypass_environment('anotherdomain.com')) -class urlopen_HttpTests(unittest.TestCase): +class urlopen_HttpTests(unittest.TestCase, FakeHTTPMixin): """Test urlopen() opening a fake http connection."""

-

- def check_read(self, ver): self.fakehttp(b"HTTP/" + ver + b" 200 OK\r\n\r\nHello!") try: @@ -394,6 +406,48 @@ class urlretrieve_FileTests(unittest.Tes self.assertEqual(report[0][1], 8192) self.assertEqual(report[0][2], 8193) + +class urlretrieve_HttpTests(unittest.TestCase, FakeHTTPMixin):

+

+Date: Wed, 02 Jan 2008 03:03:54 GMT +Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e +Connection: close +Content-Length: 100 +Content-Type: text/html; charset=iso-8859-1 + +FF +''') +

+

+

+Date: Wed, 02 Jan 2008 03:03:54 GMT +Server: Apache/1.3.33 (Debian GNU/Linux) mod_ssl/2.8.22 OpenSSL/0.9.7e +Connection: close +Content-Length: 100 +Content-Type: text/html; charset=iso-8859-1 + +FF +''')

+ + class QuotingTests(unittest.TestCase): """Tests for urllib.quote() and urllib.quote_plus() @@ -1164,6 +1218,7 @@ def test_main(): urlopen_FileTests, urlopen_HttpTests, urlretrieve_FileTests,

--- a/Lib/urllib/request.py +++ b/Lib/urllib/request.py @@ -1589,9 +1589,9 @@ class URLopener: size = -1 read = 0 blocknum = 0

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -66,6 +66,9 @@ Core and Builtins Library ------- +- Issue 10817: Fix urlretrieve function to raise ContentTooShortError even