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/3e80d3274c1a4c54beb9033cccfa2d5c100d4a2a?ds=sidebyside *.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 0fa434a..46abccb 100644 --- a/algorithms.py +++ b/algorithms.py @@ -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, ' + diff --git a/catacomb/__init__.py b/catacomb/__init__.py index e283744..5399182 100644 --- a/catacomb/__init__.py +++ b/catacomb/__init__.py @@ -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. diff --git a/catacomb/pwsafe.py b/catacomb/pwsafe.py index cfbac7e..03ed685 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')