~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.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) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011, 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
16
16
 
17
17
"""Implementation of Transport over SFTP, using paramiko."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
# TODO: Remove the transport-based lock_read and lock_write methods.  They'll
20
22
# then raise TransportNotPossible, which will break remote access to any
21
23
# formats which rely on OS-level locks.  That should be fine as those formats
31
33
import stat
32
34
import sys
33
35
import time
34
 
import urllib
35
 
import urlparse
36
36
import warnings
37
37
 
38
38
from bzrlib import (
42
42
    urlutils,
43
43
    )
44
44
from bzrlib.errors import (FileExists,
45
 
                           NoSuchFile, PathNotChild,
 
45
                           NoSuchFile,
46
46
                           TransportError,
47
47
                           LockError,
48
48
                           PathError,
49
49
                           ParamikoNotPresent,
50
50
                           )
51
 
from bzrlib.osutils import pathjoin, fancy_rename, getcwd
52
 
from bzrlib.symbol_versioning import (
53
 
        deprecated_function,
54
 
        )
 
51
from bzrlib.osutils import fancy_rename
55
52
from bzrlib.trace import mutter, warning
56
53
from bzrlib.transport import (
57
54
    FileFileStream,
58
55
    _file_streams,
59
 
    local,
60
 
    Server,
61
56
    ssh,
62
57
    ConnectedTransport,
63
58
    )
337
332
    # up the request itself, rather than us having to worry about it
338
333
    _max_request_size = 32768
339
334
 
340
 
    def __init__(self, base, _from_transport=None):
341
 
        super(SFTPTransport, self).__init__(base,
342
 
                                            _from_transport=_from_transport)
343
 
 
344
335
    def _remote_path(self, relpath):
345
336
        """Return the path to be passed along the sftp protocol for relpath.
346
337
 
347
338
        :param relpath: is a urlencoded string.
348
339
        """
349
 
        relative = urlutils.unescape(relpath).encode('utf-8')
350
 
        remote_path = self._combine_paths(self._path, relative)
 
340
        remote_path = self._parsed_url.clone(relpath).path
351
341
        # the initial slash should be removed from the path, and treated as a
352
342
        # homedir relative path (the path begins with a double slash if it is
353
343
        # absolute).  see draft-ietf-secsh-scp-sftp-ssh-uri-03.txt
372
362
        in base url at transport creation time.
373
363
        """
374
364
        if credentials is None:
375
 
            password = self._password
 
365
            password = self._parsed_url.password
376
366
        else:
377
367
            password = credentials
378
368
 
379
369
        vendor = ssh._get_ssh_vendor()
380
 
        user = self._user
 
370
        user = self._parsed_url.user
381
371
        if user is None:
382
372
            auth = config.AuthenticationConfig()
383
 
            user = auth.get_user('ssh', self._host, self._port)
384
 
        connection = vendor.connect_sftp(self._user, password,
385
 
                                         self._host, self._port)
 
373
            user = auth.get_user('ssh', self._parsed_url.host,
 
374
                self._parsed_url.port)
 
375
        connection = vendor.connect_sftp(self._parsed_url.user, password,
 
376
            self._parsed_url.host, self._parsed_url.port)
386
377
        return connection, (user, password)
387
378
 
388
379
    def disconnect(self):
602
593
                                    create_parent_dir=create_parent_dir,
603
594
                                    dir_mode=dir_mode)
604
595
 
605
 
    def put_bytes_non_atomic(self, relpath, bytes, mode=None,
 
596
    def put_bytes_non_atomic(self, relpath, raw_bytes, mode=None,
606
597
                             create_parent_dir=False,
607
598
                             dir_mode=None):
 
599
        if not isinstance(raw_bytes, str):
 
600
            raise TypeError(
 
601
                'raw_bytes must be a plain string, not %s' % type(raw_bytes))
 
602
 
608
603
        def writer(fout):
609
 
            fout.write(bytes)
 
604
            fout.write(raw_bytes)
610
605
        self._put_non_atomic_helper(relpath, writer, mode=mode,
611
606
                                    create_parent_dir=create_parent_dir,
612
607
                                    dir_mode=dir_mode)