chiark / gitweb /
catacomb/pwsafe.py, pwsafe: Replace `PW''s MODE parameter with WRITEP flag.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 24 May 2015 15:38:11 +0000 (16:38 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Thu, 28 May 2015 10:21:01 +0000 (11:21 +0100)
This abstracts away from the GDBM interface slightly, and makes it a bit
more convenient for other implementations.

catacomb/pwsafe.py
pwsafe

index 65aec712d09e5a2b62381d4ca88240db0e14b7f1..1e8e4dbfeb41ce1097be5868c2a1b985922a658d 100644 (file)
@@ -161,17 +161,17 @@ class PW (object):
   using the stored keys.
   """
 
-  def __init__(me, file, mode = 'r'):
+  def __init__(me, file, writep = False):
     """
     Initialize a PW object from the GDBM database in FILE.
 
-    MODE can be `r' for read-only access to the underlying database, or `w'
-    for read-write access.  Requests the database password from the Pixie,
+    If WRITEP is true, then allow write-access to the database; otherwise
+    allow read access only.  Requests the database password from the Pixie,
     which may cause interaction.
     """
 
     ## Open the database.
-    me.db = _G.open(file, mode)
+    me.db = _G.open(file, writep and 'w' or 'r')
 
     ## Find out what crypto to use.
     c = _C.gcciphers[me.db['cipher']]
diff --git a/pwsafe b/pwsafe
index a3365e72510c76dcf078619e294180b5c3de904e..d4a4547fa8077a64b609e10b278a6e5988b743da 100644 (file)
--- a/pwsafe
+++ b/pwsafe
@@ -97,7 +97,7 @@ def cmd_create(av):
 def cmd_changepp(av):
   if len(av) != 0:
     return 1
-  pw = PW(file, 'w')
+  pw = PW(file, writep = True)
   pw.changepp()
 
 def cmd_find(av):
@@ -122,7 +122,7 @@ def cmd_store(av):
     pp = stdin.readline()
   else:
     pp = av[1]
-  pw = PW(file, 'w')
+  pw = PW(file, writep = True)
   pw[av[0]] = chomp(pp)
 
 def cmd_copy(av):
@@ -169,7 +169,7 @@ def cmd_topixie(av):
 def cmd_del(av):
   if len(av) != 1:
     return 1
-  pw = PW(file, 'w')
+  pw = PW(file, writep = True)
   tag = av[0]
   try:
     del pw[tag]