Rev 2512: Hearing jam saying "vila, you're trying too hard", I simplified again. in file:///v/home/vila/src/experimental/reuse.transports/
Vincent Ladeuil
v.ladeuil+lp at free.fr
Sat Jun 2 15:40:29 BST 2007
At file:///v/home/vila/src/experimental/reuse.transports/
------------------------------------------------------------
revno: 2512
revision-id: v.ladeuil+lp at free.fr-20070602144026-bvhq9zlis7l6qe7j
parent: v.ladeuil+lp at free.fr-20070601204435-bd379jw1ux7id111
committer: Vincent Ladeuil <v.ladeuil+lp at free.fr>
branch nick: reuse.transports
timestamp: Sat 2007-06-02 16:40:26 +0200
message:
Hearing jam saying "vila, you're trying too hard", I simplified again.
* bzrlib/transport/sftp.py:
(SFTPUrlHandling): Simplified to the point only _remote_path
remains at which point _remote_path have been put under
SFTPTransport and the class itself deleted.
(SFTPTransport._remote_path): This is the only point where home
dir related processing needs to occur. (another use case for
tracking moving lines).
* bzrlib/tests/test_sftp_transport.py:
(SFTPTransportTestRelativeRoot.test__remote_path_relative_root):
Internally we use '/~/' to indicate home dir relative paths, only
_remote_path will strip that.
modified:
bzrlib/tests/test_sftp_transport.py testsftp.py-20051027032739-247570325fec7e7e
bzrlib/transport/sftp.py sftp.py-20051019050329-ab48ce71b7e32dfe
-------------- next part --------------
=== modified file 'bzrlib/tests/test_sftp_transport.py'
--- a/bzrlib/tests/test_sftp_transport.py 2007-06-01 20:26:46 +0000
+++ b/bzrlib/tests/test_sftp_transport.py 2007-06-02 14:40:26 +0000
@@ -149,8 +149,9 @@
def test__remote_path_relative_root(self):
# relative paths are preserved
t = self.get_transport('')
- # the remote path should be ''
- self.assertEqual('', t._path)
+ self.assertEqual('/~/', t._path)
+ # the remote path should be relative to home dir
+ # (i.e. not begining with a '/')
self.assertEqual('a', t._remote_path('a'))
@@ -179,7 +180,7 @@
self.assertEquals(s._user, 'robey')
# FIXME: sftp should just not connect at init time !!!
#self.assertEquals(s._password, 'h at t')
- self.assertEquals(s._path, 'relative/')
+ self.assertEquals(s._path, '/~/relative/')
def test_relpath(self):
s = SFTPTransport('sftp://user@host.com/abs/path',
=== modified file 'bzrlib/transport/sftp.py'
--- a/bzrlib/transport/sftp.py 2007-06-01 20:26:46 +0000
+++ b/bzrlib/transport/sftp.py 2007-06-02 14:40:26 +0000
@@ -134,62 +134,7 @@
pass
-class SFTPUrlHandling(ConnectedTransport):
- """Mix-in that does common handling of SSH/SFTP URLs."""
-
- def _urlencode_abspath(self, abspath):
- abspath = super(SFTPUrlHandling, self)._urlencode_abspath(abspath)
- # handle homedir paths
- if not abspath.startswith('/'):
- abspath = "/~/" + abspath
- return abspath
-
- def _urldecode_abspath(self, abspath):
- abspath = super(SFTPUrlHandling, self)._urldecode_abspath(abspath)
- if abspath.startswith('/~/'):
- abspath = abspath[3:]
- elif abspath == '/~':
- abspath = ''
- return abspath
-
- def _combine_paths_respecting_home_dir(self, relpath):
- # the initial slash should be removed from the path, and treated
- # as a homedir relative path (the path begins with a double slash
- # if it is absolute).
- # see draft-ietf-secsh-scp-sftp-ssh-uri-03.txt
- # RBC 20060118 we are not using this as its too user hostile. instead
- # we are following lftp and using /~/foo to mean '~/foo'.
-
- if not self._path.startswith('/'):
- abspath = self._combine_paths('/~/' + self._path, relpath)
- if abspath.startswith('/~/'):
- abspath = abspath[3:]
- elif abspath == '/~':
- abspath = ''
- else:
- abspath = self._combine_paths(self._path, relpath)
-
- return abspath
-
- def abspath(self, relpath):
- """Return the full url to the given relative path respecting home dir"""
- relative = urlutils.unescape(relpath).encode('utf-8')
- path = self._combine_paths_respecting_home_dir(relative)
- return self._unsplit_url(self._scheme, self._user, self._password,
- self._host, self._port,
- self._urlencode_abspath(path))
-
-
- def _remote_path(self, relpath):
- """Return the path to be passed along the sftp protocol for relpath.
-
- :param relpath: is a urlencoded string.
- """
- relative = urlutils.unescape(relpath).encode('utf-8')
- remote_path = self._combine_paths_respecting_home_dir(relative)
- return remote_path
-
-class SFTPTransport(SFTPUrlHandling):
+class SFTPTransport(ConnectedTransport):
"""Transport implementation for SFTP access."""
_do_prefetch = _default_do_prefetch
@@ -219,7 +164,26 @@
# use the same ssh connection, etc
self._sftp = from_transport._sftp
# super saves 'self.base'
-
+
+ def _remote_path(self, relpath):
+ """Return the path to be passed along the sftp protocol for relpath.
+
+ :param relpath: is a urlencoded string.
+ """
+ relative = urlutils.unescape(relpath).encode('utf-8')
+ remote_path = self._combine_paths(self._path, relative)
+ # the initial slash should be removed from the path, and treated as a
+ # homedir relative path (the path begins with a double slash if it is
+ # absolute). see draft-ietf-secsh-scp-sftp-ssh-uri-03.txt
+ # RBC 20060118 we are not using this as its too user hostile. instead
+ # we are following lftp and using /~/foo to mean '~/foo'
+ # vila--20070602 and leave absolute paths begin with a single slash.
+ if remote_path.startswith('/~/'):
+ remote_path = remote_path[3:]
+ elif remote_path == '/~':
+ remote_path = ''
+ return remote_path
+
def should_cache(self):
"""
Return True if the data pulled across should be cached locally.
More information about the bazaar-commits
mailing list