~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

(gz) Remove bzrlib/util/elementtree/ package (Martin Packman)

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
 
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
    )
114
109
        except FileExists:
115
110
            raise LockError('File %r already locked' % (self.path,))
116
111
 
117
 
    def __del__(self):
118
 
        """Should this warn, or actually try to cleanup?"""
119
 
        if self.lock_file:
120
 
            warning("SFTPLock %r not explicitly unlocked" % (self.path,))
121
 
            self.unlock()
122
 
 
123
112
    def unlock(self):
124
113
        if not self.lock_file:
125
114
            return
343
332
    # up the request itself, rather than us having to worry about it
344
333
    _max_request_size = 32768
345
334
 
346
 
    def __init__(self, base, _from_transport=None):
347
 
        super(SFTPTransport, self).__init__(base,
348
 
                                            _from_transport=_from_transport)
349
 
 
350
335
    def _remote_path(self, relpath):
351
336
        """Return the path to be passed along the sftp protocol for relpath.
352
337
 
353
338
        :param relpath: is a urlencoded string.
354
339
        """
355
 
        relative = urlutils.unescape(relpath).encode('utf-8')
356
 
        remote_path = self._combine_paths(self._path, relative)
 
340
        remote_path = self._parsed_url.clone(relpath).path
357
341
        # the initial slash should be removed from the path, and treated as a
358
342
        # homedir relative path (the path begins with a double slash if it is
359
343
        # absolute).  see draft-ietf-secsh-scp-sftp-ssh-uri-03.txt
378
362
        in base url at transport creation time.
379
363
        """
380
364
        if credentials is None:
381
 
            password = self._password
 
365
            password = self._parsed_url.password
382
366
        else:
383
367
            password = credentials
384
368
 
385
369
        vendor = ssh._get_ssh_vendor()
386
 
        user = self._user
 
370
        user = self._parsed_url.user
387
371
        if user is None:
388
372
            auth = config.AuthenticationConfig()
389
 
            user = auth.get_user('ssh', self._host, self._port)
390
 
        connection = vendor.connect_sftp(self._user, password,
391
 
                                         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)
392
377
        return connection, (user, password)
393
378
 
394
379
    def disconnect(self):