Merge lp:~vila/bzr/1184021 into lp:bzr

Proposed by Vincent Ladeuil
Status: Merged
Approved by: Jelmer Vernooij
Approved revision: no longer in the source branch.
Merged at revision: 6576
Proposed branch: lp:~vila/bzr/1184021
Merge into: lp:bzr
Diff against target: 68 lines (+19/-3)
2 files modified
bzrlib/tests/test_http_response.py (+11/-3)
bzrlib/transport/http/response.py (+8/-0)
To merge this branch: bzr merge lp:~vila/bzr/1184021
Reviewer Review Type Date Requested Status
Jelmer Vernooij Pending
bzr-core Pending
Review via email: mp+165720@code.launchpad.net

Commit message

Add __iter__ to http ResponseFile

Description of the change

Tests for jelmer's fix for bug #1184021, as straight forward than the fix so I'll just let jelmer approve and land ;)

To post a comment you must log in.
Revision history for this message
Vincent Ladeuil (vila) wrote :

sent to pqm by email

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bzrlib/tests/test_http_response.py'
2--- bzrlib/tests/test_http_response.py 2012-08-04 11:16:14 +0000
3+++ bzrlib/tests/test_http_response.py 2013-05-24 23:55:31 +0000
4@@ -75,6 +75,17 @@
5 pass
6
7
8+class TestResponseFileIter(tests.TestCase):
9+
10+ def test_iter_empty(self):
11+ f = response.ResponseFile('empty', StringIO())
12+ self.assertEqual([], list(f))
13+
14+ def test_iter_many(self):
15+ f = response.ResponseFile('many', StringIO('0\n1\nboo!\n'))
16+ self.assertEqual(['0\n', '1\n', 'boo!\n'], list(f))
17+
18+
19 class TestHTTPConnection(tests.TestCase):
20
21 def test_cleanup_pipe(self):
22@@ -137,7 +148,6 @@
23
24 def test_read_zero(self):
25 f = self._file
26- start = self.first_range_start
27 self.assertEquals('', f.read(0))
28 f.seek(10, 1)
29 self.assertEquals('', f.read(0))
30@@ -371,13 +381,11 @@
31
32 def test_seek_across_ranges(self):
33 f = self._file
34- start = self.first_range_start
35 f.seek(126) # skip the two first ranges
36 self.assertEquals('AB', f.read(2))
37
38 def test_checked_read_dont_overflow_buffers(self):
39 f = self._file
40- start = self.first_range_start
41 # We force a very low value to exercise all code paths in _checked_read
42 f._discarded_buf_size = 8
43 f.seek(126) # skip the two first ranges
44
45=== modified file 'bzrlib/transport/http/response.py'
46--- bzrlib/transport/http/response.py 2012-04-06 11:38:05 +0000
47+++ bzrlib/transport/http/response.py 2013-05-24 23:55:31 +0000
48@@ -38,6 +38,7 @@
49 """A wrapper around the http socket containing the result of a GET request.
50
51 Only read() and seek() (forward) are supported.
52+
53 """
54 def __init__(self, path, infile):
55 """Constructor.
56@@ -71,6 +72,13 @@
57 self._pos += len(data)
58 return data
59
60+ def __iter__(self):
61+ while True:
62+ line = self.readline()
63+ if not line:
64+ return
65+ yield line
66+
67 def tell(self):
68 return self._pos
69