/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/tests/stub_sftp.py

  • Committer: Jelmer Vernooij
  • Date: 2018-02-18 21:42:57 UTC
  • mto: This revision was merged to the branch mainline in revision 6859.
  • Revision ID: jelmer@jelmer.uk-20180218214257-jpevutp1wa30tz3v
Update TODO to reference Breezy, not Bazaar.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
import paramiko
24
24
import socket
25
 
import socketserver
 
25
try:
 
26
    import socketserver
 
27
except ImportError:
 
28
    import SocketServer as socketserver
26
29
import sys
27
30
import time
28
31
 
132
135
    def list_folder(self, path):
133
136
        path = self._realpath(path)
134
137
        try:
135
 
            out = []
 
138
            out = [ ]
136
139
            # TODO: win32 incorrectly lists paths with non-ascii if path is not
137
140
            # unicode. However on unix the server should only deal with
138
141
            # bytestreams and posix.listdir does the right thing
213
216
            return paramiko.SFTPServer.convert_errno(e.errno)
214
217
        return paramiko.SFTP_OK
215
218
 
216
 
    def symlink(self, target_path, path):
217
 
        path = self._realpath(path)
218
 
        try:
219
 
            os.symlink(target_path, path)
220
 
        except OSError as e:
221
 
            return paramiko.SFTPServer.convert_errno(e.errno)
222
 
        return paramiko.SFTP_OK
223
 
 
224
 
    def readlink(self, path):
225
 
        path = self._realpath(path)
226
 
        try:
227
 
            target_path = os.readlink(path)
228
 
        except OSError as e:
229
 
            return paramiko.SFTPServer.convert_errno(e.errno)
230
 
        return target_path
231
 
 
232
219
    def mkdir(self, path, attr):
233
220
        path = self._realpath(path)
234
221
        try:
253
240
            return paramiko.SFTPServer.convert_errno(e.errno)
254
241
        return paramiko.SFTP_OK
255
242
 
256
 
    # removed: chattr
 
243
    # removed: chattr, symlink, readlink
257
244
    # (nothing in bzr's sftp transport uses those)
258
245
 
259
246
 
260
247
# ------------- server test implementation --------------
261
248
 
262
 
STUB_SERVER_KEY = """\
 
249
STUB_SERVER_KEY = """
263
250
-----BEGIN RSA PRIVATE KEY-----
264
251
MIICWgIBAAKBgQDTj1bqB4WmayWNPB+8jVSYpZYk80Ujvj680pOTh2bORBjbIAyz
265
252
oWGW+GUjzKxTiiPvVmxFgx5wdsFvF03v34lEVVhMpouqPAYQ15N37K/ir5XY+9m/
393
380
        # Re-import these as locals, so that they're still accessible during
394
381
        # interpreter shutdown (when all module globals get set to None, leading
395
382
        # to confusing errors like "'NoneType' object has no attribute 'error'".
396
 
 
397
383
        class FakeChannel(object):
398
384
            def get_transport(self):
399
385
                return self
400
 
 
401
386
            def get_log_channel(self):
402
387
                return 'brz.paramiko'
403
 
 
404
388
            def get_name(self):
405
389
                return '1'
406
 
 
407
390
            def get_hexdump(self):
408
391
                return False
409
 
 
410
392
            def close(self):
411
393
                pass
412
394
 
415
397
            FakeChannel(), 'sftp', StubServer(tcs), StubSFTPServer,
416
398
            root=tcs._root, home=tcs._server_homedir)
417
399
        self.sftp_server = sftp_server
418
 
        sys_stderr = sys.stderr  # Used in error reporting during shutdown
 
400
        sys_stderr = sys.stderr # Used in error reporting during shutdown
419
401
        try:
420
402
            sftp_server.start_subsystem(
421
403
                'sftp', None, ssh.SocketAsChannelAdapter(self.request))
495
477
    def start_server(self, backing_server=None):
496
478
        # XXX: TODO: make sftpserver back onto backing_server rather than local
497
479
        # disk.
498
 
        if not (backing_server is None
499
 
                or isinstance(backing_server, test_server.LocalURLServer)):
 
480
        if not (backing_server is None or
 
481
                isinstance(backing_server, test_server.LocalURLServer)):
500
482
            raise AssertionError(
501
483
                'backing_server should not be %r, because this can only serve '
502
484
                'the local current working directory.' % (backing_server,))
507
489
            # Normalize the path or it will be wrongly escaped
508
490
            self._homedir = osutils.normpath(self._homedir)
509
491
        else:
510
 
            self._homedir = self._homedir
 
492
            # But unix SFTP servers should just deal in bytestreams
 
493
            self._homedir = self._homedir.encode('utf-8')
511
494
        if self._server_homedir is None:
512
495
            self._server_homedir = self._homedir
513
496
        self._root = '/'
586
569
        server = super(SFTPSiblingAbsoluteServer, self).create_server()
587
570
        server._server_homedir = '/dev/noone/runs/tests/here'
588
571
        return server
 
572