From: Mark Wooding Date: Sat, 19 Oct 2019 16:10:41 +0000 (+0100) Subject: *.py: Use `str.replace' rather than `str.translate'. X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/catacomb-python/commitdiff_plain/2b1672ca4d5d93f1cbad3acbd728d3fa32986cdb *.py: Use `str.replace' rather than `str.translate'. It seems that the `None' argument to `str.translate' was a brief experiment added in 2.6 which didn't survive into 3.0. --- diff --git a/algorithms.py b/algorithms.py index 3ceb207..84ea439 100644 --- a/algorithms.py +++ b/algorithms.py @@ -33,7 +33,7 @@ latindances = ''' salsa20 salsa20/12 salsa20/8 xsalsa20 xsalsa20/12 xsalsa20/8 chacha20 chacha12 chacha8 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 sha384 sha512 @@ -86,7 +86,7 @@ for i in latindances: raise ValueError, 'failed to find root name for %s' % i print ('\t_("%(name)s", %(root)s_keysz, %(id)s_rand, ' + 'RNGF_NONCE, %(ROOT)s_NONCESZ) \\') % \ - {'name': i, 'id': i.translate(None, '/'), + {'name': i, 'id': i.replace('/', ''), 'root': root, 'ROOT': root.upper()} print '\t/* end */' print diff --git a/catacomb/__init__.py b/catacomb/__init__.py index f79b4d2..d29aa95 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -42,7 +42,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. diff --git a/catacomb/pwsafe.py b/catacomb/pwsafe.py index 4b4b994..f3af1b9 100644 --- a/catacomb/pwsafe.py +++ b/catacomb/pwsafe.py @@ -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')