~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/http/__init__.py

  • Committer: Vincent Ladeuil
  • Date: 2007-12-10 10:41:24 UTC
  • mto: (3097.2.1 trunk)
  • mto: This revision was merged to the branch mainline in revision 3099.
  • Revision ID: v.ladeuil+lp@free.fr-20071210104124-0brt3h7ed1kiug0v
Take spiv review comments into account.

* bzrlib/transport/http/response.py:
(RangeFile._seek_to_next_range): Factored out since this is now
used by both seek and read.
(RangeFile.read): Trigger next range recognition when needed.
(RangeFile.seek): Don't seek over the range boundary if not
required to.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._coalesce_readv.get_and_yield): Add a
prophylactic assertionError.

* bzrlib/tests/test_transport_implementations.py:
Fix typos.

* bzrlib/tests/test_http_response.py:
(TestRangeFileMixin.test_read_zero,
TestRangeFileMixin.test_seek_at_range_end,
TestRangeFileMixin.test_read_at_range_end,
TestRangeFileSizeUnknown.test_read_at_range_end,
TestRangeFilMultipleRanges.test_seek_at_range_end,
TestRangeFilMultipleRanges.test_read_at_range_end): More tests
covering read(0).

Show diffs side-by-side

added added

removed removed

Lines of Context:
204
204
        :param return: A list or generator of (offset, data) tuples
205
205
        """
206
206
 
207
 
        # offsets may be a genarator, we will iterate it several times, so
 
207
        # offsets may be a generator, we will iterate it several times, so
208
208
        # build a list
209
209
        offsets = list(offsets)
210
210
 
227
227
            # Cache the data read, but only until it's been used
228
228
            data_map = {}
229
229
            # We will iterate on the data received from the GET requests and
230
 
            # serve the corresponding offsets repecting the initial order. We
 
230
            # serve the corresponding offsets respecting the initial order. We
231
231
            # need an offset iterator for that.
232
232
            iter_offsets = iter(offsets)
233
233
            cur_offset_and_size = iter_offsets.next()
275
275
        def get_and_yield(relpath, coalesced):
276
276
            if coalesced:
277
277
                # Note that the _get below may raise
278
 
                # errors.InvalidHttpRange. It's the caller's responsability to
 
278
                # errors.InvalidHttpRange. It's the caller's responsibility to
279
279
                # decide how to retry since it may provide different coalesced
280
280
                # offsets.
281
281
                code, rfile = self._get(relpath, coalesced)
290
290
            total = len(coalesced)
291
291
            if self._range_hint == 'multi':
292
292
                max_ranges = self._max_get_ranges
293
 
            else: # self._range_hint == 'single'
 
293
            elif self._range_hint == 'single':
294
294
                max_ranges = total
 
295
            else:
 
296
                raise AssertionError("Unknown _range_hint %r"
 
297
                                     % (self._range_hint,))
295
298
            # TODO: Some web servers may ignore the range requests and return
296
299
            # the whole file, we may want to detect that and avoid further
297
300
            # requests.