*.py: Use `str.replace' rather than `str.translate'.
authorMark Wooding <mdw@distorted.org.uk>
Sat, 19 Oct 2019 16:10:41 +0000 (17:10 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Sun, 17 Nov 2019 01:41:01 +0000 (01:41 +0000)
It seems that the `None' argument to `str.translate' was a brief
experiment added in 2.6 which didn't survive into 3.0.

algorithms.py
catacomb/__init__.py
catacomb/pwsafe.py

index 0fa434a..46abccb 100644 (file)
@@ -37,7 +37,7 @@ chacha20 chacha12 chacha8
 chacha20-ietf chacha12-ietf chacha8-ietf
 xchacha20 xchacha12 xchacha8
 '''.split()
-streamciphers += map(lambda s: s.translate(None, '/'), latindances)
+streamciphers += map(lambda s: s.replace('/', ''), latindances)
 hashes = '''
 md2 md4 md5 tiger has160
 sha sha224 sha256 sha512/224 sha512/256 sha384 sha512
@@ -94,7 +94,7 @@ for i in latindances:
   if i.endswith('-ietf'): root += '_ietf'
   print ('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' +
          'RNG_LATIN, %(ROOT)s_NONCESZ) \\') % \
-      {'name': i, 'id': i.translate(None, '/').replace('-', '_'),
+      {'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, ' +
index e283744..5399182 100644 (file)
@@ -46,7 +46,7 @@ def _fixname(name):
   name = name.replace('-', '_')
 
   ## But slashes might become underscores or just vanish.
-  if name.startswith('salsa20'): name = name.translate(None, '/')
+  if name.startswith('salsa20'): name = name.replace('/', '')
   else: name = name.replace('/', '_')
 
   ## Done.
index cfbac7e..03ed685 100644 (file)
@@ -80,7 +80,7 @@ def _dec_metaname(name):
 
 def _b64(s):
   """Encode S as base64, without newlines, and trimming `=' padding."""
-  return s.encode('base64').translate(None, '\n=')
+  return s.encode('base64').replace('\n', '').rstrip('=')
 def _unb64(s):
   """Decode S as base64 with trimmed `=' padding."""
   return (s + '='*((4 - len(s))%4)).decode('base64')