~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-06-30 18:28:17 UTC
  • mfrom: (5967.10.2 test-cat)
  • Revision ID: pqm@pqm.ubuntu.com-20110630182817-83a5q9r9rxfkdn8r
(mbp) don't use subprocesses for testing cat (Martin Pool)

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Implementation of Transport over SFTP, using paramiko."""
18
18
 
19
 
from __future__ import absolute_import
20
 
 
21
19
# TODO: Remove the transport-based lock_read and lock_write methods.  They'll
22
20
# then raise TransportNotPossible, which will break remote access to any
23
21
# formats which rely on OS-level locks.  That should be fine as those formats
33
31
import stat
34
32
import sys
35
33
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,
 
45
                           NoSuchFile, PathNotChild,
46
46
                           TransportError,
47
47
                           LockError,
48
48
                           PathError,
49
49
                           ParamikoNotPresent,
50
50
                           )
51
 
from bzrlib.osutils import fancy_rename
 
51
from bzrlib.osutils import pathjoin, fancy_rename, getcwd
 
52
from bzrlib.symbol_versioning import (
 
53
        deprecated_function,
 
54
        )
52
55
from bzrlib.trace import mutter, warning
53
56
from bzrlib.transport import (
54
57
    FileFileStream,
55
58
    _file_streams,
 
59
    local,
 
60
    Server,
56
61
    ssh,
57
62
    ConnectedTransport,
58
63
    )
332
337
    # up the request itself, rather than us having to worry about it
333
338
    _max_request_size = 32768
334
339
 
 
340
    def __init__(self, base, _from_transport=None):
 
341
        super(SFTPTransport, self).__init__(base,
 
342
                                            _from_transport=_from_transport)
 
343
 
335
344
    def _remote_path(self, relpath):
336
345
        """Return the path to be passed along the sftp protocol for relpath.
337
346
 
338
347
        :param relpath: is a urlencoded string.
339
348
        """
340
 
        remote_path = self._parsed_url.clone(relpath).path
 
349
        relative = urlutils.unescape(relpath).encode('utf-8')
 
350
        remote_path = self._combine_paths(self._path, relative)
341
351
        # the initial slash should be removed from the path, and treated as a
342
352
        # homedir relative path (the path begins with a double slash if it is
343
353
        # absolute).  see draft-ietf-secsh-scp-sftp-ssh-uri-03.txt
362
372
        in base url at transport creation time.
363
373
        """
364
374
        if credentials is None:
365
 
            password = self._parsed_url.password
 
375
            password = self._password
366
376
        else:
367
377
            password = credentials
368
378
 
369
379
        vendor = ssh._get_ssh_vendor()
370
 
        user = self._parsed_url.user
 
380
        user = self._user
371
381
        if user is None:
372
382
            auth = config.AuthenticationConfig()
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)
 
383
            user = auth.get_user('ssh', self._host, self._port)
 
384
        connection = vendor.connect_sftp(self._user, password,
 
385
                                         self._host, self._port)
377
386
        return connection, (user, password)
378
387
 
379
388
    def disconnect(self):