From 86fe372a2c3eb13cdf25a050ff1d63f6d9b4d991 Mon Sep 17 00:00:00 2001 From: Dorian Pula Date: Tue, 13 Aug 2013 16:10:56 -0400 Subject: [PATCH] [Python 3]: New octal syntax. --- paramiko/pkey.py | 4 ++-- paramiko/sftp_attr.py | 4 ++-- paramiko/sftp_client.py | 4 ++-- tests/stub_sftp.py | 4 ++-- tests/test_sftp.py | 20 ++++++++++---------- tests/test_sftp_big.py | 2 +- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/paramiko/pkey.py b/paramiko/pkey.py index 4a0653d..e925bb6 100644 --- a/paramiko/pkey.py +++ b/paramiko/pkey.py @@ -346,9 +346,9 @@ class PKey (object): @raise IOError: if there was an error writing the file. """ - f = open(filename, 'w', 0600) + f = open(filename, 'w', 0o600) # grrr... the mode doesn't always take hold - os.chmod(filename, 0600) + os.chmod(filename, 0o600) self._write_private_key(tag, f, data, password) f.close() diff --git a/paramiko/sftp_attr.py b/paramiko/sftp_attr.py index 1f09421..59a823b 100644 --- a/paramiko/sftp_attr.py +++ b/paramiko/sftp_attr.py @@ -194,8 +194,8 @@ class SFTPAttributes (object): ks = 's' else: ks = '?' - ks += self._rwx((self.st_mode & 0700) >> 6, self.st_mode & stat.S_ISUID) - ks += self._rwx((self.st_mode & 070) >> 3, self.st_mode & stat.S_ISGID) + ks += self._rwx((self.st_mode & 0o700) >> 6, self.st_mode & stat.S_ISUID) + ks += self._rwx((self.st_mode & 0o70) >> 3, self.st_mode & stat.S_ISGID) ks += self._rwx(self.st_mode & 7, self.st_mode & stat.S_ISVTX, True) else: ks = '?---------' diff --git a/paramiko/sftp_client.py b/paramiko/sftp_client.py index 689dcf7..86b272a 100644 --- a/paramiko/sftp_client.py +++ b/paramiko/sftp_client.py @@ -285,10 +285,10 @@ class SFTPClient (BaseSFTP): self._log(DEBUG, 'rename(%r, %r)' % (oldpath, newpath)) self._request(CMD_RENAME, oldpath, newpath) - def mkdir(self, path, mode=0777): + def mkdir(self, path, mode= 0o777): """ Create a folder (directory) named C{path} with numeric mode C{mode}. - The default mode is 0777 (octal). On some systems, mode is ignored. + The default mode is 0o777 (octal). On some systems, mode is ignored. Where it is used, the current umask value is first masked out. @param path: name of the folder to create diff --git a/tests/stub_sftp.py b/tests/stub_sftp.py index e960967..195e567 100644 --- a/tests/stub_sftp.py +++ b/tests/stub_sftp.py @@ -95,9 +95,9 @@ class StubSFTPServer (SFTPServerInterface): if mode is not None: fd = os.open(path, flags, mode) else: - # os.open() defaults to 0777 which is + # os.open() defaults to 0o777 which is # an odd default mode for files - fd = os.open(path, flags, 0666) + fd = os.open(path, flags, 0o666) except OSError as e: return SFTPServer.convert_errno(e.errno) if (flags & os.O_CREAT) and (attr is not None): diff --git a/tests/test_sftp.py b/tests/test_sftp.py index e9615b4..459d17c 100755 --- a/tests/test_sftp.py +++ b/tests/test_sftp.py @@ -300,16 +300,16 @@ class SFTPTest (unittest.TestCase): f.close() stat = sftp.stat(FOLDER + '/special') - sftp.chmod(FOLDER + '/special', (stat.st_mode & ~0777) | 0600) + sftp.chmod(FOLDER + '/special', (stat.st_mode & ~0o777) | 0o600) stat = sftp.stat(FOLDER + '/special') - expected_mode = 0600 + expected_mode = 0o600 if sys.platform == 'win32': # chmod not really functional on windows - expected_mode = 0666 + expected_mode = 0o666 if sys.platform == 'cygwin': # even worse. - expected_mode = 0644 - self.assertEqual(stat.st_mode & 0777, expected_mode) + expected_mode = 0o644 + self.assertEqual(stat.st_mode & 0o777, expected_mode) self.assertEqual(stat.st_size, 1024) mtime = stat.st_mtime - 3600 @@ -340,17 +340,17 @@ class SFTPTest (unittest.TestCase): f = sftp.open(FOLDER + '/special', 'r+') stat = f.stat() - f.chmod((stat.st_mode & ~0777) | 0600) + f.chmod((stat.st_mode & ~0o777) | 0o600) stat = f.stat() - expected_mode = 0600 + expected_mode = 0o600 if sys.platform == 'win32': # chmod not really functional on windows - expected_mode = 0666 + expected_mode = 0o666 if sys.platform == 'cygwin': # even worse. - expected_mode = 0644 - self.assertEqual(stat.st_mode & 0777, expected_mode) + expected_mode = 0o644 + self.assertEqual(stat.st_mode & 0o777, expected_mode) self.assertEqual(stat.st_size, 1024) mtime = stat.st_mtime - 3600 diff --git a/tests/test_sftp_big.py b/tests/test_sftp_big.py index a32a700..d1d328e 100644 --- a/tests/test_sftp_big.py +++ b/tests/test_sftp_big.py @@ -68,7 +68,7 @@ class BigSFTPTest (unittest.TestCase): f = sftp.open('%s/file%d.txt' % (FOLDER, i), 'w', 1) f.write('this is file #%d.\n' % i) f.close() - sftp.chmod('%s/file%d.txt' % (FOLDER, i), 0660) + sftp.chmod('%s/file%d.txt' % (FOLDER, i), 0o660) # now make sure every file is there, by creating a list of filenmes # and reading them in random order.