From 895ba55cf7759ed7a76eb77b435bbd038fe6a759 Mon Sep 17 00:00:00 2001 From: Jean-Paul Calderone Date: Wed, 16 Dec 2020 18:17:14 -0500 Subject: [PATCH] Python 3 compatibility --- src/allmydata/test/test_introducer.py | 6 +++--- src/allmydata/util/base32.py | 4 +++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/allmydata/test/test_introducer.py b/src/allmydata/test/test_introducer.py index 1ba928257..0475d3f6c 100644 --- a/src/allmydata/test/test_introducer.py +++ b/src/allmydata/test/test_introducer.py @@ -1071,9 +1071,9 @@ class Signatures(SyncTestCase): (msg, sig, key) = sign_to_foolscap(ann, private_key) # Drop a base32 word from the middle of the key to invalidate the # signature. - sig_l = list(sig) - sig_l[20:22] = [] - sig = b"".join(sig_l) + sig_a = bytearray(sig) + sig_a[20:22] = [] + sig = bytes(sig_a) ann_t = (msg, sig, key) ic.got_announcements([ann_t]) diff --git a/src/allmydata/util/base32.py b/src/allmydata/util/base32.py index 287d214ea..41c0f0413 100644 --- a/src/allmydata/util/base32.py +++ b/src/allmydata/util/base32.py @@ -140,7 +140,9 @@ def a2b(cs): # Add padding back, to make Python's base64 module happy: while (len(cs) * 5) % 8 != 0: cs += b"=" - return base64.b32decode(cs) + # Let newbytes come through and still work on Python 2, where the base64 + # module gets confused by them. + return base64.b32decode(backwardscompat_bytes(cs)) __all__ = ["b2a", "a2b", "b2a_or_none", "BASE32CHAR_3bits", "BASE32CHAR_1bits", "BASE32CHAR", "BASE32STR_anybytes", "could_be_base32_encoded"]