Index: Lib/test/test_urllib2_localnet.py =================================================================== --- Lib/test/test_urllib2_localnet.py (revision 83811) +++ Lib/test/test_urllib2_localnet.py (working copy) @@ -308,8 +308,9 @@ def do_GET(self): body = self.send_head() - if body: - self.wfile.write(body) + while body: + done = self.wfile.write(body) + body = body[done:] def do_POST(self): content_length = self.headers["Content-Length"] @@ -501,6 +502,26 @@ urllib.request.urlopen, "http://sadflkjsasf.i.nvali.d./") + def test_iteration(self): + handler = self.start_server() + url = urllib.request.urlopen("http://localhost:%s" % handler.port) + for line in url: + pass + + def test_line_iteration(self): + lines = [b"We\n", b"got\n", b"here\n", b"verylong" * 8192 + b"\n"] + expected_response = b"".join(lines) + response = [(200, [], expected_response)] + handler = self.start_server(response) + open_url = urllib.request.urlopen("http://localhost:%s" % handler.port) + for index, line in enumerate(open_url): + if line != lines[index]: + self.fail("Fetched line number %s doesn't match expected:\n " + "Expected lenght was %s, got %s" % (index, + len(lines[index]), len(line)) + ) + self.assertEquals(index + 1, len(lines)) + def test_main(): support.run_unittest(ProxyAuthTests, TestUrlopen)