3c0d417
From 0170dfe5fc97f48a32f662fd7123096940eecc9a Mon Sep 17 00:00:00 2001
3c0d417
From: Dan Callaghan <dcallagh@redhat.com>
3c0d417
Date: Mon, 27 Aug 2018 08:20:39 +1000
3c0d417
Subject: [PATCH 1/2] port to Python 3
3c0d417
3c0d417
These changes are unfortunately not compatible with Python 2 because of
3c0d417
the differences between string.maketrans (Python 2) and str.maketrans
3c0d417
(Python 3). The former does not accept deletechars whereas the latter
3c0d417
does.
3c0d417
---
3c0d417
 setup.py                     |  2 +-
3c0d417
 zbase32/__init__.py          |  2 +-
3c0d417
 zbase32/test/test_zbase32.py | 44 ++++++++---------
3c0d417
 zbase32/zbase32.py           | 91 +++++++++++++++++++-----------------
3c0d417
 zbase32/zbase32id.py         | 18 ++++---
3c0d417
 5 files changed, 79 insertions(+), 78 deletions(-)
3c0d417
3c0d417
diff --git a/setup.py b/setup.py
3c0d417
index 1ede56d..e004253 100644
3c0d417
--- a/setup.py
3c0d417
+++ b/setup.py
3c0d417
@@ -49,7 +49,7 @@
3c0d417
     if mo:
3c0d417
         verstr = mo.group(1)
3c0d417
     else:
3c0d417
-        print "unable to find version in %s" % (VERSIONFILE,)
3c0d417
+        print("unable to find version in %s" % (VERSIONFILE,))
3c0d417
         raise RuntimeError("if %s.py exists, it must be well-formed" % (VERSIONFILE,))
3c0d417
 
3c0d417
 # darcsver is needed only if you want "./setup.py darcsver" to write a new
3c0d417
diff --git a/zbase32/__init__.py b/zbase32/__init__.py
3c0d417
index b4990a7..381c557 100644
3c0d417
--- a/zbase32/__init__.py
3c0d417
+++ b/zbase32/__init__.py
3c0d417
@@ -1 +1 @@
3c0d417
-from zbase32 import *
3c0d417
+from zbase32.zbase32 import *
3c0d417
diff --git a/zbase32/test/test_zbase32.py b/zbase32/test/test_zbase32.py
3c0d417
index 9ab9299..31dead4 100644
3c0d417
--- a/zbase32/test/test_zbase32.py
3c0d417
+++ b/zbase32/test/test_zbase32.py
3c0d417
@@ -22,19 +22,19 @@ def test_ende(self):
3c0d417
         bs = insecurerandstr(2**3)
3c0d417
         asciis=b2a(bs)
3c0d417
         bs2=a2b(asciis)
3c0d417
-        assert bs2 == bs, "bs2: %s, bs: %s" % (`bs2`, `bs`,)
3c0d417
+        assert bs2 == bs, "bs2: %r, bs: %r" % (bs2, bs,)
3c0d417
 
3c0d417
     def test_ende_long(self):
3c0d417
         bs = insecurerandstr(2**3)
3c0d417
         asciis=b2a_long(bs)
3c0d417
         bs2=a2b_long(asciis)
3c0d417
-        assert bs2 == bs, "bs2: %s, bs: %s" % (`bs2`, `bs`,)
3c0d417
+        assert bs2 == bs, "bs2: %r, bs: %r" % (bs2, bs,)
3c0d417
 
3c0d417
     def test_both(self):
3c0d417
         bs = insecurerandstr(2**3)
3c0d417
         asciis=b2a(bs)
3c0d417
         asciisl=b2a_long(bs)
3c0d417
-        assert asciis == asciisl, "asciis: %s, asciisl: %s" % (`asciis`, `asciisl`,)
3c0d417
+        assert asciis == asciisl, "asciis: %r, asciisl: %r" % (asciis, asciisl,)
3c0d417
         asciis=b2a(bs)
3c0d417
         bs2=a2b(asciis)
