~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/remote.py

  • Committer: Jelmer Vernooij
  • Date: 2016-04-03 16:32:31 UTC
  • mto: This revision was merged to the branch mainline in revision 6617.
  • Revision ID: jelmer@jelmer.uk-20160403163231-h72bo0uyek2gikw0
Don't put French text in doc/en/user-reference when LANGUAGE=fr_CH.UTF_8.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2006-2010 Canonical Ltd
 
1
# Copyright (C) 2006-2012, 2016 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
imported from bzrlib.smart.
21
21
"""
22
22
 
 
23
from __future__ import absolute_import
 
24
 
23
25
__all__ = ['RemoteTransport', 'RemoteTCPTransport', 'RemoteSSHTransport']
24
26
 
25
27
from cStringIO import StringIO
34
36
    urlutils,
35
37
    )
36
38
from bzrlib.smart import client, medium
37
 
from bzrlib.symbol_versioning import (
38
 
    deprecated_method,
39
 
    )
40
39
 
41
40
 
42
41
class _SmartStat(object):
170
169
 
171
170
    def _remote_path(self, relpath):
172
171
        """Returns the Unicode version of the absolute path for relpath."""
173
 
        return self._combine_paths(self._path, relpath)
 
172
        return urlutils.URL._combine_paths(self._parsed_url.path, relpath)
174
173
 
175
174
    def _call(self, method, *args):
176
175
        resp = self._call2(method, *args)
248
247
        transport._file_streams[self.abspath(relpath)] = result
249
248
        return result
250
249
 
251
 
    def put_bytes(self, relpath, upload_contents, mode=None):
252
 
        # FIXME: upload_file is probably not safe for non-ascii characters -
253
 
        # should probably just pass all parameters as length-delimited
254
 
        # strings?
255
 
        if type(upload_contents) is unicode:
256
 
            # Although not strictly correct, we raise UnicodeEncodeError to be
257
 
            # compatible with other transports.
258
 
            raise UnicodeEncodeError(
259
 
                'undefined', upload_contents, 0, 1,
260
 
                'put_bytes must be given bytes, not unicode.')
261
 
        resp = self._call_with_body_bytes('put',
 
250
    def put_bytes(self, relpath, raw_bytes, mode=None):
 
251
        if not isinstance(raw_bytes, str):
 
252
            raise TypeError(
 
253
                'raw_bytes must be a plain string, not %s' % type(raw_bytes))
 
254
        resp = self._call_with_body_bytes(
 
255
            'put',
262
256
            (self._remote_path(relpath), self._serialise_optional_mode(mode)),
263
 
            upload_contents)
 
257
            raw_bytes)
264
258
        self._ensure_ok(resp)
265
 
        return len(upload_contents)
 
259
        return len(raw_bytes)
266
260
 
267
 
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
 
261
    def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
268
262
                             create_parent_dir=False,
269
263
                             dir_mode=None):
270
264
        """See Transport.put_bytes_non_atomic."""
277
271
            'put_non_atomic',
278
272
            (self._remote_path(relpath), self._serialise_optional_mode(mode),
279
273
             create_parent_str, self._serialise_optional_mode(dir_mode)),
280
 
            bytes)
 
274
            raw_bytes)
281
275
        self._ensure_ok(resp)
282
276
 
283
277
    def put_file(self, relpath, upload_file, mode=None):
483
477
 
484
478
    def _build_medium(self):
485
479
        client_medium = medium.SmartTCPClientMedium(
486
 
            self._host, self._port, self.base)
 
480
            self._parsed_url.host, self._parsed_url.port, self.base)
487
481
        return client_medium, None
488
482
 
489
483
 
496
490
 
497
491
    def _build_medium(self):
498
492
        client_medium = medium.SmartTCPClientMedium(
499
 
            self._host, self._port, self.base)
 
493
            self._parsed_url.host, self._parsed_url.port, self.base)
500
494
        client_medium._protocol_version = 2
501
495
        client_medium._remember_remote_is_before((1, 6))
502
496
        return client_medium, None
512
506
    def _build_medium(self):
513
507
        location_config = config.LocationConfig(self.base)
514
508
        bzr_remote_path = location_config.get_bzr_remote_path()
515
 
        user = self._user
 
509
        user = self._parsed_url.user
516
510
        if user is None:
517
511
            auth = config.AuthenticationConfig()
518
 
            user = auth.get_user('ssh', self._host, self._port)
519
 
        ssh_params = medium.SSHParams(self._host, self._port, user,
520
 
            self._password, bzr_remote_path)
 
512
            user = auth.get_user('ssh', self._parsed_url.host,
 
513
                self._parsed_url.port)
 
514
        ssh_params = medium.SSHParams(self._parsed_url.host,
 
515
                self._parsed_url.port, user, self._parsed_url.password,
 
516
                bzr_remote_path)
521
517
        client_medium = medium.SmartSSHClientMedium(self.base, ssh_params)
522
 
        return client_medium, (user, self._password)
 
518
        return client_medium, (user, self._parsed_url.password)
523
519
 
524
520
 
525
521
class RemoteHTTPTransport(RemoteTransport):
539
535
            # url only for an intial construction (when the url came from the
540
536
            # command-line).
541
537
            http_url = base[len('bzr+'):]
542
 
            self._http_transport = transport.get_transport(http_url)
 
538
            self._http_transport = transport.get_transport_from_url(http_url)
543
539
        else:
544
540
            self._http_transport = http_transport
545
541
        super(RemoteHTTPTransport, self).__init__(