/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 breezy/transport/remote.py

  • Committer: Jelmer Vernooij
  • Date: 2018-11-17 00:47:52 UTC
  • mfrom: (7182 work)
  • mto: This revision was merged to the branch mainline in revision 7305.
  • Revision ID: jelmer@jelmer.uk-20181117004752-6ywampe5pfywlby4
Merge trunk.

Show diffs side-by-side

added added

removed removed

Lines of Context:
66
66
    """
67
67
 
68
68
    # When making a readv request, cap it at requesting 5MB of data
69
 
    _max_readv_bytes = 5*1024*1024
 
69
    _max_readv_bytes = 5 * 1024 * 1024
70
70
 
71
71
    # IMPORTANT FOR IMPLEMENTORS: RemoteTransport MUST NOT be given encoding
72
72
    # responsibilities: Put those on SmartClient or similar. This is vital for
102
102
        # what we want to share is really the shared connection.
103
103
 
104
104
        if (_from_transport is not None
105
 
            and isinstance(_from_transport, RemoteTransport)):
 
105
                and isinstance(_from_transport, RemoteTransport)):
106
106
            _client = _from_transport._client
107
107
        elif _from_transport is None:
108
108
            # If no _from_transport is specified, we need to intialize the
228
228
    def get_bytes(self, relpath):
229
229
        remote = self._remote_path(relpath)
230
230
        try:
231
 
            resp, response_handler = self._client.call_expecting_body(b'get', remote)
 
231
            resp, response_handler = self._client.call_expecting_body(
 
232
                b'get', remote)
232
233
        except errors.ErrorFromSmartServer as err:
233
234
            self._translate_error(err, relpath)
234
235
        if resp != (b'ok', ):
244
245
 
245
246
    def mkdir(self, relpath, mode=None):
246
247
        resp = self._call2(b'mkdir', self._remote_path(relpath),
247
 
            self._serialise_optional_mode(mode))
 
248
                           self._serialise_optional_mode(mode))
248
249
 
249
250
    def open_write_stream(self, relpath, mode=None):
250
251
        """See Transport.open_write_stream."""
331
332
 
332
333
        sorted_offsets = sorted(offsets)
333
334
        coalesced = list(self._coalesce_offsets(sorted_offsets,
334
 
                               limit=self._max_readv_combine,
335
 
                               fudge_factor=self._bytes_to_read_before_seek,
336
 
                               max_size=self._max_readv_bytes))
 
335
                                                limit=self._max_readv_combine,
 
336
                                                fudge_factor=self._bytes_to_read_before_seek,
 
337
                                                max_size=self._max_readv_bytes))
337
338
 
338
339
        # now that we've coallesced things, avoid making enormous requests
339
340
        requests = []
389
390
        for c_offset in coalesced:
390
391
            if len(data) < c_offset.length:
391
392
                raise errors.ShortReadvError(relpath, c_offset.start,
392
 
                            c_offset.length, actual=len(data))
 
393
                                             c_offset.length, actual=len(data))
393
394
            for suboffset, subsize in c_offset.ranges:
394
 
                key = (c_offset.start+suboffset, subsize)
395
 
                this_data = data[data_offset+suboffset:
396
 
                                 data_offset+suboffset+subsize]
 
395
                key = (c_offset.start + suboffset, subsize)
 
396
                this_data = data[data_offset + suboffset:
 
397
                                 data_offset + suboffset + subsize]
397
398
                # Special case when the data is in-order, rather than packing
398
399
                # into a map and then back out again. Benchmarking shows that
399
400
                # this has 100% hit rate, but leave in the data_map work just
404
405
                if key == cur_offset_and_size:
405
406
                    yield cur_offset_and_size[0], this_data
406
407
                    try:
407
 
                        cur_offset_and_size = next_offset[0] = next(offset_stack)
 
408
                        cur_offset_and_size = next_offset[0] = next(
 
409
                            offset_stack)
408
410
                    except StopIteration:
409
411
                        return
410
412
                else:
451
453
            return _SmartStat(int(resp[1]), int(resp[2], 8))
452
454
        raise errors.UnexpectedSmartServerResponse(resp)
453
455
 
454
 
    ## def lock_read(self, relpath):
455
 
    ##     """Lock the given file for shared (read) access.
456
 
    ##     :return: A lock object, which should be passed to Transport.unlock()
457
 
    ##     """
458
 
    ##     # The old RemoteBranch ignore lock for reading, so we will
459
 
    ##     # continue that tradition and return a bogus lock object.
460
 
    ##     class BogusLock(object):
461
 
    ##         def __init__(self, path):
 
456
    # def lock_read(self, relpath):
 
457
    # """Lock the given file for shared (read) access.
 
458
    # :return: A lock object, which should be passed to Transport.unlock()
 
459
    # """
 
460
    # The old RemoteBranch ignore lock for reading, so we will
 
461
    # continue that tradition and return a bogus lock object.
 
462
    # class BogusLock(object):
 
463
    # def __init__(self, path):
462
464
    ##             self.path = path
463
 
    ##         def unlock(self):
464
 
    ##             pass
465
 
    ##     return BogusLock(relpath)
 
465
    # def unlock(self):
 
466
    # pass
 
467
    # return BogusLock(relpath)
466
468
 
467
469
    def listable(self):
468
470
        return True
522
524
        if user is None:
523
525
            auth = config.AuthenticationConfig()
524
526
            user = auth.get_user('ssh', self._parsed_url.host,
525
 
                self._parsed_url.port)
 
527
                                 self._parsed_url.port)
526
528
        ssh_params = medium.SSHParams(self._parsed_url.host,
527
 
                self._parsed_url.port, user, self._parsed_url.password,
528
 
                bzr_remote_path)
 
529
                                      self._parsed_url.port, user, self._parsed_url.password,
 
530
                                      bzr_remote_path)
529
531
        client_medium = medium.SmartSSHClientMedium(self.base, ssh_params)
530
532
        return client_medium, (user, self._parsed_url.password)
531
533
 
591
593
        """See transport._redirected_to"""
592
594
        redirected = self._http_transport._redirected_to(source, target)
593
595
        if (redirected is not None
594
 
            and isinstance(redirected, type(self._http_transport))):
 
596
                and isinstance(redirected, type(self._http_transport))):
595
597
            return RemoteHTTPTransport('bzr+' + redirected.external_url(),
596
598
                                       http_transport=redirected)
597
599
        else:
604
606
 
605
607
    def __init__(self, url):
606
608
        raise errors.UnsupportedProtocol(url,
607
 
            'bzr supports bzr+ssh to operate over ssh, use "bzr+%s".' % url)
 
609
                                         'bzr supports bzr+ssh to operate over ssh, use "bzr+%s".' % url)
608
610
 
609
611
 
610
612
def get_test_permutations():
611
613
    """Return (transport, server) permutations for testing."""
612
 
    ### We may need a little more test framework support to construct an
613
 
    ### appropriate RemoteTransport in the future.
 
614
    # We may need a little more test framework support to construct an
 
615
    # appropriate RemoteTransport in the future.
614
616
    from ..tests import test_server
615
617
    return [(RemoteTCPTransport, test_server.SmartTCPServer_for_testing)]