~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/transport/sftp.py

  • Committer: Robert Collins
  • Date: 2007-07-04 08:08:13 UTC
  • mfrom: (2572 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2587.
  • Revision ID: robertc@robertcollins.net-20070704080813-wzebx0r88fvwj5rq
Merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2005 Robey Pointer <robey@lag.net>
2
 
# Copyright (C) 2005, 2006 Canonical Ltd
 
2
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
3
3
#
4
4
# This program is free software; you can redistribute it and/or modify
5
5
# it under the terms of the GNU General Public License as published by
51
51
from bzrlib.trace import mutter, warning
52
52
from bzrlib.transport import (
53
53
    LateReadError,
 
54
    local,
54
55
    register_urlparse_netloc_protocol,
55
56
    Server,
56
57
    split_url,
1078
1079
        ssh_server.start_server(event, server)
1079
1080
        event.wait(5.0)
1080
1081
    
1081
 
    def setUp(self):
1082
 
        self._original_vendor = ssh._ssh_vendor
1083
 
        ssh._ssh_vendor = self._vendor
 
1082
    def setUp(self, backing_server=None):
 
1083
        # XXX: TODO: make sftpserver back onto backing_server rather than local
 
1084
        # disk.
 
1085
        assert (backing_server is None or
 
1086
                isinstance(backing_server, local.LocalURLServer)), (
 
1087
            "backing_server should not be %r, because this can only serve the "
 
1088
            "local current working directory." % (backing_server,))
 
1089
        self._original_vendor = ssh._ssh_vendor_manager._cached_ssh_vendor
 
1090
        ssh._ssh_vendor_manager._cached_ssh_vendor = self._vendor
1084
1091
        if sys.platform == 'win32':
1085
1092
            # Win32 needs to use the UNICODE api
1086
1093
            self._homedir = getcwd()
1099
1106
    def tearDown(self):
1100
1107
        """See bzrlib.transport.Server.tearDown."""
1101
1108
        self._listener.stop()
1102
 
        ssh._ssh_vendor = self._original_vendor
 
1109
        ssh._ssh_vendor_manager._cached_ssh_vendor = self._original_vendor
1103
1110
 
1104
1111
    def get_bogus_url(self):
1105
1112
        """See bzrlib.transport.Server.get_bogus_url."""
1116
1123
 
1117
1124
    def get_url(self):
1118
1125
        """See bzrlib.transport.Server.get_url."""
1119
 
        return self._get_sftp_url(urlutils.escape(self._homedir[1:]))
 
1126
        homedir = self._homedir
 
1127
        if sys.platform != 'win32':
 
1128
            # Remove the initial '/' on all platforms but win32
 
1129
            homedir = homedir[1:]
 
1130
        return self._get_sftp_url(urlutils.escape(homedir))
1120
1131
 
1121
1132
 
1122
1133
class SFTPServerWithoutSSH(SFTPServer):
1154
1165
            else:
1155
1166
                raise
1156
1167
        except Exception, e:
1157
 
            import sys; sys.stderr.write('\nEXCEPTION %r\n\n' % e.__class__)
 
1168
            # This typically seems to happen during interpreter shutdown, so
 
1169
            # most of the useful ways to report this error are won't work.
 
1170
            # Writing the exception type, and then the text of the exception,
 
1171
            # seems to be the best we can do.
 
1172
            import sys
 
1173
            sys.stderr.write('\nEXCEPTION %r: ' % (e.__class__,))
 
1174
            sys.stderr.write('%s\n\n' % (e,))
1158
1175
        server.finish_subsystem()
1159
1176
 
1160
1177
 
1163
1180
 
1164
1181
    def get_url(self):
1165
1182
        """See bzrlib.transport.Server.get_url."""
1166
 
        if sys.platform == 'win32':
1167
 
            return self._get_sftp_url(urlutils.escape(self._homedir))
1168
 
        else:
1169
 
            return self._get_sftp_url(urlutils.escape(self._homedir[1:]))
 
1183
        homedir = self._homedir
 
1184
        if sys.platform != 'win32':
 
1185
            # Remove the initial '/' on all platforms but win32
 
1186
            homedir = homedir[1:]
 
1187
        return self._get_sftp_url(urlutils.escape(homedir))
1170
1188
 
1171
1189
 
1172
1190
class SFTPHomeDirServer(SFTPServerWithoutSSH):
1178
1196
 
1179
1197
 
1180
1198
class SFTPSiblingAbsoluteServer(SFTPAbsoluteServer):
1181
 
    """A test servere for sftp transports, using absolute urls to non-home."""
1182
 
 
1183
 
    def setUp(self):
 
1199
    """A test server for sftp transports where only absolute paths will work.
 
1200
 
 
1201
    It does this by serving from a deeply-nested directory that doesn't exist.
 
1202
    """
 
1203
 
 
1204
    def setUp(self, backing_server=None):
1184
1205
        self._server_homedir = '/dev/noone/runs/tests/here'
1185
 
        super(SFTPSiblingAbsoluteServer, self).setUp()
 
1206
        super(SFTPSiblingAbsoluteServer, self).setUp(backing_server)
1186
1207
 
1187
1208
 
1188
1209
def _sftp_connect(host, port, username, password):