3c0d417
         bs2l=a2b_long(asciis)
3c0d417
@@ -45,7 +45,7 @@ def test_big(self):
3c0d417
         bs = insecurerandstr(2**9)
3c0d417
         asciis=b2a(bs)
3c0d417
         asciisl=b2a_long(bs)
3c0d417
-        assert asciis == asciisl, "asciis: %s, asciisl: %s" % (`asciis`, `asciisl`,)
3c0d417
+        assert asciis == asciisl, "asciis: %r, asciisl: %r" % (asciis, asciisl,)
3c0d417
         asciis=b2a(bs)
3c0d417
         bs2=a2b(asciis)
3c0d417
         bs2l=a2b_long(asciis)
3c0d417
@@ -60,21 +60,21 @@ def DISABLED_test_odd_sizes_violates_preconditions(self):
3c0d417
             lib = random.randrange(1, 2**8)
3c0d417
             bs = insecurerandstr(random.randrange(1, 2**5))
3c0d417
             asciis = b2a_l(bs, lib)
3c0d417
-            assert len(asciis) == (lib+4)/5 # the size of the base-32 encoding must be just right
3c0d417
+            assert len(asciis) == (lib+4)//5 # the size of the base-32 encoding must be just right
3c0d417
             asciisl = b2a_l_long(bs, lib)
3c0d417
-            assert len(asciisl) == (lib+4)/5 # the size of the base-32 encoding must be just right
3c0d417
+            assert len(asciisl) == (lib+4)//5 # the size of the base-32 encoding must be just right
3c0d417
             assert asciis == asciisl
3c0d417
             bs2 = a2b_l(asciis, lib)
3c0d417
-            assert len(bs2) == (lib+7)/8 # the size of the result must be just right
3c0d417
+            assert len(bs2) == (lib+7)//8 # the size of the result must be just right
3c0d417
             bs2l = a2b_l_long(asciis, lib)
3c0d417
-            assert len(bs2l) == (lib+7)/8 # the size of the result must be just right
3c0d417
+            assert len(bs2l) == (lib+7)//8 # the size of the result must be just right
3c0d417
             assert bs2 == bs2l
3c0d417
-            assert trimnpad(bs, lib) == bs2, "trimnpad(%s, %s): %s, bs2: %s" % (`bs`, lib, `trimnpad(bs, lib)`, `bs2`,)
3c0d417
+            assert trimnpad(bs, lib) == bs2, "trimnpad(%r, %r): %r, bs2: %r" % (bs, lib, trimnpad(bs, lib), bs2,)
3c0d417
 
3c0d417
     def test_odd_sizes(self):
3c0d417
         for j in range(2**6):
3c0d417
             lib = random.randrange(1, 2**8)
