/breezy/unstable

To get this branch, use:
bzr branch https://code.breezy-vcs.org/breezy/unstable

« back to all changes in this revision

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

  • Committer: Jelmer Vernooij
  • Date: 2017-05-24 01:39:33 UTC
  • mfrom: (3815.3776.6)
  • Revision ID: jelmer@jelmer.uk-20170524013933-ir4y4tqtrsiz2ka2
New upstream snapshot.

Show diffs side-by-side

added added

removed removed

Lines of Context:
27
27
import sys
28
28
import weakref
29
29
 
30
 
from bzrlib import (
 
30
from ... import (
31
31
    debug,
32
32
    errors,
33
33
    transport,
34
34
    ui,
35
35
    urlutils,
36
36
    )
37
 
from bzrlib.smart import medium
38
 
from bzrlib.trace import mutter
39
 
from bzrlib.transport import (
 
37
from ...smart import medium
 
38
from ...trace import mutter
 
39
from ...transport import (
40
40
    ConnectedTransport,
41
41
    )
42
42
 
127
127
            self._medium = SmartClientHTTPMedium(self)
128
128
        return self._medium
129
129
 
130
 
    def _degrade_range_hint(self, relpath, ranges, exc_info):
 
130
    def _degrade_range_hint(self, relpath, ranges):
131
131
        if self._range_hint == 'multi':
132
132
            self._range_hint = 'single'
133
133
            mutter('Retry "%s" with single range request' % relpath)
135
135
            self._range_hint = None
136
136
            mutter('Retry "%s" without ranges' % relpath)
137
137
        else:
138
 
            # We tried all the tricks, but nothing worked. We re-raise the
139
 
            # original exception; the 'mutter' calls above will indicate that
140
 
            # further tries were unsuccessful
141
 
            raise exc_info[0], exc_info[1], exc_info[2]
 
138
            # We tried all the tricks, but nothing worked, caller must reraise.
 
139
            return False
 
140
        return True
142
141
 
143
142
    # _coalesce_offsets is a helper for readv, it try to combine ranges without
144
143
    # degrading readv performances. _bytes_to_read_before_seek is the value
227
226
                        cur_offset_and_size = iter_offsets.next()
228
227
 
229
228
            except (errors.ShortReadvError, errors.InvalidRange,
230
 
                    errors.InvalidHttpRange, errors.HttpBoundaryMissing), e:
 
229
                    errors.InvalidHttpRange, errors.HttpBoundaryMissing) as e:
231
230
                mutter('Exception %r: %s during http._readv',e, e)
232
231
                if (not isinstance(e, errors.ShortReadvError)
233
232
                    or retried_offset == cur_offset_and_size):
235
234
                    # they do not indicate a problem with the server ability to
236
235
                    # handle ranges. Except when we fail to get back a required
237
236
                    # offset twice in a row. In that case, falling back to
238
 
                    # single range or whole file should help or end up in a
239
 
                    # fatal exception.
240
 
                    self._degrade_range_hint(relpath, coalesced, sys.exc_info())
 
237
                    # single range or whole file should help.
 
238
                    if not self._degrade_range_hint(relpath, coalesced):
 
239
                        raise
241
240
                # Some offsets may have been already processed, so we retry
242
241
                # only the unsuccessful ones.
243
242
                offsets = [cur_offset_and_size] + [o for o in iter_offsets]
365
364
        raise errors.TransportNotPossible('http does not support delete()')
366
365
 
367
366
    def external_url(self):
368
 
        """See bzrlib.transport.Transport.external_url."""
 
367
        """See breezy.transport.Transport.external_url."""
369
368
        # HTTP URL's are externally usable as long as they don't mention their
370
369
        # implementation qualifier
371
370
        url = self._parsed_url.clone()
561
560
                raise errors.InvalidHttpResponse(
562
561
                    t._remote_path('.bzr/smart'),
563
562
                    'Expected 200 response code, got %r' % (code,))
564
 
        except (errors.InvalidHttpResponse, errors.ConnectionReset), e:
 
563
        except (errors.InvalidHttpResponse, errors.ConnectionReset) as e:
565
564
            raise errors.SmartProtocolError(str(e))
566
565
        return body_filelike
567
566