From 41be2e3061e2a824e9960751bdfbae57749671bf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kamil=20Cholewi=C5=84ski?= Date: Fri, 10 Apr 2015 10:26:44 +0200 Subject: [PATCH] Python 3 support: octal syntax --- boltons/fileutils.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/boltons/fileutils.py b/boltons/fileutils.py index 98582c4..a5157a6 100644 --- a/boltons/fileutils.py +++ b/boltons/fileutils.py @@ -67,8 +67,10 @@ class FilePerms(object): >>> FilePerms(user='rwx', group='xrw', other='wxr') # note character order FilePerms(user='rwx', group='rwx', other='rwx') - >>> oct(int(FilePerms('r', 'r', ''))) - '0440' + >>> int(FilePerms('r', 'r', '')) + 288 + >>> oct(288)[-3:] # XXX Py3k + '440' See also the :meth:`FilePerms.from_int` and :meth:`FilePerms.from_path` classmethods for useful alternative @@ -127,14 +129,14 @@ class FilePerms(object): def from_int(cls, i): """Create a :class:`FilePerms` object from an integer. - >>> FilePerms.from_int(0644) # note the leading zero for octal + >>> FilePerms.from_int(0o644) # note the leading zero-oh for octal FilePerms(user='rw', group='r', other='r') """ - i &= 0777 + i &= 0o777 key = ('', 'x', 'w', 'xw', 'r', 'rx', 'rw', 'rwx') parts = [] while i: - parts.append(key[i & 07]) + parts.append(key[i & 0o7]) i >>= 3 parts.reverse() return cls(*parts)