/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

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

  • Committer: Vincent Ladeuil
  • Date: 2007-11-29 23:22:01 UTC
  • mto: (3059.2.1 173010)
  • mto: This revision was merged to the branch mainline in revision 3060.
  • Revision ID: v.ladeuil+lp@free.fr-20071129232201-thjmmlgo5ucbrwfn
Add tests and fix trivial bugs and other typos.

* bzrlib/transport/http/response.py:
(handle_response): Delete obsolete TODO.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._readv): Fix some trivial bugs revealed by the
test suite.
(HttpTransportBase._coalesce_readv): Fix list splice access, first
seen by jam, but found by the test suite too.

* bzrlib/tests/test_http.py:
Fix some imports.
(TestRangeRequestServer.test_readv_multiple_get_requests):
Exercise the rewritten readv.

* bzrlib/tests/HttpServer.py:
(TestingHTTPRequestHandler.do_GET): Count the requests (more tests
use that info).

* bzrlib/tests/HTTPTestUtil.py:
(LimitedRangeRequestHandler.do_GET): The statistics are collected
in the base request handler now.
(NoRangeRequestHandler.do_GET): But since we bypass the base
handler, re-enable the statistics collection here.

Show diffs side-by-side

added added

removed removed

Lines of Context:
293
293
                for cur_coal, file in self._coalesce_readv(relpath, coalesced):
294
294
                    # Split the received chunk
295
295
                    for offset, size in cur_coal.ranges:
296
 
                        key = (cur_coal.start + offset, size)
297
 
                        file.seek(cur_coal.start + offset, 0)
 
296
                        start = cur_coal.start + offset
 
297
                        file.seek(start, 0)
298
298
                        data = file.read(size)
299
299
                        data_len = len(data)
300
300
                        if data_len != size:
301
301
                            raise errors.ShortReadvError(relpath, start, size,
302
302
                                                         actual=data_len)
303
 
                        data_map[key] = data
 
303
                        data_map[(start, size)] = data
304
304
 
305
305
                    # Yield everything we can
306
306
                    while cur_offset_and_size in data_map:
315
315
                self._degrade_range_hint(relpath, coalesced, sys.exc_info())
316
316
                # Some offsets may have been already processed, so we retry
317
317
                # only the unsuccessful ones.
318
 
                offsets = [cur_offset_and_size] + [o for o in offset_stack]
 
318
                offsets = [cur_offset_and_size] + [o for o in iter_offsets]
 
319
                try_again = True
319
320
 
320
321
    def _coalesce_readv(self, relpath, coalesced):
321
322
        """Issue several GET requests to satisfy the coalesced offsets"""
328
329
            # The whole file will be downloaded anyway
329
330
            max_ranges = total
330
331
        for group in xrange(0, len(coalesced), max_ranges):
331
 
            ranges = coalesced[group * max_ranges:group+1 * max_ranges]
 
332
            ranges = coalesced[group:group+max_ranges]
332
333
            # Note that the following may raise errors.InvalidRange. It's the
333
334
            # caller responsability to decide how to retry since it may provide
334
335
            # different coalesced offsets.
335
 
            file = self._get(relpath, ranges)
 
336
            code, file = self._get(relpath, ranges)
336
337
            for range in ranges:
337
338
                yield range, file
338
339