3c0d417
-            bs = insecurerandstr((lib+7)/8)
3c0d417
+            bs = insecurerandstr((lib+7)//8)
3c0d417
             # zero-out unused least-sig bits
3c0d417
             if lib%8:
3c0d417
                 b=ord(bs[-1])
3c0d417
@@ -82,31 +82,31 @@ def test_odd_sizes(self):
3c0d417
                 b = b << (8 - (lib%8))
3c0d417
                 bs = bs[:-1] + chr(b)
3c0d417
             asciis = b2a_l(bs, lib)
3c0d417
-            assert len(asciis) == (lib+4)/5 # the size of the base-32 encoding must be just right
3c0d417
+            assert len(asciis) == (lib+4)//5 # the size of the base-32 encoding must be just right
3c0d417
             asciisl = b2a_l_long(bs, lib)
3c0d417
-            assert len(asciisl) == (lib+4)/5 # the size of the base-32 encoding must be just right
3c0d417
+            assert len(asciisl) == (lib+4)//5 # the size of the base-32 encoding must be just right
3c0d417
             assert asciis == asciisl
3c0d417
             bs2 = a2b_l(asciis, lib)
3c0d417
-            assert len(bs2) == (lib+7)/8 # the size of the result must be just right
3c0d417
+            assert len(bs2) == (lib+7)//8 # the size of the result must be just right
3c0d417
             bs2l = a2b_l_long(asciis, lib)
3c0d417
-            assert len(bs2l) == (lib+7)/8 # the size of the result must be just right
3c0d417
+            assert len(bs2l) == (lib+7)//8 # the size of the result must be just right
3c0d417
             assert bs2 == bs2l
3c0d417
-            assert trimnpad(bs, lib) == bs2, "trimnpad(%s, %s): %s, bs2: %s" % (`bs`, lib, `trimnpad(bs, lib)`, `bs2`,)
3c0d417
+            assert trimnpad(bs, lib) == bs2, "trimnpad(%r, %r): %r, bs2: %r" % (bs, lib, trimnpad(bs, lib), bs2,)
3c0d417
 
3c0d417
     def test_n8mo4_is_an_encoding(self):
3c0d417
-        self.failUnless(could_be_base32_encoded_l('n8mo4', 25))
3c0d417
+        self.assertTrue(could_be_base32_encoded_l('n8mo4', 25))
3c0d417
 
3c0d417
     def test_could_be(self):
3c0d417
         # base-32 encoded strings could be
3c0d417
         for j in range(2**9):
3c0d417
             rands = insecurerandstr(random.randrange(1, 2**7))
3c0d417
             randsenc = b2a(rands)
3c0d417
-            assert could_be_base32_encoded(randsenc), "rands: %s, randsenc: %s, a2b(randsenc): %s" % (`rands`, `randsenc`, `a2b(randsenc)`,)
3c0d417
+            assert could_be_base32_encoded(randsenc), "rands: %r, randsenc: %r, a2b(randsenc): %r" % (rands, randsenc, a2b(randsenc),)
3c0d417
 
3c0d417
         # base-32 encoded strings with unusual bit lengths could be, too
3c0d417
         for j in range(2**9):
3c0d417
             bitl = random.randrange(1, 2**7)
3c0d417
-            bs = insecurerandstr((bitl+7)/8)
3c0d417
+            bs = insecurerandstr((bitl+7)//8)
3c0d417
             # zero-out unused least-sig bits
3c0d417
             if bitl%8:
3c0d417
                 b=ord(bs[-1])
3c0d417
@@ -137,13 +137,13 @@ def _help_bench_ed_l(N):
3c0d417
 
3c0d417
 def benchem():
3c0d417
     import benchfunc # from pyutil
3c0d417
-    print "e: "
3c0d417
+    print("e: ")
3c0d417
     benchfunc.bench(_help_bench_e, TOPXP=13)
3c0d417
-    print "ed: "
3c0d417
+    print("ed: ")
3c0d417
     benchfunc.bench(_help_bench_ed, TOPXP=13)
3c0d417
-    print "e_l: "
3c0d417
+    print("e_l: ")
3c0d417
     benchfunc.bench(_help_bench_e_l, TOPXP=13)
3c0d417
-    print "ed_l: "
3c0d417
+    print("ed_l: ")
3c0d417
     benchfunc.bench(_help_bench_ed_l, TOPXP=13)
3c0d417
 
3c0d417
 def suite():
3c0d417
diff --git a/zbase32/zbase32.py b/zbase32/zbase32.py
3c0d417
index 98aa435..c840882 100644
3c0d417
--- a/zbase32/zbase32.py
3c0d417
+++ b/zbase32/zbase32.py
3c0d417
@@ -6,6 +6,8 @@
3c0d417
 # deal in this work without restriction (including the rights to use, modify,
3c0d417
 # distribute, sublicense, and/or sell copies).
3c0d417
 
3c0d417
+from __future__ import print_function
3c0d417
+
3c0d417
 # from the Python Standard Library
3c0d417
 import string
3c0d417
 
3c0d417
@@ -49,9 +51,9 @@
3c0d417
 chars = mnet32_alphabet
3c0d417
 
3c0d417
 vals = ''.join([chr(i) for i in range(32)])
3c0d417
-c2vtranstable = string.maketrans(chars, vals)
3c0d417
-v2ctranstable = string.maketrans(vals, chars)
3c0d417
-identitytranstable = string.maketrans(chars, chars)
3c0d417
+c2vtranstable = str.maketrans(chars, vals)
3c0d417
+v2ctranstable = str.maketrans(vals, chars)
3c0d417
+identitytranstable = str.maketrans(chars, chars)
3c0d417
 
3c0d417
 def _get_trailing_chars_without_lsbs(N, d):
3c0d417
     """
3c0d417
@@ -62,7 +64,7 @@ def _get_trailing_chars_without_lsbs(N, d):
3c0d417
         s.extend(_get_trailing_chars_without_lsbs(N+1, d=d))
3c0d417
     i = 0
3c0d417
     while i < len(chars):
3c0d417
-        if not d.has_key(i):
3c0d417
+        if i not in d:
3c0d417
             d[i] = None
3c0d417
             s.append(chars[i])
3c0d417
         i = i + 2**N
3c0d417
@@ -76,19 +78,19 @@ def get_trailing_chars_without_lsbs(N):
3c0d417
     return ''.join(_get_trailing_chars_without_lsbs(N, d=d))
3c0d417
 
3c0d417
 def print_trailing_chars_without_lsbs(N):
3c0d417
-    print get_trailing_chars_without_lsbs(N)
3c0d417
+    print(get_trailing_chars_without_lsbs(N))
3c0d417
 
3c0d417
 def print_trailing_chars():
3c0d417
     N = 4
3c0d417
     while N >= 0:
3c0d417
-        print "%2d" % N + ": ",
3c0d417
+        print("%2d" % N + ": ", end='')
3c0d417
         print_trailing_chars_without_lsbs(N)
3c0d417
         N = N - 1
3c0d417
 
3c0d417
-upcasetranstable = string.maketrans(string.ascii_lowercase, string.ascii_uppercase)
3c0d417
-digitchars = string.translate(chars, identitytranstable, string.ascii_lowercase)
3c0d417
-def add_upcase(s, upcasetranstable=upcasetranstable, digitchars=digitchars):
3c0d417
-    return s + string.translate(s, upcasetranstable, digitchars)
3c0d417
+digitchars = chars.translate(str.maketrans('', '', string.ascii_lowercase))
3c0d417
+upcasetranstable = str.maketrans(string.ascii_lowercase, string.ascii_uppercase, digitchars)
3c0d417
+def add_upcase(s, upcasetranstable=upcasetranstable):
3c0d417
+    return s + s.translate(upcasetranstable)
3c0d417
 
3c0d417
 def b2a(os):
3c0d417
     """
3c0d417
@@ -122,7 +124,7 @@ def b2a_l(os, lengthinbits):
3c0d417
 
3c0d417
     @return the contents of os in base-32 encoded form
3c0d417
     """
3c0d417
-    precondition(isinstance(lengthinbits, (int, long,)), "lengthinbits is required to be an integer.", lengthinbits=lengthinbits)
3c0d417
+    precondition(isinstance(lengthinbits, int), "lengthinbits is required to be an integer.", lengthinbits=lengthinbits)
3c0d417
     precondition(div_ceil(lengthinbits, 8) == len(os), "lengthinbits is required to specify a number of bits storable in exactly len(os) octets.", lengthinbits=lengthinbits, lenos=len(os))
3c0d417
     # precondition((lengthinbits % 8==0) or ((ord(os[-1]) % (2**(8-(lengthinbits%8))))==0), "Any unused least-significant bits in os are required to be zero bits.", ord(os[-1]), lengthinbits=lengthinbits) # removing this precondition, because I like to use it with random os, like this: base32.b2a_l(file("/dev/urandom", "r").read(9), 65)
3c0d417
 
3c0d417
@@ -152,19 +154,19 @@ def b2a_l(os, lengthinbits):
3c0d417
             cutoff = 256
3c0d417
             continue
3c0d417
         cutoff = cutoff * 8
3c0d417
-        quintet = num / cutoff
3c0d417
+        quintet = num // cutoff
3c0d417
         quintets.append(quintet)
3c0d417
         num = num - (quintet * cutoff)
3c0d417
 
3c0d417
-        cutoff = cutoff / 32
3c0d417
-        quintet = num / cutoff
3c0d417
+        cutoff = cutoff // 32
3c0d417
+        quintet = num // cutoff
3c0d417
         quintets.append(quintet)
3c0d417
         num = num - (quintet * cutoff)
3c0d417
 
3c0d417
     if len(quintets) > numquintets:
3c0d417
         assert len(quintets) == (numquintets+1), "len(quintets): %s, numquintets: %s, quintets: %s" % (len(quintets), numquintets, quintets,)
3c0d417
         quintets = quintets[:numquintets]
3c0d417
-    res = string.translate(''.join([chr(q) for q in quintets]), v2ctranstable)
3c0d417
+    res = ''.join([chr(q) for q in quintets]).translate(v2ctranstable)
3c0d417
     assert could_be_base32_encoded_l(res, lengthinbits), "lengthinbits: %s, res: %s" % (lengthinbits, res,)
3c0d417
     return res
3c0d417
 
3c0d417
@@ -186,7 +188,7 @@ def b2a_l(os, lengthinbits):
3c0d417
 
3c0d417
 def num_octets_that_encode_to_this_many_quintets(numqs):
3c0d417
     # Here is a computation that conveniently expresses this:
3c0d417
-    return (numqs*5+3)/8
3c0d417
+    return (numqs*5+3)//8
3c0d417
 
3c0d417
 def a2b(cs):
3c0d417
     """
3c0d417
@@ -212,7 +214,7 @@ def a2b_l(cs, lengthinbits):
3c0d417
     """
3c0d417
     precondition(could_be_base32_encoded_l(cs, lengthinbits), "cs is required to be possibly base32 encoded data.", cs=cs, lengthinbits=lengthinbits)
3c0d417
 
3c0d417
-    qs = [ord(v) for v in string.translate(cs, c2vtranstable)]
3c0d417
+    qs = [ord(v) for v in cs.translate(c2vtranstable)]
3c0d417
 
3c0d417
     numoctets = div_ceil(lengthinbits, 8)
3c0d417
     numquintetsofdata = div_ceil(lengthinbits, 5)
3c0d417
@@ -227,10 +229,10 @@ def a2b_l(cs, lengthinbits):
3c0d417
     i = 1
3c0d417
     while len(octets) < numoctets:
3c0d417
         while pos > 256:
3c0d417
-            pos = pos / 32
3c0d417
+            pos = pos // 32
3c0d417
             num = num + (qs[i] * pos)
3c0d417
             i = i + 1
3c0d417
-        octet = num / 256
3c0d417
+        octet = num // 256
3c0d417
         octets.append(octet)
3c0d417
         num = num - (octet * 256)
3c0d417
         num = num * 256
3c0d417
@@ -292,11 +294,12 @@ def init_s5a():
3c0d417
     return tuple(s5a)
3c0d417
 s5a = init_s5a()
3c0d417
 
3c0d417
-def could_be_base32_encoded(s, s8=s8, tr=string.translate, identitytranstable=identitytranstable, chars=chars):
3c0d417
-    return bool(s8[len(s)%8][ord(s[-1])] and not tr(s, identitytranstable, chars))
3c0d417
+deletechars = str.maketrans('', '', chars)
3c0d417
+def could_be_base32_encoded(s, s8=s8):
3c0d417
+    return bool(s8[len(s)%8][ord(s[-1])] and not s.translate(deletechars))
3c0d417
 
3c0d417
-def could_be_base32_encoded_l(s, lengthinbits, s5=s5, tr=string.translate, identitytranstable=identitytranstable, chars=chars):
3c0d417
-    return bool((((lengthinbits+4)/5) == len(s)) and s5[lengthinbits%5][ord(s[-1])] and not string.translate(s, identitytranstable, chars))
3c0d417
+def could_be_base32_encoded_l(s, lengthinbits, s5=s5):
3c0d417
+    return bool((((lengthinbits+4)//5) == len(s)) and s5[lengthinbits%5][ord(s[-1])] and not s.translate(deletechars))
3c0d417
 
3c0d417
 # the _long functions are 2/3 as fast as the normal ones.  The _long variants are included for testing, documentation, and benchmarking purposes.
3c0d417
 def b2a_long(os):
3c0d417
@@ -307,8 +310,8 @@ def b2a_l_long(os, lengthinbits):
3c0d417
 
3c0d417
     os = [ord(o) for o in os]
3c0d417
 
3c0d417
-    numquintets = (lengthinbits+4)/5
3c0d417
-    numoctetsofdata = (lengthinbits+7)/8
3c0d417
+    numquintets = (lengthinbits+4)//5
3c0d417
+    numoctetsofdata = (lengthinbits+7)//8
3c0d417
     # strip trailing octets that won't be used
3c0d417
     del os[numoctetsofdata:]
3c0d417
     # zero out any unused bits in the final octet
3c0d417
@@ -317,41 +320,41 @@ def b2a_l_long(os, lengthinbits):
3c0d417
         os[-1] = os[-1] >> (8-(lengthinbits % 8))
3c0d417
         os[-1] = os[-1] << (8-(lengthinbits % 8))
3c0d417
     # append zero octets for padding if needed
3c0d417
-    numoctetsneeded = (numquintets*5+7)/8+4 # append 4 extra zero octets so that I can read in 40 -bit (5-octet) chunks
3c0d417
+    numoctetsneeded = (numquintets*5+7)//8+4 # append 4 extra zero octets so that I can read in 40 -bit (5-octet) chunks
3c0d417
     os.extend([0]*(numoctetsneeded-len(os)))
3c0d417
 
3c0d417
     quintets = []
3c0d417
     i = 0
3c0d417
-    CUTOFF = 2L**35
3c0d417
+    CUTOFF = 2**35
3c0d417
     while len(quintets) < numquintets:
3c0d417
         # take the next 5 octets and turn them into 8 quintets
3c0d417
-        num = 0L # i am a LONG!  hear me roar
3c0d417
+        num = 0
3c0d417
         for j in range(5):
3c0d417
             num = num *256
3c0d417
             num = num + os[i]
3c0d417
             i = i + 1
3c0d417
         for j in range(8):
3c0d417
-            quintet = num / CUTOFF
3c0d417
+            quintet = num // CUTOFF
3c0d417
             quintets.append(quintet)
3c0d417
             num = num - (quintet * CUTOFF)
3c0d417
             num = num * 32
3c0d417
     quintets = quintets[:numquintets]
3c0d417
-    res = string.translate(''.join([chr(q) for q in quintets]), v2ctranstable)
3c0d417
-    assert could_be_base32_encoded_l(res, lengthinbits), "lengthinbits: %s, res: %s, origos: %s" % (lengthinbits, res, `origos`)
3c0d417
+    res = ''.join([chr(q) for q in quintets]).translate(v2ctranstable)
3c0d417
+    assert could_be_base32_encoded_l(res, lengthinbits), "lengthinbits: %s, res: %s, origos: %r" % (lengthinbits, res, origos)
3c0d417
     return res
3c0d417
 
3c0d417
 def a2b_long(cs):
3c0d417
-    return a2b_l_long(cs, ((len(cs)*5+3)/8)*8)
3c0d417
+    return a2b_l_long(cs, ((len(cs)*5+3)//8)*8)
3c0d417
 
3c0d417
 def a2b_l_long(cs, lengthinbits):
3c0d417
     precondition(could_be_base32_encoded_l(cs, lengthinbits), "cs is required to be possibly base32 encoded data.", lengthinbits=lengthinbits, cs=cs)
3c0d417
 
3c0d417
-    qs = [ord(v) for v in string.translate(cs, c2vtranstable)]
3c0d417
+    qs = [ord(v) for v in cs.translate(c2vtranstable)]
3c0d417
 
3c0d417
     # print "lengthinbits: ", lengthinbits
3c0d417
-    numoctets = (lengthinbits+7)/8
3c0d417
+    numoctets = (lengthinbits+7)//8
3c0d417
     # print "numoctets: ", numoctets
3c0d417
-    numquintetsofdata = (lengthinbits+4)/5
3c0d417
+    numquintetsofdata = (lengthinbits+4)//5
3c0d417
     # print "numquintetsofdata: ", numquintetsofdata
3c0d417
     # strip trailing quintets that won't be used
3c0d417
     del qs[numquintetsofdata:]
3c0d417
@@ -360,21 +363,21 @@ def a2b_l_long(cs, lengthinbits):
3c0d417
         qs[-1] = qs[-1] >> (5-(lengthinbits % 5))
3c0d417
         qs[-1] = qs[-1] << (5-(lengthinbits % 5))
3c0d417
     # append zero quintets for padding if needed
3c0d417
-    numquintetsneeded = (numoctets*8+4)/5+7 # append 7 extra zero quintets so that I can read in 40 -bit (8-quintet) chunks
3c0d417
+    numquintetsneeded = (numoctets*8+4)//5+7 # append 7 extra zero quintets so that I can read in 40 -bit (8-quintet) chunks
3c0d417
     qs.extend([0]*(numquintetsneeded-len(qs)))
3c0d417
 
3c0d417
     octets = []
3c0d417
     i = 0
3c0d417
-    CUTOFF = 2L**32
3c0d417
+    CUTOFF = 2**32
3c0d417
     while len(octets) < numoctets:
3c0d417
         # take the next 8 quintets and turn them into 5 octets
3c0d417
-        num = 0L # i am a LONG!  hear me roar
3c0d417
+        num = 0
3c0d417
         for j in range(8):
3c0d417
             num = num * 32
3c0d417
             num = num + qs[i]
3c0d417
             i = i + 1
3c0d417
         for j in range(5):
3c0d417
-            octet = num / CUTOFF
3c0d417
+            octet = num // CUTOFF
3c0d417
             octets.append(octet)
3c0d417
             num = num - (octet * CUTOFF)
3c0d417
             num = num * 256
3c0d417
@@ -389,7 +392,7 @@ def trimnpad(os, lengthinbits):
3c0d417
     """
3c0d417
     os = [ord(o) for o in os]
3c0d417
     mod8 = lengthinbits % 8
3c0d417
-    div8 = lengthinbits / 8
3c0d417
+    div8 = lengthinbits // 8
3c0d417
     numos = div8 + (mod8 != 0)
3c0d417
     if len(os) >= numos:
3c0d417
         # strip trailing octets that won't be used
3c0d417
@@ -429,12 +432,12 @@ def _help_bench_ed_l(N):
3c0d417
 
3c0d417
 def benchem():
3c0d417
     import benchfunc # from pyutil
3c0d417
-    print "e: "
3c0d417
+    print("e: ")
3c0d417
     benchfunc.bench(_help_bench_e, TOPXP=13)
3c0d417
-    print "ed: "
3c0d417
+    print("ed: ")
3c0d417
     benchfunc.bench(_help_bench_ed, TOPXP=13)
3c0d417
-    print "e_l: "
3c0d417
+    print("e_l: ")
3c0d417
     benchfunc.bench(_help_bench_e_l, TOPXP=13)
3c0d417
-    print "ed_l: "
3c0d417
+    print("ed_l: ")
3c0d417
     benchfunc.bench(_help_bench_ed_l, TOPXP=13)
3c0d417
 
3c0d417
diff --git a/zbase32/zbase32id.py b/zbase32/zbase32id.py
3c0d417
index cc3e82e..e601fc0 100644
3c0d417
--- a/zbase32/zbase32id.py
3c0d417
+++ b/zbase32/zbase32id.py
3c0d417
@@ -4,14 +4,12 @@
3c0d417
 #    GNU Lesser General Public License v2.1.
3c0d417
 #    See the file COPYING or visit http://www.gnu.org/ for details.
3c0d417
 
3c0d417
-import string
3c0d417
-
3c0d417
 from pyutil import humanreadable
3c0d417
 
3c0d417
 import zbase32 
3c0d417
 
3c0d417
 printableascii = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_=+!@#$%^&*()`~[]\{}|;':\",./<>? \t" # I just typed this in by looking at my keyboard.  It probably doesn't matter much if I missed some, because I only use it to guess whether a 20-byte string should be represented as a string or as an ID.  If all of the characters in the string are found `printableascii', then we guess that it is a string, not an id.
3c0d417
-nulltrans = string.maketrans('', '')
3c0d417
+nonprintabletrans = str.maketrans('', '', printableascii)
3c0d417
 
3c0d417
 def abbrev_bare(id, b2a_l=zbase32.b2a_l, trimnpad=zbase32.trimnpad):
3c0d417
     return b2a_l(trimnpad(id[:4], 25), 25)
3c0d417
@@ -32,19 +30,19 @@ class AbbrevRepr(humanreadable.BetterRepr):
3c0d417
     def __init__(self):
3c0d417
         humanreadable.BetterRepr.__init__(self)
3c0d417
 
3c0d417
-    def repr_str(self, obj, level, could_be_base32_encoded_l=zbase32.could_be_base32_encoded_l, nulltrans=nulltrans, printableascii=printableascii, abbrev=abbrev):
3c0d417
+    def repr_str(self, obj, level, could_be_base32_encoded_l=zbase32.could_be_base32_encoded_l, nonprintabletrans=nonprintabletrans, abbrev=abbrev):
3c0d417
         if len(obj) == 20:
3c0d417
             # But maybe it was just a 20-character human-readable string, like "credit limit reached", so this is an attempt to detect that case.
3c0d417
-            if len(obj.translate(nulltrans, printableascii)) == 0:
3c0d417
+            if len(obj.translate(nonprintabletrans)) == 0:
3c0d417
                 if self.maxstring >= 22:
3c0d417
-                    return `obj`
3c0d417
+                    return repr(obj)
3c0d417
 
3c0d417
                 # inlining repr.repr_string() here...
3c0d417
-                s = `obj[:self.maxstring]`
3c0d417
+                s = repr(obj[:self.maxstring])
3c0d417
                 if len(s) > self.maxstring:
3c0d417
                     i = max(0, (self.maxstring-3)/2)
3c0d417
                     j = max(0, self.maxstring-3-i)
3c0d417
-                    s = `obj[:i] + obj[len(obj)-j:]`
3c0d417
+                    s = repr(obj[:i] + obj[len(obj)-j:])
3c0d417
                     s = s[:i] + '...' + s[len(s)-j:]
3c0d417
                     # ... done inlining `repr.repr_string()'
3c0d417
                 return s
3c0d417
@@ -55,11 +53,11 @@ def repr_str(self, obj, level, could_be_base32_encoded_l=zbase32.could_be_base32
3c0d417
             return '<' + obj[:5] + '>'
3c0d417
         else:
3c0d417
             # inlining repr.repr_string() here...
3c0d417
-            s = `obj[:self.maxstring]`
3c0d417
+            s = repr(obj[:self.maxstring])
3c0d417
             if len(s) > self.maxstring:
3c0d417
                 i = max(0, (self.maxstring-3)/2)
3c0d417
                 j = max(0, self.maxstring-3-i)
3c0d417
-                s = `obj[:i] + obj[len(obj)-j:]`
3c0d417
+                s = repr(obj[:i] + obj[len(obj)-j:])
3c0d417
                 s = s[:i] + '...' + s[len(s)-j:]
3c0d417
             # ... done inlining `repr.repr_string()'
3c0d417
             return s
3c0d417
-- 
3c0d417
2.17.1
3c0d417