catacomb/pwsafe.py: Hack around the difference in octal literal syntax.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 21 Oct 2019 17:06:31 +0000 (18:06 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:44:21 +0000 (12:44 +0100)
Python 2.5 wants `0DIGITS', while Python 3 insists on `0oDIGITS'.  The
latter is prettier, but the difference is annoying.  We only need these
for Unix permissions, so just set up the ones we want in advance using
an explicit conversion from strings.

catacomb/pwsafe.py

index 6874ae8..c62bc6b 100644 (file)
@@ -50,6 +50,9 @@ _MAC = _bin('mac:')
 
 def _excval(): return _SYS.exc_info()[1]
 
+_M600 = int("600", 8)
+_M700 = int("700", 8)
+
 ###--------------------------------------------------------------------------
 ### Text encoding utilities.
 
@@ -520,7 +523,7 @@ else:
       except _G.error: raise StorageBackendRefusal(_excval())
 
     def _create(me, file):
-      me._db = _G.open(file, 'n', 0600)
+      me._db = _G.open(file, 'n', _M600)
 
     def _close(me, abruptp):
       me._db.close()
@@ -588,7 +591,7 @@ else:
         ('unknown database schema version (%d > %d)' % (ver, me.VERSION))
 
     def _create(me, file):
-      fd = _OS.open(file, _OS.O_WRONLY | _OS.O_CREAT | _OS.O_EXCL, 0600)
+      fd = _OS.open(file, _OS.O_WRONLY | _OS.O_CREAT | _OS.O_EXCL, _M600)
       _OS.close(fd)
       try:
         me._db = _Q.connect(file)
@@ -731,7 +734,7 @@ class PlainTextBackend (StorageBackend):
     me._dirtyp = False
     super(PlainTextBackend, me).__init__(*args, **kw)
 
-  def _create_file(me, file, mode = 0600, freshp = False):
+  def _create_file(me, file, mode = _M600, freshp = False):
     """
     Make sure FILE exists, creating it with the given MODE if necessary.
 
@@ -783,7 +786,7 @@ class PlainTextBackend (StorageBackend):
         if not line or line.startswith('#'): continue
         me._parse_line(line)
 
-  def _write_file(me, file, writebody, mode = 0600, magic = None):
+  def _write_file(me, file, writebody, mode = _M600, magic = None):
     """
     Update FILE atomically.
 
@@ -926,9 +929,9 @@ class DirectoryStorageBackend (PlainTextBackend):
     me._parse_meta(line)
 
   def _create(me, file):
-    _OS.mkdir(file, 0700)
-    _OS.mkdir(_OS.path.join(file, 'pw'), 0700)
-    _OS.mkdir(_OS.path.join(file, 'tmp'), 0700)
+    _OS.mkdir(file, _M700)
+    _OS.mkdir(_OS.path.join(file, 'pw'), _M700)
+    _OS.mkdir(_OS.path.join(file, 'tmp'), _M700)
     me._mark_dirty()
     me._dir = file
 
@@ -948,7 +951,7 @@ class DirectoryStorageBackend (PlainTextBackend):
     with f: return f.read()
   def _put_passwd(me, label, payload):
     new = me._pwfile(label, 'tmp')
-    fd = _OS.open(new, _OS.O_WRONLY | _OS.O_CREAT | _OS.O_TRUNC, 0600)
+    fd = _OS.open(new, _OS.O_WRONLY | _OS.O_CREAT | _OS.O_TRUNC, _M600)
     _OS.close(fd)
     with open(new, 'wb') as f: f.write(payload)
     _OS.rename(new, me._pwfile(label))