*.py: Add parentheses around `print' arguments.
authorMark Wooding <mdw@distorted.org.uk>
Mon, 21 Oct 2019 16:57:29 +0000 (17:57 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sat, 11 Apr 2020 11:44:21 +0000 (12:44 +0100)
For `print >>FILE', just switch to `FILE.write(...)' instead, with an
explicit newline.

algorithms.py
pock
pwsafe

index 35c8874..2444382 100644 (file)
@@ -51,41 +51,41 @@ hmodes = '''
 mgf hmac
 '''.split()
 
-print '/* algorithms.h [generated] */'
-print
+print('/* algorithms.h [generated] */')
+print('')
 
 for i in prps:
-  print '#include <catacomb/%s.h>' % i.replace('/', '-')
+  print('#include <catacomb/%s.h>' % i.replace('/', '-'))
   for j in pmodes:
-    print '#include <catacomb/%s-%s.h>' % (i.replace('/', '-'), j)
+    print('#include <catacomb/%s-%s.h>' % (i.replace('/', '-'), j))
 for i in streamciphers:
-  print '#include <catacomb/%s.h>' % i.replace('/', '-')
-print
+  print('#include <catacomb/%s.h>' % i.replace('/', '-'))
+print('')
 for i in hashes:
-  print '#include <catacomb/%s.h>' % i.replace('/', '-')
+  print('#include <catacomb/%s.h>' % i.replace('/', '-'))
   for j in hmodes:
-    print '#include <catacomb/%s-%s.h>' % (i.replace('/', '-'), j)
-print
+    print('#include <catacomb/%s-%s.h>' % (i.replace('/', '-'), j))
+print('')
 
-print '#define PRPS(_) \\'
+print('#define PRPS(_) \\')
 for i in prps:
-  print '\t_(%s, %s) \\' % (i.upper(), i)
-print '\t/* end */'
-print
+  print('\t_(%s, %s) \\' % (i.upper(), i))
+print('\t/* end */')
+print('')
 
-print '#define RNGS(_) \\'
+print('#define RNGS(_) \\')
 for i in (cross(prps, ['ofb', 'counter'])):
-  print ('\t_("%(prim)s-%(mode)s", %(primid)s_keysz, ' +
-         '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') % \
-         {'prim': i[0], 'mode': i[1],
-          'primid': i[0].replace('-', '_').replace('/', '_')}
+  print(('\t_("%(prim)s-%(mode)s", %(primid)s_keysz, ' +
+         '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') %
+        {'prim': i[0], 'mode': i[1],
+         'primid': i[0].replace('-', '_').replace('/', '_')})
 for i in (cross(hashes, 'mgf')):
-  print ('\t_("%(prim)s-%(mode)s", %(primid)s_%(mode)skeysz, ' +
-         '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') % \
-         {'prim': i[0], 'mode': i[1],
-          'primid': i[0].replace('-', '_').replace('/', '_')}
-print '\t_("rc4", rc4_keysz, rc4_rand, 0, 0) \\'
-print '\t_("seal", seal_keysz, seal_rand, RNG_SEAL, 0) \\'
+  print(('\t_("%(prim)s-%(mode)s", %(primid)s_%(mode)skeysz, ' +
+         '%(primid)s_%(mode)srand, RNG_PLAIN, 0) \\') %
+        {'prim': i[0], 'mode': i[1],
+         'primid': i[0].replace('-', '_').replace('/', '_')})
+print('\t_("rc4", rc4_keysz, rc4_rand, 0, 0) \\')
+print('\t_("seal", seal_keysz, seal_rand, RNG_SEAL, 0) \\')
 for i in latindances:
   for r in ['salsa20', 'xsalsa20', 'chacha', 'xchacha']:
     if i.startswith(r):
@@ -94,16 +94,16 @@ for i in latindances:
   else:
     raise ValueError('failed to find root name for %s' % i)
   if i.endswith('-ietf'): root += '_ietf'
