Rev 6576: (vila) Add __iter__ to http ResponseFile (Vincent Ladeuil) in file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

Patch Queue Manager pqm at pqm.ubuntu.com
Sat May 25 00:23:25 UTC 2013


At file:///srv/pqm.bazaar-vcs.org/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 6576 [merge]
revision-id: pqm at pqm.ubuntu.com-20130525002324-a3vwfemjm3vlhspz
parent: pqm at pqm.ubuntu.com-20130523103523-2wt6jmauja1n1vdt
parent: v.ladeuil+lp at free.fr-20130524235040-2wcup9uokmbn346p
committer: Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Sat 2013-05-25 00:23:24 +0000
message:
  (vila) Add __iter__ to http ResponseFile (Vincent Ladeuil)
modified:
  bzrlib/tests/test_http_response.py test_http_response.py-20060628233143-950b2a482a32505d
  bzrlib/transport/http/response.py _response.py-20060613154423-a2ci7hd4iw5c7fnt-1
=== modified file 'bzrlib/tests/test_http_response.py'
--- a/bzrlib/tests/test_http_response.py	2012-08-04 11:16:14 +0000
+++ b/bzrlib/tests/test_http_response.py	2013-05-24 23:50:40 +0000
@@ -75,6 +75,17 @@
         pass
 
 
+class TestResponseFileIter(tests.TestCase):
+
+    def test_iter_empty(self):
+        f = response.ResponseFile('empty', StringIO())
+        self.assertEqual([], list(f))
+
+    def test_iter_many(self):
+        f = response.ResponseFile('many', StringIO('0\n1\nboo!\n'))
+        self.assertEqual(['0\n', '1\n', 'boo!\n'], list(f))
+
+
 class TestHTTPConnection(tests.TestCase):
 
     def test_cleanup_pipe(self):
@@ -137,7 +148,6 @@
 
     def test_read_zero(self):
         f = self._file
-        start = self.first_range_start
         self.assertEquals('', f.read(0))
         f.seek(10, 1)
         self.assertEquals('', f.read(0))
@@ -371,13 +381,11 @@
 
     def test_seek_across_ranges(self):
         f = self._file
-        start = self.first_range_start
         f.seek(126) # skip the two first ranges
         self.assertEquals('AB', f.read(2))
 
     def test_checked_read_dont_overflow_buffers(self):
         f = self._file
-        start = self.first_range_start
         # We force a very low value to exercise all code paths in _checked_read
         f._discarded_buf_size = 8
         f.seek(126) # skip the two first ranges

=== modified file 'bzrlib/transport/http/response.py'
--- a/bzrlib/transport/http/response.py	2012-04-06 11:38:05 +0000
+++ b/bzrlib/transport/http/response.py	2013-05-24 23:45:55 +0000
@@ -38,6 +38,7 @@
     """A wrapper around the http socket containing the result of a GET request.
 
     Only read() and seek() (forward) are supported.
+
     """
     def __init__(self, path, infile):
         """Constructor.
@@ -71,6 +72,13 @@
         self._pos += len(data)
         return data
 
+    def __iter__(self):
+        while True:
+            line = self.readline()
+            if not line:
+                return
+            yield line
+
     def tell(self):
         return self._pos
 




More information about the bazaar-commits mailing list