~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Vincent Ladeuil
  • Date: 2007-06-01 20:26:46 UTC
  • mto: (2485.8.44 bzr.connection.sharing)
  • mto: This revision was merged to the branch mainline in revision 2646.
  • Revision ID: v.ladeuil+lp@free.fr-20070601202646-wuriw6z7rfwks5ny
Separate abspath from _remote_path, the intents are different.

* bzrlib/transport/sftp.py:
(SFTPUrlHandling._combine_paths_respecting_home_dir): New method.
(SFTPUrlHandling.abspath): Take home dir into account explicitely.
(SFTPUrlHandling._remote_path): Simplified.
(SFTPTransport.__init__): Cleanup cloning.

* bzrlib/transport/http/_urllib.py: 
Revert the previous _remote_path -> _unqualified_abspath renaming.

* bzrlib/transport/http/_pycurl.py:
Revert the previous _remote_path -> _unqualified_abspath renaming.

* bzrlib/transport/http/__init__.py:
(HttpTransportBase._remote_path): Re-introduce _remote_path
instead of _unqualified_abspath.

* bzrlib/transport/ftp.py:
(FtpTransport.__init__): Cleanup cloning.
(FtpTransport.clone): Deleted. The inherited one is enough.

* bzrlib/transport/__init__.py:
(ConnectedTransport.__init__): Copy password *after* splitting the
url if needed.
(ConnectedTransport.clone): Generic clone method.
(ConnectedTransport._split_url): Cleanup.
(ConnectedTransport._initial_split_url): New method that daughter
classes can override.
(ConnectedTransport.abspath): Do not call _remote_path, the intent
is different.

* bzrlib/tests/test_transport_implementations.py:
Cleanup imports.
(TransportTests.test_clone_preserve_info): New test.

* bzrlib/tests/test_sftp_transport.py:
(FakeSFTPTransport): Add a dummy get_connection method.
(SFTPNonServerTest.test_parse_url_with_home_dir): Temporarily
disable the password checking.

Show diffs side-by-side

added added

removed removed

Lines of Context:
146
146
 
147
147
    def _urldecode_abspath(self, abspath):
148
148
        abspath = super(SFTPUrlHandling, self)._urldecode_abspath(abspath)
 
149
        if abspath.startswith('/~/'):
 
150
            abspath = abspath[3:]
 
151
        elif abspath == '/~':
 
152
            abspath = ''
 
153
        return abspath
 
154
 
 
155
    def _combine_paths_respecting_home_dir(self, relpath):
149
156
        # the initial slash should be removed from the path, and treated
150
157
        # as a homedir relative path (the path begins with a double slash
151
158
        # if it is absolute).
153
160
        # RBC 20060118 we are not using this as its too user hostile. instead
154
161
        # we are following lftp and using /~/foo to mean '~/foo'.
155
162
 
156
 
        # handle homedir paths
157
 
        if abspath.startswith('/~/'):
158
 
            abspath = abspath[3:]
159
 
        elif abspath == '/~':
160
 
            abspath = ''
 
163
        if not self._path.startswith('/'):
 
164
            abspath = self._combine_paths('/~/' + self._path, relpath)
 
165
            if abspath.startswith('/~/'):
 
166
                abspath = abspath[3:]
 
167
            elif abspath == '/~':
 
168
                abspath = ''
 
169
        else:
 
170
            abspath = self._combine_paths(self._path, relpath)
 
171
 
161
172
        return abspath
162
173
 
 
174
    def abspath(self, relpath):
 
175
        """Return the full url to the given relative path respecting home dir"""
 
176
        relative = urlutils.unescape(relpath).encode('utf-8')
 
177
        path = self._combine_paths_respecting_home_dir(relative)
 
178
        return self._unsplit_url(self._scheme, self._user, self._password,
 
179
                                 self._host, self._port,
 
180
                                 self._urlencode_abspath(path))
 
181
 
 
182
 
163
183
    def _remote_path(self, relpath):
164
184
        """Return the path to be passed along the sftp protocol for relpath.
165
185
        
166
186
        :param relpath: is a urlencoded string.
167
187
        """
168
188
        relative = urlutils.unescape(relpath).encode('utf-8')
169
 
        if not self._path.startswith('/'):
170
 
            # handle homedir paths
171
 
            remote_path = self._combine_paths('/~/' + self._path, relative)
172
 
            if remote_path.startswith('/~/'):
173
 
                remote_path = remote_path[3:]
174
 
            elif remote_path == '/~':
175
 
                remote_path = ''
176
 
        else:
177
 
            remote_path = self._combine_paths(self._path, relative)
 
189
        remote_path = self._combine_paths_respecting_home_dir(relative)
178
190
        return remote_path
179
191
 
180
192
class SFTPTransport(SFTPUrlHandling):
198
210
    # up the request itself, rather than us having to worry about it
199
211
    _max_request_size = 32768
200
212
 
201
 
    def __init__(self, base, clone_from=None):
 
213
    def __init__(self, base, from_transport=None):
202
214
        assert base.startswith('sftp://')
203
 
        super(SFTPTransport, self).__init__(base)
204
 
        if clone_from is None:
 
215
        super(SFTPTransport, self).__init__(base, from_transport)
 
216
        if from_transport is None:
205
217
            self._sftp_connect()
206
218
        else:
207
219
            # use the same ssh connection, etc
208
 
            self._sftp = clone_from._sftp
 
220
            self._sftp = from_transport._sftp
209
221
        # super saves 'self.base'
210
222
    
211
223
    def should_cache(self):