From 0cee90eeca1c421ee1fa7078df7b91db13ecc032 Mon Sep 17 00:00:00 2001 From: Robey Pointer Date: Sun, 26 Mar 2006 16:17:26 -0800 Subject: [PATCH] [project @ robey@lag.net-20060327001726-7ccb095fd5c416f5] roll in some changes from bzr that may be necessary to get stub_sftp to work on windows --- tests/stub_sftp.py | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py index 459af06..1679e34 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: