summaryrefslogtreecommitdiffhomepage
path: root/tests/stub_sftp.py
diff options
context:
space:
mode:
Diffstat (limited to 'tests/stub_sftp.py')
-rw-r--r--tests/stub_sftp.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py
index 459af066..1679e34e 100644
--- a/tests/stub_sftp.py
+++ b/tests/stub_sftp.py
@@ -91,18 +91,25 @@ class StubSFTPServer (SFTPServerInterface):
def open(self, path, flags, attr):
path = self._realpath(path)
try:
- fd = os.open(path, flags)
+ binary_flag = getattr(os, 'O_BINARY', 0)
+ flags |= binary_flag
+ mode = getattr(attr, 'st_mode', None)
+ if mode is not None:
+ fd = os.open(path, flags, mode)
+ else:
+ fd = os.open(path, flags)
except OSError, e:
return SFTPServer.convert_errno(e.errno)
if (flags & os.O_CREAT) and (attr is not None):
+ attr._flags &= ~attr.FLAG_PERMISSIONS
SFTPServer.set_file_attr(path, attr)
if flags & os.O_WRONLY:
- fstr = 'w'
+ fstr = 'wb'
elif flags & os.O_RDWR:
- fstr = 'r+'
+ fstr = 'r+b'
else:
# O_RDONLY (== 0)
- fstr = 'r'
+ fstr = 'rb'
try:
f = os.fdopen(fd, fstr)
except OSError, e: