/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

Merge from bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import re
25
25
import urlparse
26
26
import urllib
 
27
import sys
27
28
 
28
 
from bzrlib import errors
 
29
from bzrlib import errors, ui
29
30
from bzrlib.trace import mutter
30
31
from bzrlib.transport import (
31
32
    Transport,
32
33
    )
33
 
from bzrlib.smart import medium, protocol
34
 
from bzrlib.ui import ui_factory
 
34
from bzrlib.smart import medium
35
35
 
36
36
 
37
37
# TODO: This is not used anymore by HttpTransport_urllib
61
61
        if password is not None:
62
62
            password = urllib.unquote(password)
63
63
        else:
64
 
            password = ui_factory.get_password(
 
64
            password = ui.ui_factory.get_password(
65
65
                prompt='HTTP %(user)s@%(host)s password',
66
66
                user=username, host=host)
67
67
        password_manager.add_password(None, host, username, password)
251
251
        """
252
252
        return self
253
253
 
 
254
    def _retry_get(self, relpath, ranges, exc_info):
 
255
        """A GET request have failed, let's retry with a simpler request."""
 
256
 
 
257
        try_again = False
 
258
        # The server does not gives us enough data or
 
259
        # bogus-looking result, let's try again with
 
260
        # a simpler request if possible.
 
261
        if self._range_hint == 'multi':
 
262
            self._range_hint = 'single'
 
263
            mutter('Retry %s with single range request' % relpath)
 
264
            try_again = True
 
265
        elif self._range_hint == 'single':
 
266
            self._range_hint = None
 
267
            mutter('Retry %s without ranges' % relpath)
 
268
            try_again = True
 
269
        if try_again:
 
270
            # Note that since the offsets and the ranges may not
 
271
            # be in the same order, we don't try to calculate a
 
272
            # restricted single range encompassing unprocessed
 
273
            # offsets.
 
274
            code, f = self._get(relpath, ranges)
 
275
            return try_again, code, f
 
276
        else:
 
277
            # We tried all the tricks, but nothing worked. We
 
278
            # re-raise original exception; the 'mutter' calls
 
279
            # above will indicate that further tries were
 
280
            # unsuccessful
 
281
            raise exc_info[0], exc_info[1], exc_info[2]
 
282
 
254
283
    def readv(self, relpath, offsets):
255
284
        """Get parts of the file at the given relative path.
256
285
 
260
289
        ranges = self.offsets_to_ranges(offsets)
261
290
        mutter('http readv of %s collapsed %s offsets => %s',
262
291
                relpath, len(offsets), ranges)
263
 
        code, f = self._get(relpath, ranges)
 
292
 
 
293
        try_again = True
 
294
        while try_again:
 
295
            try_again = False
 
296
            try:
 
297
                code, f = self._get(relpath, ranges)
 
298
            except (errors.InvalidRange, errors.ShortReadvError), e:
 
299
                try_again, code, f = self._retry_get(relpath, ranges,
 
300
                                                     sys.exc_info())
 
301
 
264
302
        for start, size in offsets:
265
303
            try_again = True
266
304
            while try_again:
272
310
                    if len(data) != size:
273
311
                        raise errors.ShortReadvError(relpath, start, size,
274
312
                                                     actual=len(data))
275
 
                except (errors.InvalidRange, errors.ShortReadvError):
276
 
                    # The server does not gives us enough data or
277
 
                    # bogus-looking result, let's try again with
278
 
                    # a simpler request if possible.
279
 
                    if self._range_hint == 'multi':
280
 
                        self._range_hint = 'single'
281
 
                        mutter('Retry %s with single range request' % relpath)
282
 
                        try_again = True
283
 
                    elif self._range_hint == 'single':
284
 
                        self._range_hint = None
285
 
                        mutter('Retry %s without ranges' % relpath)
286
 
                        try_again = True
287
 
                    if try_again:
288
 
                        # Note that since the offsets and the
289
 
                        # ranges may not be in the same order we
290
 
                        # dont't try to calculate a restricted
291
 
                        # single range encompassing unprocessed
292
 
                        # offsets. Note that we replace 'f' here
293
 
                        # and that it may need cleaning one day
294
 
                        # before being thrown that way.
295
 
                        code, f = self._get(relpath, ranges)
296
 
                    else:
297
 
                        # We tried all the tricks, nothing worked
298
 
                        raise
299
 
 
 
313
                except (errors.InvalidRange, errors.ShortReadvError), e:
 
314
                    # Note that we replace 'f' here and that it
 
315
                    # may need cleaning one day before being
 
316
                    # thrown that way.
 
317
                    try_again, code, f = self._retry_get(relpath, ranges,
 
318
                                                         sys.exc_info())
 
319
            # After one or more tries, we get the data.
300
320
            yield start, data
301
321
 
302
322
    @staticmethod