~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/stub_sftp.py

first cut at merge from integration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
22
22
import os
23
23
from paramiko import ServerInterface, SFTPServerInterface, SFTPServer, SFTPAttributes, \
24
24
    SFTPHandle, SFTP_OK, AUTH_SUCCESSFUL, OPEN_SUCCEEDED
25
 
 
26
25
from bzrlib.osutils import pathjoin
27
26
from bzrlib.trace import mutter
28
27
 
29
28
 
30
29
class StubServer (ServerInterface):
31
 
 
32
30
    def __init__(self, test_case):
33
31
        ServerInterface.__init__(self)
34
32
        self._test_case = test_case
61
59
 
62
60
 
63
61
class StubSFTPServer (SFTPServerInterface):
64
 
 
65
62
    def __init__(self, server, root, home=None):
66
63
        SFTPServerInterface.__init__(self, server)
67
64
        self.root = root
93
90
        path = self._realpath(path)
94
91
        try:
95
92
            out = [ ]
96
 
            # TODO: win32 incorrectly lists paths with non-ascii if path is not
97
 
            # unicode. However on Linux the server should only deal with
98
 
            # bytestreams and posix.listdir does the right thing 
99
93
            flist = os.listdir(path)
100
94
            for fname in flist:
101
95
                attr = SFTPAttributes.from_stat(os.stat(pathjoin(path, fname)))
130
124
                fd = os.open(path, flags)
131
125
        except OSError, e:
132
126
            return SFTPServer.convert_errno(e.errno)
133
 
 
134
127
        if (flags & os.O_CREAT) and (attr is not None):
135
128
            attr._flags &= ~attr.FLAG_PERMISSIONS
136
129
            SFTPServer.set_file_attr(path, attr)