mirror of
https://github.com/tahoe-lafs/tahoe-lafs.git
synced 2025-03-11 14:53:55 +00:00
Port idlib to Python 3, making its behavior consistent across Python 2 and 3.
This commit is contained in:
parent
995f271d38
commit
fb621f4388
@ -33,7 +33,9 @@ if six.PY3:
|
||||
|
||||
class IDLib(unittest.TestCase):
|
||||
def test_nodeid_b2a(self):
|
||||
self.failUnlessEqual(idlib.nodeid_b2a(b"\x00"*20), "a"*32)
|
||||
result = idlib.nodeid_b2a(b"\x00"*20)
|
||||
self.assertEqual(result, "a"*32)
|
||||
self.assertIsInstance(result, str)
|
||||
|
||||
|
||||
class MyList(list):
|
||||
|
@ -94,6 +94,7 @@ PORTED_MODULES = [
|
||||
"allmydata.util.happinessutil",
|
||||
"allmydata.util.hashutil",
|
||||
"allmydata.util.humanreadable",
|
||||
"allmydata.util.idlib",
|
||||
"allmydata.util.iputil",
|
||||
"allmydata.util.jsonbytes",
|
||||
"allmydata.util.log",
|
||||
|
@ -1,9 +1,29 @@
|
||||
"""
|
||||
Ported to Python 3.
|
||||
"""
|
||||
from __future__ import absolute_import
|
||||
from __future__ import division
|
||||
from __future__ import print_function
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from future.utils import PY2
|
||||
if PY2:
|
||||
from future.builtins import filter, map, zip, ascii, chr, hex, input, next, oct, open, pow, round, super, bytes, dict, list, object, range, str, max, min # noqa: F401
|
||||
|
||||
from six import ensure_text
|
||||
from foolscap import base32
|
||||
|
||||
|
||||
def nodeid_b2a(nodeid):
|
||||
# we display nodeids using the same base32 alphabet that Foolscap uses
|
||||
return base32.encode(nodeid)
|
||||
"""
|
||||
We display nodeids using the same base32 alphabet that Foolscap uses.
|
||||
|
||||
Returns a Unicode string.
|
||||
"""
|
||||
return ensure_text(base32.encode(nodeid))
|
||||
|
||||
def shortnodeid_b2a(nodeid):
|
||||
"""
|
||||
Short version of nodeid_b2a() output, Unicode string.
|
||||
"""
|
||||
return nodeid_b2a(nodeid)[:8]
|
||||
|
Loading…
x
Reference in New Issue
Block a user