~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/tests/stub_sftp.py

  • Committer: John Arbash Meinel
  • Date: 2006-01-23 22:33:23 UTC
  • mto: This revision was merged to the branch mainline in revision 1551.
  • Revision ID: john@arbash-meinel.com-20060123223323-16eb865383bf650a
From Jari Alto: Makefile fixes (clean target error suppression)

Show diffs side-by-side

added added

removed removed

Lines of Context:
59
59
 
60
60
 
61
61
class StubSFTPServer (SFTPServerInterface):
62
 
    def __init__(self, server, root):
 
62
    def __init__(self, server, root, home=None):
63
63
        SFTPServerInterface.__init__(self, server)
64
64
        self.root = root
65
 
        
 
65
        if home is None:
 
66
            self.home = self.root
 
67
        else:
 
68
            self.home = home[len(self.root):]
 
69
        if (len(self.home) > 0) and (self.home[0] == '/'):
 
70
            self.home = self.home[1:]
 
71
 
66
72
    def _realpath(self, path):
67
73
        return self.root + self.canonicalize(path)
68
74
 
 
75
    def canonicalize(self, path):
 
76
        if os.path.isabs(path):
 
77
            return os.path.normpath(path)
 
78
        else:
 
79
            return os.path.normpath('/' + os.path.join(self.home, path))
 
80
 
69
81
    def chattr(self, path, attr):
70
82
        try:
71
83
            SFTPServer.set_file_attr(path, attr)
105
117
        try:
106
118
            if hasattr(os, 'O_BINARY'):
107
119
                flags |= os.O_BINARY
108
 
            if (attr is not None) and hasattr(attr, 'st_mode'):
 
120
            if getattr(attr, 'st_mode', None):
109
121
                fd = os.open(path, flags, attr.st_mode)
110
122
            else:
111
123
                fd = os.open(path, flags)
151
163
    def mkdir(self, path, attr):
152
164
        path = self._realpath(path)
153
165
        try:
154
 
            if attr is not None and hasattr(attr, 'st_mode'):
 
166
            # Using getattr() in case st_mode is None or 0
 
167
            # both evaluate to False
 
168
            if getattr(attr, 'st_mode', None):
155
169
                os.mkdir(path, attr.st_mode)
156
170
            else:
157
171
                os.mkdir(path)