-  print ('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' +
+  print(('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' +
          'RNG_LATIN, %(ROOT)s_NONCESZ) \\') % \
-      {'name': i, 'id': i.replace('/', '').replace('-', '_'),
-       'root': root, 'ROOT': root.upper()}
+        {'name': i, 'id': i.replace('/', '').replace('-', '_'),
+         'root': root, 'ROOT': root.upper()})
 for i in [128, 256]:
-  print ('\t_("shake%(w)d", shake%(w)d_keysz, cshake%(w)d_rand, ' +
+  print(('\t_("shake%(w)d", shake%(w)d_keysz, cshake%(w)d_rand, ' +
          'RNG_SHAKE, 0) \\') % \
-         {'w': i}
-  print ('\t_("kmac%(w)d", kmac%(w)d_keysz, kmac%(w)d_rand, ' +
+        {'w': i})
+  print(('\t_("kmac%(w)d", kmac%(w)d_keysz, kmac%(w)d_rand, ' +
          'RNG_KMAC, 0) \\') % \
-         {'w': i}
-print '\t/* end */'
-print
+        {'w': i})
+print('\t/* end */')
+print('')
diff --git a/pock b/pock
index 2df5fd2..a980cbe 100644 (file)
--- a/pock
+++ b/pock
@@ -607,7 +607,7 @@ def check(pp, line):
   if p.nbits != nb:
     raise ExpectedError('check failed: nbits(%s) = %d /= %d' % \
                         (label, p.nbits, nb))
-  if VERBOSITY: print ';; %s = %d [%d]' % (label, p, nb)
+  if VERBOSITY: print(';; %s = %d [%d]' % (label, p, nb))
 
 def setsievebits(pp, line):
   """
diff --git a/pwsafe b/pwsafe
index 6a3dfae..205df23 100644 (file)
--- a/pwsafe
+++ b/pwsafe
@@ -51,7 +51,7 @@ prog = re.sub(r'^.*[/\\]', '', argv[0])
 
 def moan(msg):
   """Issue a warning message MSG."""
-  print >>stderr, '%s: %s' % (prog, msg)
+  stderr.write('%s: %s\n' % (prog, msg))
 
 def die(msg):
   """Report MSG as a fatal error, and exit."""
@@ -99,7 +99,7 @@ def cmd_changepp(av):
 def cmd_find(av):
   if len(av) != 1: return 1
   with PW(file) as pw:
-    try: print pw[av[0]]
+    try: print(pw[av[0]])
     except KeyError: die("Password `%s' not found" % _excval().args[0])
 
 def cmd_store(av):
@@ -131,7 +131,7 @@ def cmd_list(av):
     if len(av) >= 1: pat = av[0]
     else: pat = None
     for k in pw:
-      if pat is None or fnmatch(k, pat): print k
+      if pat is None or fnmatch(k, pat): print(k)
 
 def cmd_topixie(av):
   if len(av) > 2: return 1
@@ -186,18 +186,18 @@ commands = { 'create': [cmd_create,
 ### Command-line handling and dispatch.
 
 def version():
-  print '%s 1.0.0' % prog
-  print 'Backend types: %s' % \
-      ' '.join([c.NAME for c in StorageBackend.classes()])
+  print('%s 1.0.0' % prog)
+  print('Backend types: %s' %
+        ' '.join([c.NAME for c in StorageBackend.classes()]))
 
 def usage(fp):
-  print >>fp, 'Usage: %s COMMAND [ARGS...]' % prog
+  fp.write('Usage: %s COMMAND [ARGS...]\n' % prog)
 
 def help():
   version()
-  print
+  print('')
   usage(stdout)
-  print '''
+  print('''
 Maintains passwords or other short secrets securely.
 
 Options:
@@ -209,9 +209,9 @@ Options:
 -f, --file=FILE                Where to find the password-safe file.
 
 Commands provided:
-'''
+''')
   for c in sorted(commands):
-    print '%s %s' % (c, commands[c][1])
+    print('%s %s' % (c, commands[c][1]))
 
 ## Choose a default database file.
 if 'PWSAFE' in environ:
@@ -252,7 +252,7 @@ else:
   c = 'find'
 try:
   if commands[c][0](argv):
-    print >>stderr, 'Usage: %s %s %s' % (prog, c, commands[c][1])
+    stderr.write('Usage: %s %s %s\n' % (prog, c, commands[c][1]))
     exit(1)
 except DecryptError:
   die("decryption failure")